refactor: squash DB migrations 1-22 into a single baseline schema
base-schema.ts now holds the full schema at version 22, taken from the
production database (column order, indexes, provenance triggers), so a
fresh database is identical to the live one. Previously a fresh DB
differed: it had an extra idx_messages_chat_timestamp index and a
different column order in paired_tasks and paired_turn_outputs.
The migration runner keeps schema_migrations:
- empty DB: apply the baseline and record version 22 ('baseline')
- existing DB: must already be at version >= 22 (the live DB records
1-22), otherwise startup refuses it without touching it
- later migrations (23+) run once each inside a transaction
Removed the 22 historical migrations, the legacy schema bundle, the
paired-turn provenance rebuild/backfill helpers that migration 10 replayed
on every start (all no-ops on the live DB), legacy session migration
helpers, the unused service handoff metadata helpers, and the tests that
only exercised legacy-schema upgrades. New schema tests check a fresh DB
against a snapshot dumped from production and that reopening a DB at the
baseline changes neither schema nor data.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,8 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { Database } from 'bun:sqlite';
|
||||
|
||||
import { applySchemaMigrations } from '../src/db/migrations/index.js';
|
||||
|
||||
describe('migrate room registrations step', () => {
|
||||
const tempRoots: string[] = [];
|
||||
|
||||
@@ -31,6 +33,7 @@ describe('migrate room registrations step', () => {
|
||||
|
||||
const dbPath = path.join(storeDir, 'messages.db');
|
||||
const legacyDb = new Database(dbPath);
|
||||
applySchemaMigrations(legacyDb);
|
||||
legacyDb.exec(`
|
||||
CREATE TABLE registered_groups (
|
||||
jid TEXT NOT NULL,
|
||||
@@ -218,20 +221,8 @@ describe('migrate room registrations step', () => {
|
||||
|
||||
const dbPath = path.join(storeDir, 'messages.db');
|
||||
const legacyDb = new Database(dbPath);
|
||||
applySchemaMigrations(legacyDb);
|
||||
legacyDb.exec(`
|
||||
CREATE TABLE room_settings (
|
||||
chat_jid TEXT PRIMARY KEY,
|
||||
room_mode TEXT NOT NULL,
|
||||
mode_source TEXT NOT NULL DEFAULT 'explicit',
|
||||
name TEXT,
|
||||
folder TEXT,
|
||||
trigger_pattern TEXT,
|
||||
requires_trigger INTEGER DEFAULT 1,
|
||||
is_main INTEGER DEFAULT 0,
|
||||
owner_agent_type TEXT,
|
||||
work_dir TEXT,
|
||||
updated_at TEXT NOT NULL
|
||||
);
|
||||
CREATE TABLE registered_groups (
|
||||
jid TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
|
||||
Reference in New Issue
Block a user