import type { Change, SchemaSnapshot } from "../types.js"; /** * Result of the D1 FK-cascade emitter: either a validated cascade (with the * affected-table set so the dispatcher can partition the remaining changes) or a * refusal because the affected tables form a foreign-key cycle. */ export type D1CascadeResult = { up: string; downWarning: string; affected: Set; handledViews: Set; } | { refuseCycle: string[]; }; /** * Emit the D1-legal FK-cascade rebuild for a set of recreated tables and every * table transitively referencing them. * * On remote D1 the plain SQLite recreate-and-copy recipe fails: its `PRAGMA * foreign_keys = OFF` is a no-op inside D1's implicit transaction, so dropping a * referenced table raises "FOREIGN KEY constraint failed". This emitter instead * rebuilds the WHOLE affected set inside one implicit transaction, deferring FK * enforcement to commit via `PRAGMA defer_foreign_keys = ON`: * * 1. `PRAGMA defer_foreign_keys = ON;` * 2. CREATE `__f_` for each affected `t` (FKs whose target is also affected * are rewritten to the target's temp name). * 3. INSERT the carried columns from each old table into its temp. * 4. DROP the old tables referrers-first (reverse topological order). * 5. RENAME each temp to the real name parents-first (topological order), * recreating that table's indexes immediately after its rename. * * No `BEGIN/COMMIT` and no `foreign_keys = OFF/ON` bracket: D1 runs the file in * one implicit transaction and the safety pass would strip the former anyway. * * `renderD1` only calls this when `actualSchema` is present, so it is required. */ export declare function emitD1Cascade(changes: readonly Change[], expectedSchema: SchemaSnapshot, actualSchema: SchemaSnapshot, recreatedTables: ReadonlySet): D1CascadeResult; //# sourceMappingURL=d1-cascade.d.ts.map