mirror of
https://github.com/screentinker/screentinker.git
synced 2026-05-15 07:32:23 -06:00
Add schema_migrations table for run-once migration tracking
New schema_migrations table (id TEXT PK, ran_at INTEGER) tracks which one-time migrations have executed. The Phase 2 playlist migration now checks for 'phase2_playlist_migration' in this table instead of inferring state from devices.playlist_id. Records the migration ID after successful completion. Eliminates ffprobe overhead on subsequent startups. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
df7919f84f
commit
b87904c326
|
|
@ -96,10 +96,12 @@ try {
|
|||
}
|
||||
|
||||
// Phase 2 migration: convert existing assignments into per-device playlists
|
||||
const MIGRATION_ID = 'phase2_playlist_migration';
|
||||
|
||||
async function migrateAssignmentsToPlaylists() {
|
||||
// Skip if already migrated (any device has a playlist_id set)
|
||||
const migrated = db.prepare('SELECT 1 FROM devices WHERE playlist_id IS NOT NULL LIMIT 1').get();
|
||||
if (migrated) return;
|
||||
// Skip if already ran (tracked in schema_migrations table)
|
||||
const already = db.prepare('SELECT 1 FROM schema_migrations WHERE id = ?').get(MIGRATION_ID);
|
||||
if (already) return;
|
||||
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
const { execFile } = require('child_process');
|
||||
|
|
@ -185,6 +187,9 @@ async function migrateAssignmentsToPlaylists() {
|
|||
});
|
||||
migrate();
|
||||
|
||||
// Record that this migration has run
|
||||
db.prepare('INSERT OR IGNORE INTO schema_migrations (id) VALUES (?)').run(MIGRATION_ID);
|
||||
|
||||
const scheduleCount = db.prepare('SELECT COUNT(*) as count FROM schedules').get().count;
|
||||
console.log(`Migration complete: ${devicesWithAssignments.length} device(s), ${totalItems} playlist item(s), ${videosProbed} video(s) probed, ${scheduleCount} schedule(s).`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -408,3 +408,10 @@ CREATE TABLE IF NOT EXISTS device_status_log (
|
|||
status TEXT NOT NULL,
|
||||
timestamp INTEGER NOT NULL DEFAULT (strftime('%s','now'))
|
||||
);
|
||||
|
||||
-- ===================== SCHEMA MIGRATIONS =====================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS schema_migrations (
|
||||
id TEXT PRIMARY KEY,
|
||||
ran_at INTEGER NOT NULL DEFAULT (strftime('%s','now'))
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue