WIP main worktree changes before merge
This commit is contained in:
@@ -4,6 +4,10 @@ import { dirname } from 'node:path';
|
||||
import { Database } from 'bun:sqlite';
|
||||
import { drizzle } from 'drizzle-orm/bun-sqlite';
|
||||
import { migrate } from 'drizzle-orm/bun-sqlite/migrator';
|
||||
import {
|
||||
ensureFinancialIngestionSchemaHealthy,
|
||||
resolveFinancialSchemaRepairMode
|
||||
} from '../lib/server/db/financial-ingestion-schema';
|
||||
import { resolveSqlitePath } from './dev-env';
|
||||
|
||||
function trim(value: string | undefined) {
|
||||
@@ -74,6 +78,13 @@ function runDatabaseMigrations() {
|
||||
try {
|
||||
client.exec('PRAGMA foreign_keys = ON;');
|
||||
migrate(drizzle(client), { migrationsFolder: './drizzle' });
|
||||
|
||||
const repairResult = ensureFinancialIngestionSchemaHealthy(client, {
|
||||
mode: resolveFinancialSchemaRepairMode(process.env.FINANCIAL_SCHEMA_REPAIR_MODE)
|
||||
});
|
||||
if (!repairResult.ok) {
|
||||
throw new Error(repairResult.error ?? `financial ingestion schema is ${repairResult.mode}`);
|
||||
}
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,10 @@ import { mkdirSync, readFileSync } from 'node:fs';
|
||||
import { Database } from 'bun:sqlite';
|
||||
import { createServer } from 'node:net';
|
||||
import { dirname, join } from 'node:path';
|
||||
import {
|
||||
ensureFinancialIngestionSchemaHealthy,
|
||||
resolveFinancialSchemaRepairMode
|
||||
} from '../lib/server/db/financial-ingestion-schema';
|
||||
import { buildLocalDevConfig, resolveSqlitePath } from './dev-env';
|
||||
|
||||
type DrizzleJournal = {
|
||||
@@ -126,6 +130,33 @@ mkdirSync(env.WORKFLOW_LOCAL_DATA_DIR ?? '.workflow-data', { recursive: true });
|
||||
|
||||
const initializedDatabase = bootstrapFreshDatabase(env.DATABASE_URL ?? '');
|
||||
|
||||
if (!initializedDatabase && databasePath && databasePath !== ':memory:') {
|
||||
const client = new Database(databasePath, { create: true });
|
||||
|
||||
try {
|
||||
client.exec('PRAGMA foreign_keys = ON;');
|
||||
const repairResult = ensureFinancialIngestionSchemaHealthy(client, {
|
||||
mode: resolveFinancialSchemaRepairMode(env.FINANCIAL_SCHEMA_REPAIR_MODE)
|
||||
});
|
||||
|
||||
if (repairResult.mode === 'repaired') {
|
||||
console.info(
|
||||
`[dev] repaired financial ingestion schema (missing indexes: ${repairResult.repair?.missingIndexesBefore.join(', ') || 'none'}; duplicate groups resolved: ${repairResult.repair?.duplicateGroupsResolved ?? 0}; bundle cache cleared: ${repairResult.repair?.bundleCacheCleared ? 'yes' : 'no'})`
|
||||
);
|
||||
} else if (repairResult.mode === 'drifted') {
|
||||
console.warn(
|
||||
`[dev] financial ingestion schema drift detected (missing indexes: ${repairResult.missingIndexes.join(', ') || 'none'}; duplicate groups: ${repairResult.duplicateGroups})`
|
||||
);
|
||||
} else if (repairResult.mode === 'failed') {
|
||||
console.warn(
|
||||
`[dev] financial ingestion schema repair failed: ${repairResult.error ?? 'unknown error'}`
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
console.info(`[dev] local origin ${config.publicOrigin}`);
|
||||
console.info(`[dev] sqlite ${env.DATABASE_URL}`);
|
||||
console.info(`[dev] workflow ${env.WORKFLOW_TARGET_WORLD} (${env.WORKFLOW_LOCAL_DATA_DIR})`);
|
||||
|
||||
Reference in New Issue
Block a user