diff --git a/sim/cluster0/scripts/load-schemas.sh b/sim/cluster0/scripts/load-schemas.sh index d6633be..2606b8e 100644 --- a/sim/cluster0/scripts/load-schemas.sh +++ b/sim/cluster0/scripts/load-schemas.sh @@ -23,6 +23,34 @@ CREATE TABLE IF NOT EXISTS schema_migrations ( applied_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ); SQL + # Pre-populate tracking table for migrations already silently applied before this tracking was added. + # Detect by checking for a known column from each migration. + _existing=$(mariadb -u root -N -e "SELECT COUNT(*) FROM schema_migrations" "$db" 2>/dev/null || echo 0) + if [ "$_existing" -eq 0 ]; then + mariadb -u root "$db" <<'PRECHECK' +INSERT IGNORE INTO schema_migrations (migration) SELECT '004_ticket_workflow.sql' + FROM information_schema.columns + WHERE table_schema=DATABASE() AND table_name='tickets' AND column_name='workflow_state' LIMIT 1; +INSERT IGNORE INTO schema_migrations (migration) SELECT '005_ticket_attachments.sql' + FROM information_schema.tables + WHERE table_schema=DATABASE() AND table_name='ticket_attachments' LIMIT 1; +INSERT IGNORE INTO schema_migrations (migration) SELECT '006_graph_sessions.sql' + FROM information_schema.tables + WHERE table_schema=DATABASE() AND table_name='graph_sessions' LIMIT 1; +INSERT IGNORE INTO schema_migrations (migration) SELECT '007_remote_access.sql' + FROM information_schema.tables + WHERE table_schema=DATABASE() AND table_name='remote_access_sessions' LIMIT 1; +INSERT IGNORE INTO schema_migrations (migration) SELECT '008_graph_sessions_indexes.sql' + FROM information_schema.statistics + WHERE table_schema=DATABASE() AND table_name='graph_sessions' AND index_name='idx_gs_device' LIMIT 1; +INSERT IGNORE INTO schema_migrations (migration) SELECT '008_auth_email_2fa.sql' + FROM information_schema.tables + WHERE table_schema=DATABASE() AND table_name='auth_email_codes' LIMIT 1; +INSERT IGNORE INTO schema_migrations (migration) SELECT '009_rssh_sessions.sql' + FROM information_schema.tables + WHERE table_schema=DATABASE() AND table_name='rssh_sessions' LIMIT 1; +PRECHECK + fi } migration_applied() {