import { describe, expect, it } from 'bun:test'; import { readFileSync } from 'node:fs'; import { join } from 'node:path'; import { Database } from 'bun:sqlite'; import { __dbInternals } from './index'; function applyMigration(client: Database, fileName: string) { const sql = readFileSync(join(process.cwd(), 'drizzle', fileName), 'utf8'); client.exec(sql); } describe('sqlite schema compatibility bootstrap', () => { it('adds missing watchlist columns and taxonomy tables for older local databases', () => { const client = new Database(':memory:'); client.exec('PRAGMA foreign_keys = ON;'); applyMigration(client, '0000_cold_silver_centurion.sql'); applyMigration(client, '0001_glossy_statement_snapshots.sql'); applyMigration(client, '0002_workflow_task_projection_metadata.sql'); applyMigration(client, '0003_task_stage_event_timeline.sql'); expect(__dbInternals.hasColumn(client, 'watchlist_item', 'category')).toBe(false); expect(__dbInternals.hasTable(client, 'filing_taxonomy_snapshot')).toBe(false); __dbInternals.ensureLocalSqliteSchema(client); expect(__dbInternals.hasColumn(client, 'watchlist_item', 'category')).toBe(true); expect(__dbInternals.hasColumn(client, 'watchlist_item', 'tags')).toBe(true); expect(__dbInternals.hasTable(client, 'filing_taxonomy_snapshot')).toBe(true); expect(__dbInternals.hasTable(client, 'filing_taxonomy_fact')).toBe(true); client.close(); }); });