From 9a4245dfab9ba4c528a10b152f3bb88888f5f48f Mon Sep 17 00:00:00 2001 From: Jordan Dalby Date: Mon, 11 Nov 2024 17:30:41 +0000 Subject: [PATCH] Create share table if it doesn't exist during the fragment migration --- server/src/config/database.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/server/src/config/database.js b/server/src/config/database.js index a881044..6920fd1 100644 --- a/server/src/config/database.js +++ b/server/src/config/database.js @@ -49,7 +49,7 @@ function needsMigration(db) { return hasCodeColumn; } -async function migrateToFragments(db) { +async function migrateToV1_4_0(db) { console.log('Starting migration to fragments...'); if (!needsMigration(db)) { @@ -73,6 +73,17 @@ async function migrateToFragments(db) { ); CREATE INDEX IF NOT EXISTS idx_fragments_snippet_id ON fragments(snippet_id); + + CREATE TABLE IF NOT EXISTS shared_snippets ( + id TEXT PRIMARY KEY, + snippet_id INTEGER NOT NULL, + requires_auth BOOLEAN NOT NULL DEFAULT false, + expires_at DATETIME, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (snippet_id) REFERENCES snippets(id) ON DELETE CASCADE + ); + + CREATE INDEX IF NOT EXISTS idx_shared_snippets_snippet_id ON shared_snippets(snippet_id); `); const snippets = db.prepare('SELECT id, code, language FROM snippets').all(); @@ -176,7 +187,7 @@ function initializeDatabase() { console.log('Database needs migration, creating backup...'); if (backupDatabase(dbPath)) { console.log('Starting migration process...'); - migrateToFragments(db); + migrateToV1_4_0(db); } } else { console.log('Database schema is up to date'); @@ -200,6 +211,6 @@ function getDb() { module.exports = { initializeDatabase, - migrateToFragments, + migrateToV1_4_0, getDb }; \ No newline at end of file