diff --git a/packages/plugin/src/features/magic-context/migrations.ts b/packages/plugin/src/features/magic-context/migrations.ts index 7c1540fd7..dc40aaff5 100644 --- a/packages/plugin/src/features/magic-context/migrations.ts +++ b/packages/plugin/src/features/magic-context/migrations.ts @@ -229,7 +229,7 @@ export const MIGRATIONS: Migration[] = [ session_id TEXT, project_path TEXT, surface_condition TEXT, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) updated_at INTEGER NOT NULL, last_checked_at INTEGER, ready_at INTEGER, @@ -320,7 +320,7 @@ export const MIGRATIONS: Migration[] = [ type TEXT NOT NULL, payload TEXT NOT NULL DEFAULT '{}', session_id TEXT, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) consumed_at INTEGER ); CREATE INDEX IF NOT EXISTS idx_plugin_messages_direction_consumed @@ -341,7 +341,7 @@ export const MIGRATIONS: Migration[] = [ session_id TEXT NOT NULL, source_compartment_start INTEGER, source_compartment_end INTEGER, - created_at INTEGER NOT NULL + created_at INTEGER NOT NULL -- epoch ms (Date.now()) ); CREATE INDEX IF NOT EXISTS idx_umc_created ON user_memory_candidates(created_at); @@ -352,7 +352,7 @@ export const MIGRATIONS: Migration[] = [ promoted_at INTEGER NOT NULL, source_candidate_ids TEXT DEFAULT '[]', source_candidate_provenance TEXT, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) updated_at INTEGER NOT NULL ); CREATE INDEX IF NOT EXISTS idx_um_status ON user_memories(status); @@ -380,7 +380,7 @@ export const MIGRATIONS: Migration[] = [ sha TEXT PRIMARY KEY, embedding BLOB NOT NULL, model_id TEXT NOT NULL, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) -- FK-cascade audit (v12): git_commit_embeddings.sha -> git_commits.sha -- uses ON DELETE CASCADE, so SQLite PRAGMA foreign_keys must be ON on -- every connection and v12 cleans historical orphan rows. @@ -1061,7 +1061,7 @@ export const MIGRATIONS: Migration[] = [ kind TEXT NOT NULL, at_compartment INTEGER, fields_json TEXT NOT NULL DEFAULT '{}', - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) harness TEXT NOT NULL DEFAULT 'opencode' ); CREATE INDEX IF NOT EXISTS idx_compartment_events_session @@ -1101,7 +1101,7 @@ export const MIGRATIONS: Migration[] = [ importance_avg REAL, discarded_last INTEGER NOT NULL DEFAULT 0, legacy INTEGER NOT NULL DEFAULT 0, - created_at INTEGER NOT NULL + created_at INTEGER NOT NULL -- epoch ms (Date.now()) ); CREATE INDEX IF NOT EXISTS idx_historian_runs_session ON historian_runs(session_id, created_at DESC); @@ -1452,7 +1452,7 @@ export const MIGRATIONS: Migration[] = [ model_id TEXT NOT NULL, dims INTEGER NOT NULL, vector BLOB NOT NULL, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) UNIQUE(compartment_id, window_index) ); CREATE INDEX IF NOT EXISTS idx_cce_session @@ -1471,7 +1471,7 @@ export const MIGRATIONS: Migration[] = [ CREATE TABLE IF NOT EXISTS workspaces ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL UNIQUE, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) updated_at INTEGER NOT NULL ); CREATE TABLE IF NOT EXISTS workspace_members ( @@ -1544,7 +1544,7 @@ export const MIGRATIONS: Migration[] = [ CREATE TABLE IF NOT EXISTS workspaces ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL UNIQUE, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) updated_at INTEGER NOT NULL, share_categories TEXT NOT NULL DEFAULT '["CONSTRAINTS"]' ); @@ -1829,7 +1829,7 @@ export const MIGRATIONS: Migration[] = [ source_message_time INTEGER NOT NULL, question_embedding BLOB, question_embedding_model_id TEXT, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) UNIQUE(project_path, harness, session_id, source_start_message_id, source_end_message_id) ); CREATE INDEX IF NOT EXISTS idx_primer_candidates_project_time @@ -1852,7 +1852,7 @@ export const MIGRATIONS: Migration[] = [ answer_refreshed_at INTEGER, source_candidate_ids TEXT NOT NULL DEFAULT '[]', source_candidate_provenance TEXT, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) updated_at INTEGER NOT NULL ); CREATE INDEX IF NOT EXISTS idx_primers_project_status_observed @@ -1985,7 +1985,7 @@ export const MIGRATIONS: Migration[] = [ sha TEXT NOT NULL, embedding BLOB NOT NULL, model_id TEXT NOT NULL, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) PRIMARY KEY(sha, model_id), FOREIGN KEY(sha) REFERENCES git_commits(sha) ON DELETE CASCADE ); @@ -2022,7 +2022,7 @@ export const MIGRATIONS: Migration[] = [ model_id TEXT NOT NULL, dims INTEGER NOT NULL, vector BLOB NOT NULL, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) UNIQUE(compartment_id, model_id, window_index) ); INSERT INTO compartment_chunk_embeddings_v49_new ( @@ -2117,7 +2117,7 @@ export const MIGRATIONS: Migration[] = [ job_id TEXT, cursor TEXT, status TEXT NOT NULL DEFAULT 'pending', - created_at INTEGER NOT NULL DEFAULT 0, + created_at INTEGER NOT NULL DEFAULT 0, -- epoch ms (Date.now()) updated_at INTEGER NOT NULL DEFAULT 0, UNIQUE(session_id, request_key) ); @@ -2156,7 +2156,7 @@ export const MIGRATIONS: Migration[] = [ shadow_epoch INTEGER NOT NULL DEFAULT 0, corpus_hash TEXT NOT NULL DEFAULT '', coverage_json TEXT NOT NULL DEFAULT '{}', - created_at INTEGER NOT NULL DEFAULT 0, + created_at INTEGER NOT NULL DEFAULT 0, -- epoch ms (Date.now()) UNIQUE(dedup_key, cohort_key) ); CREATE INDEX IF NOT EXISTS idx_embedding_measurement_session @@ -2814,7 +2814,7 @@ export const MIGRATIONS: Migration[] = [ stage_path TEXT NOT NULL, content_sha256 TEXT NOT NULL, phase TEXT NOT NULL CHECK (phase IN ('staged', 'db_committed')), - created_at INTEGER NOT NULL + created_at INTEGER NOT NULL -- epoch ms (Date.now()) ); `); }, diff --git a/packages/plugin/src/features/magic-context/storage-db.ts b/packages/plugin/src/features/magic-context/storage-db.ts index 60c35d908..97fce8154 100644 --- a/packages/plugin/src/features/magic-context/storage-db.ts +++ b/packages/plugin/src/features/magic-context/storage-db.ts @@ -963,7 +963,7 @@ export function initializeDatabase( p1_embedding BLOB, p1_embedding_model_id TEXT, legacy INTEGER NOT NULL DEFAULT 0, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) harness TEXT NOT NULL DEFAULT 'opencode', UNIQUE(session_id, sequence) ); @@ -982,7 +982,7 @@ export function initializeDatabase( model_id TEXT NOT NULL, dims INTEGER NOT NULL, vector BLOB NOT NULL, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) UNIQUE(compartment_id, model_id, window_index) ); CREATE INDEX IF NOT EXISTS idx_cce_session ON compartment_chunk_embeddings(session_id); @@ -1005,7 +1005,7 @@ export function initializeDatabase( kind TEXT NOT NULL, at_compartment INTEGER, fields_json TEXT NOT NULL DEFAULT '{}', - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) harness TEXT NOT NULL DEFAULT 'opencode' ); CREATE INDEX IF NOT EXISTS idx_compartment_events_session @@ -1034,7 +1034,7 @@ export function initializeDatabase( session_id TEXT NOT NULL, category TEXT NOT NULL, content TEXT NOT NULL, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) updated_at INTEGER NOT NULL, harness TEXT NOT NULL DEFAULT 'opencode' ); @@ -1053,7 +1053,7 @@ export function initializeDatabase( source_message_time INTEGER NOT NULL, question_embedding BLOB, question_embedding_model_id TEXT, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) UNIQUE(project_path, harness, session_id, source_start_message_id, source_end_message_id) ); CREATE INDEX IF NOT EXISTS idx_primer_candidates_project_time @@ -1076,7 +1076,7 @@ export function initializeDatabase( answer_refreshed_at INTEGER, source_candidate_ids TEXT NOT NULL DEFAULT '[]', source_candidate_provenance TEXT, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) updated_at INTEGER NOT NULL ); CREATE INDEX IF NOT EXISTS idx_primers_project_status_observed @@ -1129,7 +1129,7 @@ export function initializeDatabase( seen_count INTEGER DEFAULT 1, retrieval_count INTEGER DEFAULT 0, first_seen_at INTEGER NOT NULL, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) updated_at INTEGER NOT NULL, last_seen_at INTEGER NOT NULL, last_retrieved_at INTEGER, @@ -1189,7 +1189,7 @@ export function initializeDatabase( job_id TEXT, cursor TEXT, status TEXT NOT NULL DEFAULT 'pending', - created_at INTEGER NOT NULL DEFAULT 0, + created_at INTEGER NOT NULL DEFAULT 0, -- epoch ms (Date.now()) updated_at INTEGER NOT NULL DEFAULT 0, UNIQUE(session_id, request_key) ); @@ -1230,7 +1230,7 @@ export function initializeDatabase( shadow_epoch INTEGER NOT NULL DEFAULT 0, corpus_hash TEXT NOT NULL DEFAULT '', coverage_json TEXT NOT NULL DEFAULT '{}', - created_at INTEGER NOT NULL DEFAULT 0, + created_at INTEGER NOT NULL DEFAULT 0, -- epoch ms (Date.now()) UNIQUE(dedup_key, cohort_key) ); CREATE INDEX IF NOT EXISTS idx_embedding_measurement_session @@ -1384,7 +1384,7 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en CREATE TABLE IF NOT EXISTS workspaces ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL UNIQUE, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) updated_at INTEGER NOT NULL, share_categories TEXT NOT NULL DEFAULT '["CONSTRAINTS"]' ); @@ -1655,7 +1655,7 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en importance_avg REAL, discarded_last INTEGER NOT NULL DEFAULT 0, legacy INTEGER NOT NULL DEFAULT 0, - created_at INTEGER NOT NULL + created_at INTEGER NOT NULL -- epoch ms (Date.now()) ); CREATE INDEX IF NOT EXISTS idx_historian_runs_session ON historian_runs(session_id, created_at DESC); @@ -1708,7 +1708,7 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en importance INTEGER NOT NULL DEFAULT 50, episode_type TEXT, pass_number INTEGER NOT NULL, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) harness TEXT NOT NULL DEFAULT 'opencode', UNIQUE(session_id, sequence) ); @@ -1719,7 +1719,7 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en category TEXT NOT NULL, content TEXT NOT NULL, pass_number INTEGER NOT NULL, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) harness TEXT NOT NULL DEFAULT 'opencode' ); @@ -2100,7 +2100,7 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en CREATE TABLE IF NOT EXISTS workspaces ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL UNIQUE, - created_at INTEGER NOT NULL, + created_at INTEGER NOT NULL, -- epoch ms (Date.now()) updated_at INTEGER NOT NULL, share_categories TEXT NOT NULL DEFAULT '["CONSTRAINTS"]' );