refactor(server): delete baseline + heal functions now unreachable under single-baseline history

baselineExistingInstall, healInitialSchemaDrift, and healRenamedColumns
existed only because of pre-squash intermediate states: dev DBs drifted
against drizzle-kit's assumed 0000 baseline, or carried pre-rename
columns from the old manual migration system. Under a single squashed
baseline there are no intermediate states to drift against, and these
functions are unreachable.

initDatabase() is now: pragmas -> drizzle() -> migrate() -> ensureDefaults().
ensureDefaults stays (idempotent startup seeding for settings row, worker
ID, first-admin promotion).

Refs backlog #31 Phase 2.
This commit is contained in:
Jannis Braun
2026-04-24 23:33:35 +02:00
parent 707d3217f1
commit ab5e7c8839
2 changed files with 1 additions and 367 deletions
+1 -19
View File
@@ -3,7 +3,7 @@ import { drizzle } from 'drizzle-orm/better-sqlite3';
import { migrate } from 'drizzle-orm/better-sqlite3/migrator';
import { config } from '../config.js';
import * as schema from './schema.js';
import { baselineExistingInstall, healInitialSchemaDrift, healRenamedColumns, ensureDefaults } from './migrate.js';
import { ensureDefaults } from './migrate.js';
import { setWorkerId } from '../utils/snowflake.js';
import { mkdirSync } from 'fs';
import { dirname, resolve } from 'path';
@@ -24,24 +24,6 @@ export function initDatabase() {
sqlite.pragma('journal_mode = WAL');
sqlite.pragma('foreign_keys = ON');
// Baseline existing installs before Drizzle migrate() runs —
// marks the initial migration as applied so it doesn't try to
// CREATE TABLE on a database that already has tables.
baselineExistingInstall(sqlite);
// Reconcile any columns present in the 0000 baseline but missing
// from the physical schema. Fixes drift between the pre-drizzle
// manual migration system and drizzle-kit's assumed baseline —
// a no-op on fresh installs and correctly-migrated DBs.
healInitialSchemaDrift(sqlite);
// Second-pass heal for rename/removal drift that the ADD-only pass
// can't resolve: for tables whose column set still doesn't match
// the 0000 snapshot and which are empty, DROP and rebuild from
// 0000_initial.sql. Non-empty tables are skipped with a warning.
// No-op on correctly-migrated DBs.
healRenamedColumns(sqlite);
// Apply any pending Drizzle migrations
const migrationsFolder = resolve(__dirname, '../../drizzle');
const db = drizzle(sqlite, { schema });