/** * Deterministic constraint-ordering pass over a single drizzle-kit-generated * Postgres migration file. * * drizzle-kit `generate` emits an incremental delta as a sequence of * statements separated by `--> statement-breakpoint`. When an upgrade adds a * composite UNIQUE (or PRIMARY KEY) constraint to a parent table AND a new * foreign key on a child table that REFERENCES that column set, drizzle-kit * can emit the child `ADD CONSTRAINT … FOREIGN KEY` BEFORE the parent * `ADD CONSTRAINT … UNIQUE`. Postgres then rejects the FK at apply time with * * there is no unique constraint matching given keys for referenced table * * (A real Attend upgrade delta placed 17 parent UNIQUE constraints after the * FKs consuming them.) Constraint replacements expose the inverse problem: * drizzle-kit can emit the parent `DROP CONSTRAINT … UNIQUE` before dropping * the child FK that still depends on it. Postgres rejects that with 2BP01. * * This pass reorders ONLY those dependency-linked standalone statements: * * - a UNIQUE/PRIMARY KEY add is pulled before the earliest FK add consuming it; * - a replacement FK drop is pulled before the referenced UNIQUE/PK drop. * * A bare DROP does not encode its constraint type, so replacement-drop * dependencies are inferred from the same-named ADD definitions later in the * delta. Statements not participating in a UNIQUE↔FK dependency keep their * relative order. The transform is therefore a no-op (byte-identical output) * on any already-correct migration — including every fresh * `0000_*.sql`, where UNIQUE constraints are inline in CREATE TABLE. */ /** * Reorder standalone constraint statements within one migration file so a * referenced UNIQUE/PRIMARY KEY precedes every FK that consumes it when adding * constraints, and every dependent FK precedes that referenced key when * dropping replacement constraints. Returns the input unchanged * (byte-identical) when nothing is misordered. */ export declare function reorderPgConstraintStatements(sql: string): string; //# sourceMappingURL=migration-reorder.d.ts.map