@quickback-dev/cli 0.60.4 → 0.60.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/compile.d.ts.map +1 -1
- package/dist/commands/compile.js +89 -13
- package/dist/commands/compile.js.map +1 -1
- package/dist/commands/compile.test.js +52 -5
- package/dist/commands/compile.test.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/api-client.d.ts +15 -0
- package/dist/lib/api-client.d.ts.map +1 -1
- package/dist/lib/api-client.js.map +1 -1
- package/dist/lib/file-loader-typescript-fallback.test.d.ts +2 -0
- package/dist/lib/file-loader-typescript-fallback.test.d.ts.map +1 -0
- package/dist/lib/file-loader-typescript-fallback.test.js +58 -0
- package/dist/lib/file-loader-typescript-fallback.test.js.map +1 -0
- package/dist/lib/file-loader.d.ts +17 -0
- package/dist/lib/file-loader.d.ts.map +1 -1
- package/dist/lib/file-loader.js +64 -12
- package/dist/lib/file-loader.js.map +1 -1
- package/dist/lib/migrations/commit.d.ts +38 -0
- package/dist/lib/migrations/commit.d.ts.map +1 -0
- package/dist/lib/migrations/commit.js +39 -0
- package/dist/lib/migrations/commit.js.map +1 -0
- package/dist/lib/migrations/drizzle-prompts.d.ts +97 -0
- package/dist/lib/migrations/drizzle-prompts.d.ts.map +1 -0
- package/dist/lib/migrations/drizzle-prompts.js +190 -0
- package/dist/lib/migrations/drizzle-prompts.js.map +1 -0
- package/dist/lib/migrations/drizzle-prompts.test.d.ts +2 -0
- package/dist/lib/migrations/drizzle-prompts.test.d.ts.map +1 -0
- package/dist/lib/migrations/drizzle-prompts.test.js +135 -0
- package/dist/lib/migrations/drizzle-prompts.test.js.map +1 -0
- package/dist/lib/migrations/drizzle-wrapper.d.ts +28 -0
- package/dist/lib/migrations/drizzle-wrapper.d.ts.map +1 -0
- package/dist/lib/migrations/drizzle-wrapper.js +63 -0
- package/dist/lib/migrations/drizzle-wrapper.js.map +1 -0
- package/dist/lib/migrations/executor.d.ts +4 -1
- package/dist/lib/migrations/executor.d.ts.map +1 -1
- package/dist/lib/migrations/executor.js +0 -6
- package/dist/lib/migrations/executor.js.map +1 -1
- package/dist/lib/migrations/file-envelopes.d.ts +42 -0
- package/dist/lib/migrations/file-envelopes.d.ts.map +1 -0
- package/dist/lib/migrations/file-envelopes.js +255 -0
- package/dist/lib/migrations/file-envelopes.js.map +1 -0
- package/dist/lib/migrations/postprocessors/audit-migration-hardening.d.ts +29 -0
- package/dist/lib/migrations/postprocessors/audit-migration-hardening.d.ts.map +1 -0
- package/dist/lib/migrations/postprocessors/audit-migration-hardening.js +67 -0
- package/dist/lib/migrations/postprocessors/audit-migration-hardening.js.map +1 -0
- package/dist/lib/migrations/postprocessors/index.d.ts +58 -0
- package/dist/lib/migrations/postprocessors/index.d.ts.map +1 -0
- package/dist/lib/migrations/postprocessors/index.js +344 -0
- package/dist/lib/migrations/postprocessors/index.js.map +1 -0
- package/dist/lib/migrations/postprocessors/index.test.d.ts +2 -0
- package/dist/lib/migrations/postprocessors/index.test.d.ts.map +1 -0
- package/dist/lib/migrations/postprocessors/index.test.js +298 -0
- package/dist/lib/migrations/postprocessors/index.test.js.map +1 -0
- package/dist/lib/migrations/postprocessors/migration-reorder.d.ts +39 -0
- package/dist/lib/migrations/postprocessors/migration-reorder.d.ts.map +1 -0
- package/dist/lib/migrations/postprocessors/migration-reorder.js +185 -0
- package/dist/lib/migrations/postprocessors/migration-reorder.js.map +1 -0
- package/dist/lib/migrations/postprocessors/trigger-sql.d.ts +51 -0
- package/dist/lib/migrations/postprocessors/trigger-sql.d.ts.map +1 -0
- package/dist/lib/migrations/postprocessors/trigger-sql.js +62 -0
- package/dist/lib/migrations/postprocessors/trigger-sql.js.map +1 -0
- package/dist/lib/migrations/prior-state.d.ts +63 -0
- package/dist/lib/migrations/prior-state.d.ts.map +1 -0
- package/dist/lib/migrations/prior-state.js +141 -0
- package/dist/lib/migrations/prior-state.js.map +1 -0
- package/dist/lib/migrations/prompt-runner.d.ts +32 -0
- package/dist/lib/migrations/prompt-runner.d.ts.map +1 -0
- package/dist/lib/migrations/prompt-runner.js +158 -0
- package/dist/lib/migrations/prompt-runner.js.map +1 -0
- package/dist/lib/migrations/prompt-runner.test.d.ts +2 -0
- package/dist/lib/migrations/prompt-runner.test.d.ts.map +1 -0
- package/dist/lib/migrations/prompt-runner.test.js +131 -0
- package/dist/lib/migrations/prompt-runner.test.js.map +1 -0
- package/dist/lib/migrations/schema-contract.d.ts +44 -0
- package/dist/lib/migrations/schema-contract.d.ts.map +1 -0
- package/dist/lib/migrations/schema-contract.js +51 -0
- package/dist/lib/migrations/schema-contract.js.map +1 -0
- package/dist/skill/docs/api/errors.md +1 -0
- package/dist/skill/docs/configure/domains.md +84 -0
- package/dist/skill/docs/define/firewall.md +1 -0
- package/dist/skill/docs/define/masking.md +16 -1
- package/dist/skill/docs/define/relationships.md +35 -0
- package/dist/skill/docs/define/schema.md +20 -0
- package/dist/skill/docs/platform/database/d1.md +14 -0
- package/dist/skill/docs/platform/database/neon.md +12 -5
- package/dist/skill/docs/start/deploy-browser.md +3 -0
- package/dist/skill/docs/tooling/cli.md +15 -0
- package/dist/skill/docs/tooling/output.md +28 -10
- package/package.json +2 -2
- package/src/skill/docs/api/errors.md +1 -0
- package/src/skill/docs/configure/domains.md +84 -0
- package/src/skill/docs/define/firewall.md +1 -0
- package/src/skill/docs/define/masking.md +16 -1
- package/src/skill/docs/define/relationships.md +35 -0
- package/src/skill/docs/define/schema.md +20 -0
- package/src/skill/docs/platform/database/d1.md +14 -0
- package/src/skill/docs/platform/database/neon.md +12 -5
- package/src/skill/docs/start/deploy-browser.md +3 -0
- package/src/skill/docs/tooling/cli.md +15 -0
- package/src/skill/docs/tooling/output.md +28 -10
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../../../src/lib/migrations/postprocessors/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,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C,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAC1F,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;IACxB,IAAI,CAAC,sDAAsD,EAAE,KAAK,IAAI,EAAE;QACtE,MAAM,QAAQ,GAAG,6BAA6B,EAAE,CAAC;QACjD,qEAAqE;QACrE,8DAA8D;QAC9D,KAAK,MAAM,EAAE,IAAI;YACf,WAAW;YACX,gBAAgB;YAChB,wBAAwB;YACxB,cAAc;YACd,YAAY;YACZ,iBAAiB;SACT,EAAE,CAAC;YACX,MAAM,CAAC,OAAO,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic constraint-ordering pass over a single drizzle-kit-generated
|
|
3
|
+
* Postgres migration file.
|
|
4
|
+
*
|
|
5
|
+
* drizzle-kit `generate` emits an incremental delta as a sequence of
|
|
6
|
+
* statements separated by `--> statement-breakpoint`. When an upgrade adds a
|
|
7
|
+
* composite UNIQUE (or PRIMARY KEY) constraint to a parent table AND a new
|
|
8
|
+
* foreign key on a child table that REFERENCES that column set, drizzle-kit
|
|
9
|
+
* can emit the child `ADD CONSTRAINT … FOREIGN KEY` BEFORE the parent
|
|
10
|
+
* `ADD CONSTRAINT … UNIQUE`. Postgres then rejects the FK at apply time with
|
|
11
|
+
*
|
|
12
|
+
* there is no unique constraint matching given keys for referenced table
|
|
13
|
+
*
|
|
14
|
+
* (A real Attend upgrade delta placed 17 parent UNIQUE constraints after the
|
|
15
|
+
* FKs consuming them.) Constraint replacements expose the inverse problem:
|
|
16
|
+
* drizzle-kit can emit the parent `DROP CONSTRAINT … UNIQUE` before dropping
|
|
17
|
+
* the child FK that still depends on it. Postgres rejects that with 2BP01.
|
|
18
|
+
*
|
|
19
|
+
* This pass reorders ONLY those dependency-linked standalone statements:
|
|
20
|
+
*
|
|
21
|
+
* - a UNIQUE/PRIMARY KEY add is pulled before the earliest FK add consuming it;
|
|
22
|
+
* - a replacement FK drop is pulled before the referenced UNIQUE/PK drop.
|
|
23
|
+
*
|
|
24
|
+
* A bare DROP does not encode its constraint type, so replacement-drop
|
|
25
|
+
* dependencies are inferred from the same-named ADD definitions later in the
|
|
26
|
+
* delta. Statements not participating in a UNIQUE↔FK dependency keep their
|
|
27
|
+
* relative order. The transform is therefore a no-op (byte-identical output)
|
|
28
|
+
* on any already-correct migration — including every fresh
|
|
29
|
+
* `0000_*.sql`, where UNIQUE constraints are inline in CREATE TABLE.
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Reorder standalone constraint statements within one migration file so a
|
|
33
|
+
* referenced UNIQUE/PRIMARY KEY precedes every FK that consumes it when adding
|
|
34
|
+
* constraints, and every dependent FK precedes that referenced key when
|
|
35
|
+
* dropping replacement constraints. Returns the input unchanged
|
|
36
|
+
* (byte-identical) when nothing is misordered.
|
|
37
|
+
*/
|
|
38
|
+
export declare function reorderPgConstraintStatements(sql: string): string;
|
|
39
|
+
//# sourceMappingURL=migration-reorder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-reorder.d.ts","sourceRoot":"","sources":["../../../../src/lib/migrations/postprocessors/migration-reorder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AA6EH;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAqFjE"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic constraint-ordering pass over a single drizzle-kit-generated
|
|
3
|
+
* Postgres migration file.
|
|
4
|
+
*
|
|
5
|
+
* drizzle-kit `generate` emits an incremental delta as a sequence of
|
|
6
|
+
* statements separated by `--> statement-breakpoint`. When an upgrade adds a
|
|
7
|
+
* composite UNIQUE (or PRIMARY KEY) constraint to a parent table AND a new
|
|
8
|
+
* foreign key on a child table that REFERENCES that column set, drizzle-kit
|
|
9
|
+
* can emit the child `ADD CONSTRAINT … FOREIGN KEY` BEFORE the parent
|
|
10
|
+
* `ADD CONSTRAINT … UNIQUE`. Postgres then rejects the FK at apply time with
|
|
11
|
+
*
|
|
12
|
+
* there is no unique constraint matching given keys for referenced table
|
|
13
|
+
*
|
|
14
|
+
* (A real Attend upgrade delta placed 17 parent UNIQUE constraints after the
|
|
15
|
+
* FKs consuming them.) Constraint replacements expose the inverse problem:
|
|
16
|
+
* drizzle-kit can emit the parent `DROP CONSTRAINT … UNIQUE` before dropping
|
|
17
|
+
* the child FK that still depends on it. Postgres rejects that with 2BP01.
|
|
18
|
+
*
|
|
19
|
+
* This pass reorders ONLY those dependency-linked standalone statements:
|
|
20
|
+
*
|
|
21
|
+
* - a UNIQUE/PRIMARY KEY add is pulled before the earliest FK add consuming it;
|
|
22
|
+
* - a replacement FK drop is pulled before the referenced UNIQUE/PK drop.
|
|
23
|
+
*
|
|
24
|
+
* A bare DROP does not encode its constraint type, so replacement-drop
|
|
25
|
+
* dependencies are inferred from the same-named ADD definitions later in the
|
|
26
|
+
* delta. Statements not participating in a UNIQUE↔FK dependency keep their
|
|
27
|
+
* relative order. The transform is therefore a no-op (byte-identical output)
|
|
28
|
+
* on any already-correct migration — including every fresh
|
|
29
|
+
* `0000_*.sql`, where UNIQUE constraints are inline in CREATE TABLE.
|
|
30
|
+
*/
|
|
31
|
+
const BREAKPOINT = '--> statement-breakpoint';
|
|
32
|
+
/** Normalize a possibly-quoted, possibly-schema-qualified table ref to `schema.table` (unquoted). */
|
|
33
|
+
function normTable(ref) {
|
|
34
|
+
return ref
|
|
35
|
+
.trim()
|
|
36
|
+
.split('.')
|
|
37
|
+
.map((part) => part.replace(/^"(.*)"$/, '$1').trim())
|
|
38
|
+
.join('.');
|
|
39
|
+
}
|
|
40
|
+
/** Parse a parenthesized column list into a normalized, order-independent key part. */
|
|
41
|
+
function normCols(cols) {
|
|
42
|
+
return cols
|
|
43
|
+
.split(',')
|
|
44
|
+
.map((c) => c.replace(/^\s*"?(.*?)"?\s*$/, '$1'))
|
|
45
|
+
.filter((c) => c.length > 0)
|
|
46
|
+
.sort()
|
|
47
|
+
.join(',');
|
|
48
|
+
}
|
|
49
|
+
/** Key identifying a unique column set on a referenced table: `schema.table::col,col`. */
|
|
50
|
+
function refKey(table, cols) {
|
|
51
|
+
return `${normTable(table)}::${normCols(cols)}`;
|
|
52
|
+
}
|
|
53
|
+
/** Normalize one quoted or unquoted Postgres identifier. */
|
|
54
|
+
function normIdent(ident) {
|
|
55
|
+
const trimmed = ident.trim();
|
|
56
|
+
if (trimmed.startsWith('"') && trimmed.endsWith('"')) {
|
|
57
|
+
return trimmed.slice(1, -1).replace(/""/g, '"');
|
|
58
|
+
}
|
|
59
|
+
return trimmed;
|
|
60
|
+
}
|
|
61
|
+
const CONSTRAINT_IDENT = '(?:"(?:[^"]|"")+"|[A-Za-z_][\\w$]*)';
|
|
62
|
+
/** Constraint identity scoped to its table: `schema.table::constraint_name`. */
|
|
63
|
+
function constraintIdentity(stmt, operation) {
|
|
64
|
+
const alter = stmt.match(/ALTER TABLE\s+(?:ONLY\s+)?([\w".]+)/i);
|
|
65
|
+
if (!alter)
|
|
66
|
+
return undefined;
|
|
67
|
+
const constraint = stmt.match(new RegExp(`${operation} CONSTRAINT\\s+(?:IF EXISTS\\s+)?(${CONSTRAINT_IDENT})`, 'i'));
|
|
68
|
+
if (!constraint)
|
|
69
|
+
return undefined;
|
|
70
|
+
return `${normTable(alter[1])}::${normIdent(constraint[1])}`;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* If a statement is a standalone `ALTER TABLE … ADD CONSTRAINT … UNIQUE|PRIMARY KEY (…)`,
|
|
74
|
+
* return the key it PRODUCES (the referenced table is the ALTERed table itself).
|
|
75
|
+
*/
|
|
76
|
+
function producedKey(stmt) {
|
|
77
|
+
const alter = stmt.match(/ALTER TABLE\s+(?:ONLY\s+)?([\w".]+)/i);
|
|
78
|
+
if (!alter)
|
|
79
|
+
return undefined;
|
|
80
|
+
const cons = stmt.match(/ADD CONSTRAINT\s+(?:"[^"]+"|\w+)\s+(UNIQUE|PRIMARY KEY)\s*\(([^)]*)\)/i);
|
|
81
|
+
if (!cons)
|
|
82
|
+
return undefined;
|
|
83
|
+
return refKey(alter[1], cons[2]);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* If a statement is a standalone `ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY (…)
|
|
87
|
+
* REFERENCES tbl (cols)`, return the key it CONSUMES. Only FKs with an explicit
|
|
88
|
+
* referenced column list create a detectable dependency (a bare `REFERENCES tbl`
|
|
89
|
+
* targets the parent PRIMARY KEY, which is created inline in the parent's
|
|
90
|
+
* CREATE TABLE — never a standalone statement we reorder against).
|
|
91
|
+
*/
|
|
92
|
+
function consumedKey(stmt) {
|
|
93
|
+
const fk = stmt.match(/ADD CONSTRAINT\s+(?:"[^"]+"|\w+)\s+FOREIGN KEY\s*\([^)]*\)\s+REFERENCES\s+([\w".]+)\s*\(([^)]*)\)/i);
|
|
94
|
+
if (!fk)
|
|
95
|
+
return undefined;
|
|
96
|
+
return refKey(fk[1], fk[2]);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Reorder standalone constraint statements within one migration file so a
|
|
100
|
+
* referenced UNIQUE/PRIMARY KEY precedes every FK that consumes it when adding
|
|
101
|
+
* constraints, and every dependent FK precedes that referenced key when
|
|
102
|
+
* dropping replacement constraints. Returns the input unchanged
|
|
103
|
+
* (byte-identical) when nothing is misordered.
|
|
104
|
+
*/
|
|
105
|
+
export function reorderPgConstraintStatements(sql) {
|
|
106
|
+
if (!sql.includes(BREAKPOINT))
|
|
107
|
+
return sql;
|
|
108
|
+
// Split on the breakpoint delimiter, preserving each segment verbatim so a
|
|
109
|
+
// plain `.join(BREAKPOINT)` reproduces the original byte-for-byte.
|
|
110
|
+
const segments = sql.split(BREAKPOINT);
|
|
111
|
+
// Earliest consumer index per key.
|
|
112
|
+
const earliestConsumer = new Map();
|
|
113
|
+
for (let i = 0; i < segments.length; i++) {
|
|
114
|
+
const key = consumedKey(segments[i]);
|
|
115
|
+
if (key !== undefined && !earliestConsumer.has(key))
|
|
116
|
+
earliestConsumer.set(key, i);
|
|
117
|
+
}
|
|
118
|
+
// A DROP CONSTRAINT statement does not say whether it drops a UNIQUE, PK,
|
|
119
|
+
// or FK. For replacements, drizzle-kit emits same-named ADD statements later
|
|
120
|
+
// in the delta, which give us the complete dependency graph. Match those
|
|
121
|
+
// definitions back to their drops and pull each dependent FK drop before
|
|
122
|
+
// every replaced UNIQUE/PK drop that can satisfy its REFERENCES tuple.
|
|
123
|
+
const replacementProducers = new Map();
|
|
124
|
+
const replacementConsumers = [];
|
|
125
|
+
const droppedAt = new Map();
|
|
126
|
+
for (let i = 0; i < segments.length; i++) {
|
|
127
|
+
const addId = constraintIdentity(segments[i], 'ADD');
|
|
128
|
+
if (addId !== undefined) {
|
|
129
|
+
const produced = producedKey(segments[i]);
|
|
130
|
+
if (produced !== undefined) {
|
|
131
|
+
const ids = replacementProducers.get(produced) ?? [];
|
|
132
|
+
ids.push(addId);
|
|
133
|
+
replacementProducers.set(produced, ids);
|
|
134
|
+
}
|
|
135
|
+
const consumed = consumedKey(segments[i]);
|
|
136
|
+
if (consumed !== undefined)
|
|
137
|
+
replacementConsumers.push({ id: addId, key: consumed });
|
|
138
|
+
}
|
|
139
|
+
const dropId = constraintIdentity(segments[i], 'DROP');
|
|
140
|
+
if (dropId !== undefined)
|
|
141
|
+
droppedAt.set(dropId, i);
|
|
142
|
+
}
|
|
143
|
+
const moveDropTo = new Map();
|
|
144
|
+
for (const consumer of replacementConsumers) {
|
|
145
|
+
const consumerDropAt = droppedAt.get(consumer.id);
|
|
146
|
+
if (consumerDropAt === undefined)
|
|
147
|
+
continue;
|
|
148
|
+
const producerDropIndexes = (replacementProducers.get(consumer.key) ?? [])
|
|
149
|
+
.map((id) => droppedAt.get(id))
|
|
150
|
+
.filter((index) => index !== undefined);
|
|
151
|
+
if (producerDropIndexes.length === 0)
|
|
152
|
+
continue;
|
|
153
|
+
const earliestProducerDrop = Math.min(...producerDropIndexes);
|
|
154
|
+
if (earliestProducerDrop < consumerDropAt) {
|
|
155
|
+
moveDropTo.set(consumerDropAt, Math.min(moveDropTo.get(consumerDropAt) ?? consumerDropAt, earliestProducerDrop));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// A dependency prerequisite pulled to index j sorts before the original
|
|
159
|
+
// statement at j. All non-participating segments keep their own index.
|
|
160
|
+
const decorated = segments.map((content, index) => {
|
|
161
|
+
let effective = moveDropTo.get(index) ?? index;
|
|
162
|
+
let dependencyFirst = moveDropTo.has(index) ? 0 : 1;
|
|
163
|
+
const pk = producedKey(content);
|
|
164
|
+
if (pk !== undefined) {
|
|
165
|
+
const consumerAt = earliestConsumer.get(pk);
|
|
166
|
+
if (consumerAt !== undefined && consumerAt < index) {
|
|
167
|
+
effective = consumerAt;
|
|
168
|
+
dependencyFirst = 0;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return { content, index, effective, dependencyFirst };
|
|
172
|
+
});
|
|
173
|
+
const reordered = [...decorated].sort((a, b) => {
|
|
174
|
+
if (a.effective !== b.effective)
|
|
175
|
+
return a.effective - b.effective;
|
|
176
|
+
if (a.dependencyFirst !== b.dependencyFirst)
|
|
177
|
+
return a.dependencyFirst - b.dependencyFirst;
|
|
178
|
+
return a.index - b.index; // stable: preserve original order otherwise
|
|
179
|
+
});
|
|
180
|
+
// No movement → return the exact input (byte-identical, D1/goldens safe).
|
|
181
|
+
if (reordered.every((seg, i) => seg.index === i))
|
|
182
|
+
return sql;
|
|
183
|
+
return reordered.map((seg) => seg.content).join(BREAKPOINT);
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=migration-reorder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-reorder.js","sourceRoot":"","sources":["../../../../src/lib/migrations/postprocessors/migration-reorder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,MAAM,UAAU,GAAG,0BAA0B,CAAC;AAE9C,qGAAqG;AACrG,SAAS,SAAS,CAAC,GAAW;IAC5B,OAAO,GAAG;SACP,IAAI,EAAE;SACN,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;SACpD,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,uFAAuF;AACvF,SAAS,QAAQ,CAAC,IAAY;IAC5B,OAAO,IAAI;SACR,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC;SAChD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;SAC3B,IAAI,EAAE;SACN,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,0FAA0F;AAC1F,SAAS,MAAM,CAAC,KAAa,EAAE,IAAY;IACzC,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;AAClD,CAAC;AAED,4DAA4D;AAC5D,SAAS,SAAS,CAAC,KAAa;IAC9B,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,QAAQ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AO,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;QAClE,IAAI,CAAC,CAAC,eAAe,KAAK,CAAC,CAAC,eAAe;YAAE,OAAO,CAAC,CAAC,eAAe,GAAG,CAAC,CAAC,eAAe,CAAC;QAC1F,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,4CAA4C;IACxE,CAAC,CAAC,CAAC;IAEH,0EAA0E;IAC1E,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC;QAAE,OAAO,GAAG,CAAC;IAE7D,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Append-side helpers for the compiler-owned SQL-trigger migration.
|
|
3
|
+
*
|
|
4
|
+
* Ported verbatim (behavior-for-behavior) from
|
|
5
|
+
* `apps/compiler/src/utils/trigger-migration.ts`. Only the append half moves
|
|
6
|
+
* to the CLI — `buildTriggerJournalMigration`, `renderSqlTrigger`, and
|
|
7
|
+
* `loweredTriggerName` stay compiler-side because they run during
|
|
8
|
+
* compilation, not during migration generation. The compiler still decides
|
|
9
|
+
* WHAT the trigger migration says (`meta.triggerJournalMigration`); the CLI
|
|
10
|
+
* only decides where and whether it lands.
|
|
11
|
+
*
|
|
12
|
+
* Keep `MIGRATION_HEADER`, the DROP composition, and the trigger-name regex
|
|
13
|
+
* byte-identical to the compiler's copy — the content hash embedded in the
|
|
14
|
+
* journal tag is computed over `createSql` upstream, but the composed
|
|
15
|
+
* document is what gets applied, and a whitespace drift here would rewrite
|
|
16
|
+
* an applied migration's bytes on the next compile.
|
|
17
|
+
*/
|
|
18
|
+
export interface TriggerJournalMigrationMeta {
|
|
19
|
+
/** The CREATE TRIGGER section — '' when the project has no sql triggers. */
|
|
20
|
+
createSql: string;
|
|
21
|
+
/** sha256[0:12] of `createSql`; embedded in the journal tag. */
|
|
22
|
+
hash: string;
|
|
23
|
+
/** Lowered trigger names in the current set. */
|
|
24
|
+
names: string[];
|
|
25
|
+
}
|
|
26
|
+
/** Journal tag shape for compiler-owned trigger migrations. */
|
|
27
|
+
export declare const TRIGGER_MIGRATION_TAG_RE: RegExp;
|
|
28
|
+
/** Filename shape of staged prior trigger migrations (for name recovery). */
|
|
29
|
+
export declare const TRIGGER_MIGRATION_FILE_RE: RegExp;
|
|
30
|
+
export declare const STATEMENT_BREAKPOINT = "--> statement-breakpoint";
|
|
31
|
+
/**
|
|
32
|
+
* Recover the lowered trigger names a previous trigger migration created, so
|
|
33
|
+
* the next migration's DROP section covers triggers a removed config no
|
|
34
|
+
* longer renders.
|
|
35
|
+
*/
|
|
36
|
+
export declare function extractTriggerNamesFromSql(sql: string): string[];
|
|
37
|
+
/**
|
|
38
|
+
* Compose the final migration document: drops for (previous ∪ current),
|
|
39
|
+
* creates for current. The BEGIN/END frames inside `createSql` are already
|
|
40
|
+
* uppercase (remote-D1 splitter requirement).
|
|
41
|
+
*/
|
|
42
|
+
export declare function composeTriggerMigrationSql(meta: TriggerJournalMigrationMeta, previousNames: string[]): string;
|
|
43
|
+
/** Journal tag shape for compiler-owned RLS migrations. */
|
|
44
|
+
export declare const RLS_MIGRATION_TAG_RE: RegExp;
|
|
45
|
+
export interface RlsJournalMigrationMeta {
|
|
46
|
+
/** The combined, idempotent RLS SQL document. */
|
|
47
|
+
sql: string;
|
|
48
|
+
/** Content hash (sha256, first 12 hex chars) of `sql` — the dedupe key. */
|
|
49
|
+
hash: string;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=trigger-sql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trigger-sql.d.ts","sourceRoot":"","sources":["../../../../src/lib/migrations/postprocessors/trigger-sql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,WAAW,2BAA2B;IAC1C,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;IAClB,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,+DAA+D;AAC/D,eAAO,MAAM,wBAAwB,QAAuC,CAAC;AAE7E,6EAA6E;AAC7E,eAAO,MAAM,yBAAyB,QAA4C,CAAC;AAEnF,eAAO,MAAM,oBAAoB,6BAA6B,CAAC;AAE/D;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAMhE;AAeD;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,2BAA2B,EACjC,aAAa,EAAE,MAAM,EAAE,GACtB,MAAM,CAOR;AAED,2DAA2D;AAC3D,eAAO,MAAM,oBAAoB,QAAkC,CAAC;AAEpE,MAAM,WAAW,uBAAuB;IACtC,iDAAiD;IACjD,GAAG,EAAE,MAAM,CAAC;IACZ,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAC;CACd"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Append-side helpers for the compiler-owned SQL-trigger migration.
|
|
3
|
+
*
|
|
4
|
+
* Ported verbatim (behavior-for-behavior) from
|
|
5
|
+
* `apps/compiler/src/utils/trigger-migration.ts`. Only the append half moves
|
|
6
|
+
* to the CLI — `buildTriggerJournalMigration`, `renderSqlTrigger`, and
|
|
7
|
+
* `loweredTriggerName` stay compiler-side because they run during
|
|
8
|
+
* compilation, not during migration generation. The compiler still decides
|
|
9
|
+
* WHAT the trigger migration says (`meta.triggerJournalMigration`); the CLI
|
|
10
|
+
* only decides where and whether it lands.
|
|
11
|
+
*
|
|
12
|
+
* Keep `MIGRATION_HEADER`, the DROP composition, and the trigger-name regex
|
|
13
|
+
* byte-identical to the compiler's copy — the content hash embedded in the
|
|
14
|
+
* journal tag is computed over `createSql` upstream, but the composed
|
|
15
|
+
* document is what gets applied, and a whitespace drift here would rewrite
|
|
16
|
+
* an applied migration's bytes on the next compile.
|
|
17
|
+
*/
|
|
18
|
+
/** Journal tag shape for compiler-owned trigger migrations. */
|
|
19
|
+
export const TRIGGER_MIGRATION_TAG_RE = /^\d+_quickback_triggers_[0-9a-f]+$/;
|
|
20
|
+
/** Filename shape of staged prior trigger migrations (for name recovery). */
|
|
21
|
+
export const TRIGGER_MIGRATION_FILE_RE = /^\d+_quickback_triggers_[0-9a-f]+\.sql$/;
|
|
22
|
+
export const STATEMENT_BREAKPOINT = '--> statement-breakpoint';
|
|
23
|
+
/**
|
|
24
|
+
* Recover the lowered trigger names a previous trigger migration created, so
|
|
25
|
+
* the next migration's DROP section covers triggers a removed config no
|
|
26
|
+
* longer renders.
|
|
27
|
+
*/
|
|
28
|
+
export function extractTriggerNamesFromSql(sql) {
|
|
29
|
+
const names = [];
|
|
30
|
+
for (const m of sql.matchAll(/CREATE TRIGGER "(qb_trg_[^"]+)"/g)) {
|
|
31
|
+
names.push(m[1]);
|
|
32
|
+
}
|
|
33
|
+
return names;
|
|
34
|
+
}
|
|
35
|
+
const MIGRATION_HEADER = `-- ═══════════════════════════════════════════════════════════════════
|
|
36
|
+
-- Quickback — table triggers migration
|
|
37
|
+
-- Generated by @quickback/compiler; applied via the standard drizzle
|
|
38
|
+
-- journal. Content-addressed: an unchanged trigger set produces no new
|
|
39
|
+
-- migration on recompile.
|
|
40
|
+
--
|
|
41
|
+
-- Idempotent by construction: DROP TRIGGER IF EXISTS for every trigger
|
|
42
|
+
-- this or any prior trigger migration created, then CREATE for the
|
|
43
|
+
-- current set — fully re-establishing trigger state and dropping
|
|
44
|
+
-- removed triggers.
|
|
45
|
+
-- ═══════════════════════════════════════════════════════════════════
|
|
46
|
+
`;
|
|
47
|
+
/**
|
|
48
|
+
* Compose the final migration document: drops for (previous ∪ current),
|
|
49
|
+
* creates for current. The BEGIN/END frames inside `createSql` are already
|
|
50
|
+
* uppercase (remote-D1 splitter requirement).
|
|
51
|
+
*/
|
|
52
|
+
export function composeTriggerMigrationSql(meta, previousNames) {
|
|
53
|
+
const allNames = Array.from(new Set([...previousNames, ...meta.names])).sort();
|
|
54
|
+
const drops = allNames
|
|
55
|
+
.map((n) => `DROP TRIGGER IF EXISTS "${n}";\n${STATEMENT_BREAKPOINT}`)
|
|
56
|
+
.join('\n');
|
|
57
|
+
const sections = [MIGRATION_HEADER, drops, meta.createSql].filter((s) => s.trim().length > 0);
|
|
58
|
+
return `${sections.join('\n')}\n`;
|
|
59
|
+
}
|
|
60
|
+
/** Journal tag shape for compiler-owned RLS migrations. */
|
|
61
|
+
export const RLS_MIGRATION_TAG_RE = /^\d+_quickback_rls_[0-9a-f]+$/;
|
|
62
|
+
//# sourceMappingURL=trigger-sql.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trigger-sql.js","sourceRoot":"","sources":["../../../../src/lib/migrations/postprocessors/trigger-sql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAWH,+DAA+D;AAC/D,MAAM,CAAC,MAAM,wBAAwB,GAAG,oCAAoC,CAAC;AAE7E,6EAA6E;AAC7E,MAAM,CAAC,MAAM,yBAAyB,GAAG,yCAAyC,CAAC;AAEnF,MAAM,CAAC,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AAE/D;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CAAC,GAAW;IACpD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,kCAAkC,CAAC,EAAE,CAAC;QACjE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,gBAAgB,GAAG;;;;;;;;;;;CAWxB,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CACxC,IAAiC,EACjC,aAAuB;IAEvB,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,aAAa,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC/E,MAAM,KAAK,GAAG,QAAQ;SACnB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,2BAA2B,CAAC,OAAO,oBAAoB,EAAE,CAAC;SACrE,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,MAAM,QAAQ,GAAG,CAAC,gBAAgB,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC9F,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AACpC,CAAC;AAED,2DAA2D;AAC3D,MAAM,CAAC,MAAM,oBAAoB,GAAG,+BAA+B,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive the migration-facing facts about a project's PRIOR state that the
|
|
3
|
+
* compiler used to compute for itself by walking the uploaded migration tree.
|
|
4
|
+
*
|
|
5
|
+
* Under compiler-owned migrations these came from `CompilerInput.existingFiles`
|
|
6
|
+
* via `parseExistingNonIdPkTables` (apps/compiler/src/schema/existing-pk-detection.ts)
|
|
7
|
+
* and `projectHasPriorAuditEmission` (apps/compiler/src/utils/audit-latch.ts).
|
|
8
|
+
* Both are pure functions over the same `{ path: content }` map the CLI already
|
|
9
|
+
* builds with `loadDrizzleMeta`, so client ownership does not change what is
|
|
10
|
+
* computed — only where. The CLI now sends the two derived facts instead of the
|
|
11
|
+
* megabytes of history they were derived from.
|
|
12
|
+
*
|
|
13
|
+
* Both facts are load-bearing and both fail SAFE in the same direction the
|
|
14
|
+
* compiler's versions did:
|
|
15
|
+
*
|
|
16
|
+
* - `existingNonIdPkTables` gates `injectIdField`. A table already deployed on
|
|
17
|
+
* a non-`id` primary key must keep it — rewriting the PK would require
|
|
18
|
+
* SQLite's recreate-and-copy dance and repointing every dependent FK.
|
|
19
|
+
* Missing the fact means proposing that rewrite against a live table.
|
|
20
|
+
* - `auditSchemaLatched` is the "once emitted, always emitted" latch on the
|
|
21
|
+
* append-only forensic sink. Missing the fact means a generated migration
|
|
22
|
+
* DROPs `audit.events` and destroys evidence.
|
|
23
|
+
*
|
|
24
|
+
* Keep these byte-equivalent to the compiler's copies. A divergence here is
|
|
25
|
+
* invisible in generated output until it produces a destructive migration.
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Tables that are already deployed on a primary key that is not `id`, read
|
|
29
|
+
* from the highest-numbered features snapshot. Compound PKs count too — the
|
|
30
|
+
* rewriter must not try to drop the table-level constraint either.
|
|
31
|
+
*
|
|
32
|
+
* Empty set when no snapshot exists (greenfield): every table is new and the
|
|
33
|
+
* rewriter may proceed.
|
|
34
|
+
*/
|
|
35
|
+
export declare function parseExistingNonIdPkTables(existingFiles: Record<string, string> | undefined): Set<string>;
|
|
36
|
+
/**
|
|
37
|
+
* True when the project's prior drizzle state shows the Postgres audit schema
|
|
38
|
+
* was ever emitted.
|
|
39
|
+
*
|
|
40
|
+
* Primary signal: a prior snapshot carrying the `audit` schema or an
|
|
41
|
+
* `audit.`-qualified table (pg snapshot shape). D1's split-layout audit
|
|
42
|
+
* snapshot is sqlite-shaped (`audit_events`, no `schemas` key) and can never
|
|
43
|
+
* match — D1 must NOT latch, since its audit store is a separate database and
|
|
44
|
+
* latching the feature-side predicate would re-arm the `auditDatabaseId` hard
|
|
45
|
+
* error.
|
|
46
|
+
*
|
|
47
|
+
* Fallback signal: prior migration SQL that CREATEs the audit subsystem. This
|
|
48
|
+
* covers broken lineages where a generated drop was hand-neutralized in SQL
|
|
49
|
+
* but the snapshots still recorded the schema as removed — the database kept
|
|
50
|
+
* the sink while the snapshot lineage lied.
|
|
51
|
+
*/
|
|
52
|
+
export declare function projectHasPriorAuditEmission(existingFiles: Record<string, string> | undefined): boolean;
|
|
53
|
+
export interface ClientMigrationPriorState {
|
|
54
|
+
auditSchemaLatched: boolean;
|
|
55
|
+
existingNonIdPkTables: string[];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Build the `migration.priorState` payload from locally-loaded drizzle meta.
|
|
59
|
+
* Sorted for a stable request body — the payload is content-addressed upstream
|
|
60
|
+
* and an unstable ordering would churn the hash on every compile.
|
|
61
|
+
*/
|
|
62
|
+
export declare function buildClientMigrationPriorState(drizzleMeta: Record<string, string> | undefined): ClientMigrationPriorState;
|
|
63
|
+
//# sourceMappingURL=prior-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prior-state.d.ts","sourceRoot":"","sources":["../../../src/lib/migrations/prior-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAYH;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAChD,GAAG,CAAC,MAAM,CAAC,CAmBb;AAuCD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,4BAA4B,CAC1C,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAChD,OAAO,CAoBT;AAED,MAAM,WAAW,yBAAyB;IACxC,kBAAkB,EAAE,OAAO,CAAC;IAC5B,qBAAqB,EAAE,MAAM,EAAE,CAAC;CACjC;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAC5C,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAC9C,yBAAyB,CAK3B"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive the migration-facing facts about a project's PRIOR state that the
|
|
3
|
+
* compiler used to compute for itself by walking the uploaded migration tree.
|
|
4
|
+
*
|
|
5
|
+
* Under compiler-owned migrations these came from `CompilerInput.existingFiles`
|
|
6
|
+
* via `parseExistingNonIdPkTables` (apps/compiler/src/schema/existing-pk-detection.ts)
|
|
7
|
+
* and `projectHasPriorAuditEmission` (apps/compiler/src/utils/audit-latch.ts).
|
|
8
|
+
* Both are pure functions over the same `{ path: content }` map the CLI already
|
|
9
|
+
* builds with `loadDrizzleMeta`, so client ownership does not change what is
|
|
10
|
+
* computed — only where. The CLI now sends the two derived facts instead of the
|
|
11
|
+
* megabytes of history they were derived from.
|
|
12
|
+
*
|
|
13
|
+
* Both facts are load-bearing and both fail SAFE in the same direction the
|
|
14
|
+
* compiler's versions did:
|
|
15
|
+
*
|
|
16
|
+
* - `existingNonIdPkTables` gates `injectIdField`. A table already deployed on
|
|
17
|
+
* a non-`id` primary key must keep it — rewriting the PK would require
|
|
18
|
+
* SQLite's recreate-and-copy dance and repointing every dependent FK.
|
|
19
|
+
* Missing the fact means proposing that rewrite against a live table.
|
|
20
|
+
* - `auditSchemaLatched` is the "once emitted, always emitted" latch on the
|
|
21
|
+
* append-only forensic sink. Missing the fact means a generated migration
|
|
22
|
+
* DROPs `audit.events` and destroys evidence.
|
|
23
|
+
*
|
|
24
|
+
* Keep these byte-equivalent to the compiler's copies. A divergence here is
|
|
25
|
+
* invisible in generated output until it produces a destructive migration.
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Tables that are already deployed on a primary key that is not `id`, read
|
|
29
|
+
* from the highest-numbered features snapshot. Compound PKs count too — the
|
|
30
|
+
* rewriter must not try to drop the table-level constraint either.
|
|
31
|
+
*
|
|
32
|
+
* Empty set when no snapshot exists (greenfield): every table is new and the
|
|
33
|
+
* rewriter may proceed.
|
|
34
|
+
*/
|
|
35
|
+
export function parseExistingNonIdPkTables(existingFiles) {
|
|
36
|
+
const out = new Set();
|
|
37
|
+
if (!existingFiles)
|
|
38
|
+
return out;
|
|
39
|
+
const snapshot = pickLatestFeaturesSnapshot(existingFiles);
|
|
40
|
+
if (!snapshot)
|
|
41
|
+
return out;
|
|
42
|
+
for (const [tableName, table] of Object.entries(snapshot.tables ?? {})) {
|
|
43
|
+
const composite = table.compositePrimaryKeys;
|
|
44
|
+
if (composite && Object.keys(composite).length > 0) {
|
|
45
|
+
out.add(tableName);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
for (const colMeta of Object.values(table.columns ?? {})) {
|
|
49
|
+
if (colMeta.primaryKey === true && colMeta.name !== 'id') {
|
|
50
|
+
out.add(tableName);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Only the FEATURES meta dir matters — PK rewrites target user tables. The
|
|
59
|
+
* auth/audit schemas are compiler-managed and never enter that pipeline.
|
|
60
|
+
*/
|
|
61
|
+
function pickLatestFeaturesSnapshot(existingFiles) {
|
|
62
|
+
const candidates = Object.entries(existingFiles).filter(([path]) => /quickback\/drizzle\/features\/meta\/\d+_snapshot\.json$/.test(path));
|
|
63
|
+
if (candidates.length === 0)
|
|
64
|
+
return null;
|
|
65
|
+
candidates.sort((a, b) => {
|
|
66
|
+
const aN = Number(a[0].match(/(\d+)_snapshot\.json$/)?.[1] ?? '0');
|
|
67
|
+
const bN = Number(b[0].match(/(\d+)_snapshot\.json$/)?.[1] ?? '0');
|
|
68
|
+
return bN - aN;
|
|
69
|
+
});
|
|
70
|
+
try {
|
|
71
|
+
return JSON.parse(candidates[0][1]);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// Malformed snapshot — treat as absent rather than fail the compile; the
|
|
75
|
+
// drizzle-kit step surfaces its own error downstream.
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** Root layout (`quickback/drizzle/meta/...`) or split (`.../<db>/meta/...`). */
|
|
80
|
+
const SNAPSHOT_KEY_RE = /(^|\/)drizzle\/(?:[^/]+\/)?meta\/\d+_snapshot\.json$/;
|
|
81
|
+
const SQL_KEY_RE = /(^|\/)drizzle\/(?:[^/]+\/)?[^/]+\.sql$/;
|
|
82
|
+
// The CREATE keyword is required so the ALTER/GRANT statements inside folded
|
|
83
|
+
// *_quickback_rls_* lockdown migrations never latch on their own. Both the
|
|
84
|
+
// bare form (legacy drizzle-kit output) and the IF NOT EXISTS form (what the
|
|
85
|
+
// hardening pass emits going forward) must match — matching only the bare form
|
|
86
|
+
// would release the latch after one compile on broken-lineage projects.
|
|
87
|
+
const CREATE_AUDIT_SCHEMA_RE = /CREATE\s+SCHEMA\s+(?:IF\s+NOT\s+EXISTS\s+)?"?audit"?\s*;/i;
|
|
88
|
+
const CREATE_AUDIT_EVENTS_RE = /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?"audit"\."events"/i;
|
|
89
|
+
/**
|
|
90
|
+
* True when the project's prior drizzle state shows the Postgres audit schema
|
|
91
|
+
* was ever emitted.
|
|
92
|
+
*
|
|
93
|
+
* Primary signal: a prior snapshot carrying the `audit` schema or an
|
|
94
|
+
* `audit.`-qualified table (pg snapshot shape). D1's split-layout audit
|
|
95
|
+
* snapshot is sqlite-shaped (`audit_events`, no `schemas` key) and can never
|
|
96
|
+
* match — D1 must NOT latch, since its audit store is a separate database and
|
|
97
|
+
* latching the feature-side predicate would re-arm the `auditDatabaseId` hard
|
|
98
|
+
* error.
|
|
99
|
+
*
|
|
100
|
+
* Fallback signal: prior migration SQL that CREATEs the audit subsystem. This
|
|
101
|
+
* covers broken lineages where a generated drop was hand-neutralized in SQL
|
|
102
|
+
* but the snapshots still recorded the schema as removed — the database kept
|
|
103
|
+
* the sink while the snapshot lineage lied.
|
|
104
|
+
*/
|
|
105
|
+
export function projectHasPriorAuditEmission(existingFiles) {
|
|
106
|
+
if (!existingFiles)
|
|
107
|
+
return false;
|
|
108
|
+
for (const [path, content] of Object.entries(existingFiles)) {
|
|
109
|
+
if (!SNAPSHOT_KEY_RE.test(path))
|
|
110
|
+
continue;
|
|
111
|
+
try {
|
|
112
|
+
const snap = JSON.parse(content);
|
|
113
|
+
if (snap.schemas && Object.values(snap.schemas).includes('audit'))
|
|
114
|
+
return true;
|
|
115
|
+
if (snap.tables && Object.keys(snap.tables).some((t) => t.startsWith('audit.')))
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
// Malformed snapshot — the SQL fallback below still applies.
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
for (const [path, content] of Object.entries(existingFiles)) {
|
|
123
|
+
if (!SQL_KEY_RE.test(path))
|
|
124
|
+
continue;
|
|
125
|
+
if (CREATE_AUDIT_SCHEMA_RE.test(content) || CREATE_AUDIT_EVENTS_RE.test(content))
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Build the `migration.priorState` payload from locally-loaded drizzle meta.
|
|
132
|
+
* Sorted for a stable request body — the payload is content-addressed upstream
|
|
133
|
+
* and an unstable ordering would churn the hash on every compile.
|
|
134
|
+
*/
|
|
135
|
+
export function buildClientMigrationPriorState(drizzleMeta) {
|
|
136
|
+
return {
|
|
137
|
+
auditSchemaLatched: projectHasPriorAuditEmission(drizzleMeta),
|
|
138
|
+
existingNonIdPkTables: [...parseExistingNonIdPkTables(drizzleMeta)].sort(),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=prior-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prior-state.js","sourceRoot":"","sources":["../../../src/lib/migrations/prior-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAYH;;;;;;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,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;gBAAE,OAAO,IAAI,CAAC;YAC/E,IAAI,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;gBAAE,OAAO,IAAI,CAAC;QAC/F,CAAC;QAAC,MAAM,CAAC;YACP,6DAA6D;QAC/D,CAAC;IACH,CAAC;IACD,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;QAC5D,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,SAAS;QACrC,IAAI,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC;YAAE,OAAO,IAAI,CAAC;IAChG,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAOD;;;;GAIG;AACH,MAAM,UAAU,8BAA8B,CAC5C,WAA+C;IAE/C,OAAO;QACL,kBAAkB,EAAE,4BAA4B,CAAC,WAAW,CAAC;QAC7D,qBAAqB,EAAE,CAAC,GAAG,0BAA0B,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE;KAC3E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { MigrationCommandRunner } from './types.js';
|
|
2
|
+
export interface PromptAwareRunnerOptions {
|
|
3
|
+
/** Project root whose node_modules holds the pinned drizzle-kit. */
|
|
4
|
+
projectRoot: string;
|
|
5
|
+
/** Verbose progress sink. Defaults to silence. */
|
|
6
|
+
log?: (message: string) => void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A migration command runner that can answer drizzle-kit's create-or-rename
|
|
10
|
+
* prompt.
|
|
11
|
+
*
|
|
12
|
+
* ── The two-attempt strategy ─────────────────────────────────────────────
|
|
13
|
+
*
|
|
14
|
+
* 1. Run drizzle-kit normally. Fast and clean for the common additive diff,
|
|
15
|
+
* which has no prompt at all. We deliberately do NOT fake a TTY here:
|
|
16
|
+
* under a TTY drizzle renders interactive spinners that never settle in a
|
|
17
|
+
* non-real terminal, so faking it unconditionally would hang the common
|
|
18
|
+
* case to serve the rare one.
|
|
19
|
+
*
|
|
20
|
+
* 2. Only if drizzle aborted on its non-TTY create/rename resolver, retry
|
|
21
|
+
* through the fake-TTY wrapper so the prompt actually renders and
|
|
22
|
+
* keystrokes can answer it.
|
|
23
|
+
*
|
|
24
|
+
* CRITICAL: drizzle-kit 0.31 prints "Interactive prompts require a TTY" on
|
|
25
|
+
* stderr and then EXITS 0. The retry must key off that message, never off a
|
|
26
|
+
* non-zero exit code. Gating on failure is a bug that already shipped
|
|
27
|
+
* compiler-side once (see run-compilation.ts) and silently skipped generation
|
|
28
|
+
* for every add+drop diff — a compile that looks successful and produces no
|
|
29
|
+
* migration.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createPromptAwareMigrationRunner(options: PromptAwareRunnerOptions): MigrationCommandRunner;
|
|
32
|
+
//# sourceMappingURL=prompt-runner.d.ts.map
|