diff --git a/server/db/database.js b/server/db/database.js index 56f5218..11f70e3 100644 --- a/server/db/database.js +++ b/server/db/database.js @@ -54,6 +54,10 @@ const migrations = [ "ALTER TABLE plans ADD COLUMN stripe_price_yearly TEXT", // Last login tracking "ALTER TABLE users ADD COLUMN last_login INTEGER", + // Phase 2: every device gets a playlist, schedules can override with a playlist + "ALTER TABLE devices ADD COLUMN playlist_id TEXT REFERENCES playlists(id) ON DELETE SET NULL", + "ALTER TABLE schedules ADD COLUMN playlist_id TEXT REFERENCES playlists(id) ON DELETE SET NULL", + "ALTER TABLE playlists ADD COLUMN is_auto_generated INTEGER NOT NULL DEFAULT 0", ]; for (const sql of migrations) { try { db.exec(sql); } catch (e) { /* already exists */ } diff --git a/server/db/schema.sql b/server/db/schema.sql index 786e077..229a987 100644 --- a/server/db/schema.sql +++ b/server/db/schema.sql @@ -53,6 +53,7 @@ CREATE TABLE IF NOT EXISTS devices ( app_version TEXT, screen_width INTEGER, screen_height INTEGER, + playlist_id TEXT REFERENCES playlists(id) ON DELETE SET NULL, created_at INTEGER NOT NULL DEFAULT (strftime('%s','now')), updated_at INTEGER NOT NULL DEFAULT (strftime('%s','now')) ); @@ -199,6 +200,7 @@ CREATE TABLE IF NOT EXISTS schedules ( content_id TEXT REFERENCES content(id) ON DELETE CASCADE, widget_id TEXT REFERENCES widgets(id) ON DELETE CASCADE, layout_id TEXT REFERENCES layouts(id) ON DELETE SET NULL, + playlist_id TEXT REFERENCES playlists(id) ON DELETE SET NULL, title TEXT NOT NULL DEFAULT '', start_time TEXT NOT NULL, end_time TEXT NOT NULL, @@ -318,6 +320,7 @@ CREATE TABLE IF NOT EXISTS playlists ( user_id TEXT NOT NULL REFERENCES users(id), name TEXT NOT NULL, description TEXT DEFAULT '', + is_auto_generated INTEGER NOT NULL DEFAULT 0, created_at INTEGER NOT NULL DEFAULT (strftime('%s','now')), updated_at INTEGER NOT NULL DEFAULT (strftime('%s','now')) );