Fix SQLite taxonomy schema bootstrap drift
This commit is contained in:
@@ -1,46 +1,38 @@
|
||||
import { mkdirSync, readFileSync, rmSync } from 'node:fs';
|
||||
import { mkdirSync, rmSync } from 'node:fs';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { Database } from 'bun:sqlite';
|
||||
|
||||
const MIGRATION_FILES = [
|
||||
'0000_cold_silver_centurion.sql',
|
||||
'0001_glossy_statement_snapshots.sql',
|
||||
'0002_workflow_task_projection_metadata.sql',
|
||||
'0003_task_stage_event_timeline.sql',
|
||||
'0004_watchlist_company_taxonomy.sql',
|
||||
'0005_financial_taxonomy_v3.sql',
|
||||
'0006_coverage_journal_tracking.sql',
|
||||
'0007_company_financial_bundles.sql',
|
||||
'0008_research_workspace.sql'
|
||||
] as const;
|
||||
import { ensureFinancialIngestionSchemaHealthy } from '../lib/server/db/financial-ingestion-schema';
|
||||
import { ensureLocalSqliteSchema } from '../lib/server/db/sqlite-schema-compat';
|
||||
|
||||
export const E2E_DATABASE_PATH = join(process.cwd(), 'data', 'e2e.sqlite');
|
||||
export const E2E_WORKFLOW_DATA_DIR = join(process.cwd(), '.workflow-data', 'e2e');
|
||||
|
||||
type PrepareE2eDatabaseOptions = {
|
||||
databasePath?: string;
|
||||
workflowDataDir?: string;
|
||||
};
|
||||
|
||||
function removeFileIfPresent(path: string) {
|
||||
rmSync(path, { force: true });
|
||||
}
|
||||
|
||||
function applyMigrations(database: Database) {
|
||||
for (const file of MIGRATION_FILES) {
|
||||
const sql = readFileSync(join(process.cwd(), 'drizzle', file), 'utf8');
|
||||
database.exec(sql);
|
||||
}
|
||||
}
|
||||
export function prepareE2eDatabase(options: PrepareE2eDatabaseOptions = {}) {
|
||||
const databasePath = options.databasePath ?? E2E_DATABASE_PATH;
|
||||
const workflowDataDir = options.workflowDataDir ?? E2E_WORKFLOW_DATA_DIR;
|
||||
|
||||
export function prepareE2eDatabase() {
|
||||
mkdirSync(dirname(E2E_DATABASE_PATH), { recursive: true });
|
||||
mkdirSync(dirname(databasePath), { recursive: true });
|
||||
|
||||
removeFileIfPresent(E2E_DATABASE_PATH);
|
||||
removeFileIfPresent(`${E2E_DATABASE_PATH}-shm`);
|
||||
removeFileIfPresent(`${E2E_DATABASE_PATH}-wal`);
|
||||
rmSync(E2E_WORKFLOW_DATA_DIR, { force: true, recursive: true });
|
||||
removeFileIfPresent(databasePath);
|
||||
removeFileIfPresent(`${databasePath}-shm`);
|
||||
removeFileIfPresent(`${databasePath}-wal`);
|
||||
rmSync(workflowDataDir, { force: true, recursive: true });
|
||||
|
||||
const database = new Database(E2E_DATABASE_PATH, { create: true });
|
||||
const database = new Database(databasePath, { create: true });
|
||||
|
||||
try {
|
||||
database.exec('PRAGMA foreign_keys = ON;');
|
||||
applyMigrations(database);
|
||||
ensureLocalSqliteSchema(database);
|
||||
ensureFinancialIngestionSchemaHealthy(database, { mode: 'auto' });
|
||||
} finally {
|
||||
database.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user