Update
This commit is contained in:
1 parent
b780bff850
commit
7b3ea37127
1752 files changed
+1341
-166
No files matched your search
+35
-3
@@ -49,13 +49,12 @@ export function runMigrations(db: Database.Database): void {
|
||||
|
||||
CREATE TABLE IF NOT EXISTS successful_messages (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
sent_message_id INTEGER NOT NULL,
|
||||
sent_message_id INTEGER,
|
||||
original_message TEXT NOT NULL,
|
||||
image_analysis TEXT,
|
||||
post_title TEXT,
|
||||
response_snippet TEXT,
|
||||
created_at INTEGER NOT NULL,
|
||||
FOREIGN KEY (sent_message_id) REFERENCES sent_messages(id)
|
||||
created_at INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_posts_subreddit
|
||||
@@ -80,4 +79,37 @@ export function runMigrations(db: Database.Database): void {
|
||||
|
||||
// Create index for response checking
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_sent_messages_response ON sent_messages(got_response)`);
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_sent_messages_recipient ON sent_messages(recipient)`);
|
||||
|
||||
// Migration: Make sent_message_id nullable in successful_messages
|
||||
// SQLite doesn't support ALTER COLUMN, so we need to recreate the table
|
||||
const successfulMsgColumns = db.prepare(`PRAGMA table_info(successful_messages)`).all() as { name: string; notnull: number }[];
|
||||
const sentMsgIdCol = successfulMsgColumns.find((c) => c.name === 'sent_message_id');
|
||||
|
||||
if (sentMsgIdCol && sentMsgIdCol.notnull === 1) {
|
||||
// Column is currently NOT NULL, we need to migrate
|
||||
db.exec(`
|
||||
-- Create new table with nullable sent_message_id
|
||||
CREATE TABLE successful_messages_new (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
sent_message_id INTEGER,
|
||||
original_message TEXT NOT NULL,
|
||||
image_analysis TEXT,
|
||||
post_title TEXT,
|
||||
response_snippet TEXT,
|
||||
created_at INTEGER NOT NULL
|
||||
);
|
||||
|
||||
-- Copy existing data
|
||||
INSERT INTO successful_messages_new
|
||||
SELECT id, sent_message_id, original_message, image_analysis, post_title, response_snippet, created_at
|
||||
FROM successful_messages;
|
||||
|
||||
-- Drop old table
|
||||
DROP TABLE successful_messages;
|
||||
|
||||
-- Rename new table
|
||||
ALTER TABLE successful_messages_new RENAME TO successful_messages;
|
||||
`);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user