/** * Parent-first table ordering for legacy copies — a dependency-free leaf. * * Lives outside `migrate.ts` so the tasks-domain store (`sqlite.ts` → * `legacy-tasks-lineage.ts`) can use it without pulling the exodus engine — * whose recovery module loads `node:sqlite` at import — into the store's * module graph (T1331 lazy-init contract; T12355). * * @module */ import type { DatabaseSync } from 'node:sqlite'; /** * Order a legacy DB's tables so every referenced (parent) table is copied * before the tables that reference it, using the SOURCE schema's foreign keys. * * `foreign_keys=OFF` defers FK enforcement during the bulk copy, but it does NOT * defer triggers. The consolidated project schema carries `BEFORE INSERT` guards * that look the parent up in `tasks_tasks` — e.g. * `tasks_task_acceptance_child_target_insert` raises * `E_CHILD_TASK_TARGET_CONTAINMENT` unless the criterion's child task already * exists. Alphabetical order copied `task_acceptance_criteria` BEFORE `tasks`, * so every legitimate `child_task` criterion was rejected and the whole * migration aborted, leaving `cleo.db` empty (T12319: 493 valid criteria in * llmtxt, zero actual violations in the source). * * Kahn's algorithm with alphabetical tie-breaking keeps the order deterministic; * self-references and references to tables outside the set are ignored, and a * cycle releases its alphabetically-first member so progress continues. * * @param db - Read-only handle on the legacy source DB. * @returns Table names, parents before children. * @task T12319 */ export declare function orderTablesForCopy(db: DatabaseSync): string[]; /** Quote an SQLite identifier. */ export declare function ident(name: string): string; /** Whether `schema.table` exists on `db`. */ export declare function hasTable(db: DatabaseSync, schema: string, table: string): boolean; /** Row count of `schema.table`. */ export declare function countRows(db: DatabaseSync, schema: string, table: string): number; //# sourceMappingURL=table-order.d.ts.map