@quickback-dev/cli 0.60.3 → 0.60.5

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.
Files changed (89) hide show
  1. package/dist/commands/compile.d.ts.map +1 -1
  2. package/dist/commands/compile.js +89 -13
  3. package/dist/commands/compile.js.map +1 -1
  4. package/dist/commands/compile.test.js +52 -5
  5. package/dist/commands/compile.test.js.map +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/lib/api-client.d.ts +15 -0
  8. package/dist/lib/api-client.d.ts.map +1 -1
  9. package/dist/lib/api-client.js +10 -8
  10. package/dist/lib/api-client.js.map +1 -1
  11. package/dist/lib/migrations/commit.d.ts +38 -0
  12. package/dist/lib/migrations/commit.d.ts.map +1 -0
  13. package/dist/lib/migrations/commit.js +39 -0
  14. package/dist/lib/migrations/commit.js.map +1 -0
  15. package/dist/lib/migrations/drizzle-prompts.d.ts +97 -0
  16. package/dist/lib/migrations/drizzle-prompts.d.ts.map +1 -0
  17. package/dist/lib/migrations/drizzle-prompts.js +190 -0
  18. package/dist/lib/migrations/drizzle-prompts.js.map +1 -0
  19. package/dist/lib/migrations/drizzle-prompts.test.d.ts +2 -0
  20. package/dist/lib/migrations/drizzle-prompts.test.d.ts.map +1 -0
  21. package/dist/lib/migrations/drizzle-prompts.test.js +135 -0
  22. package/dist/lib/migrations/drizzle-prompts.test.js.map +1 -0
  23. package/dist/lib/migrations/drizzle-wrapper.d.ts +28 -0
  24. package/dist/lib/migrations/drizzle-wrapper.d.ts.map +1 -0
  25. package/dist/lib/migrations/drizzle-wrapper.js +63 -0
  26. package/dist/lib/migrations/drizzle-wrapper.js.map +1 -0
  27. package/dist/lib/migrations/executor.d.ts +4 -1
  28. package/dist/lib/migrations/executor.d.ts.map +1 -1
  29. package/dist/lib/migrations/executor.js +0 -6
  30. package/dist/lib/migrations/executor.js.map +1 -1
  31. package/dist/lib/migrations/file-envelopes.d.ts +42 -0
  32. package/dist/lib/migrations/file-envelopes.d.ts.map +1 -0
  33. package/dist/lib/migrations/file-envelopes.js +255 -0
  34. package/dist/lib/migrations/file-envelopes.js.map +1 -0
  35. package/dist/lib/migrations/postprocessors/audit-migration-hardening.d.ts +29 -0
  36. package/dist/lib/migrations/postprocessors/audit-migration-hardening.d.ts.map +1 -0
  37. package/dist/lib/migrations/postprocessors/audit-migration-hardening.js +67 -0
  38. package/dist/lib/migrations/postprocessors/audit-migration-hardening.js.map +1 -0
  39. package/dist/lib/migrations/postprocessors/index.d.ts +58 -0
  40. package/dist/lib/migrations/postprocessors/index.d.ts.map +1 -0
  41. package/dist/lib/migrations/postprocessors/index.js +344 -0
  42. package/dist/lib/migrations/postprocessors/index.js.map +1 -0
  43. package/dist/lib/migrations/postprocessors/index.test.d.ts +2 -0
  44. package/dist/lib/migrations/postprocessors/index.test.d.ts.map +1 -0
  45. package/dist/lib/migrations/postprocessors/index.test.js +298 -0
  46. package/dist/lib/migrations/postprocessors/index.test.js.map +1 -0
  47. package/dist/lib/migrations/postprocessors/migration-reorder.d.ts +39 -0
  48. package/dist/lib/migrations/postprocessors/migration-reorder.d.ts.map +1 -0
  49. package/dist/lib/migrations/postprocessors/migration-reorder.js +185 -0
  50. package/dist/lib/migrations/postprocessors/migration-reorder.js.map +1 -0
  51. package/dist/lib/migrations/postprocessors/trigger-sql.d.ts +51 -0
  52. package/dist/lib/migrations/postprocessors/trigger-sql.d.ts.map +1 -0
  53. package/dist/lib/migrations/postprocessors/trigger-sql.js +62 -0
  54. package/dist/lib/migrations/postprocessors/trigger-sql.js.map +1 -0
  55. package/dist/lib/migrations/prior-state.d.ts +63 -0
  56. package/dist/lib/migrations/prior-state.d.ts.map +1 -0
  57. package/dist/lib/migrations/prior-state.js +141 -0
  58. package/dist/lib/migrations/prior-state.js.map +1 -0
  59. package/dist/lib/migrations/prompt-runner.d.ts +32 -0
  60. package/dist/lib/migrations/prompt-runner.d.ts.map +1 -0
  61. package/dist/lib/migrations/prompt-runner.js +158 -0
  62. package/dist/lib/migrations/prompt-runner.js.map +1 -0
  63. package/dist/lib/migrations/prompt-runner.test.d.ts +2 -0
  64. package/dist/lib/migrations/prompt-runner.test.d.ts.map +1 -0
  65. package/dist/lib/migrations/prompt-runner.test.js +131 -0
  66. package/dist/lib/migrations/prompt-runner.test.js.map +1 -0
  67. package/dist/lib/migrations/schema-contract.d.ts +44 -0
  68. package/dist/lib/migrations/schema-contract.d.ts.map +1 -0
  69. package/dist/lib/migrations/schema-contract.js +51 -0
  70. package/dist/lib/migrations/schema-contract.js.map +1 -0
  71. package/dist/skill/docs/api/errors.md +1 -0
  72. package/dist/skill/docs/changelog/index.md +24 -0
  73. package/dist/skill/docs/configure/domains.md +84 -0
  74. package/dist/skill/docs/define/firewall.md +1 -0
  75. package/dist/skill/docs/define/relationships.md +35 -0
  76. package/dist/skill/docs/platform/database/d1.md +14 -0
  77. package/dist/skill/docs/platform/database/neon.md +12 -5
  78. package/dist/skill/docs/start/deploy-browser.md +3 -0
  79. package/dist/skill/docs/tooling/output.md +28 -10
  80. package/package.json +1 -1
  81. package/src/skill/docs/api/errors.md +1 -0
  82. package/src/skill/docs/changelog/index.md +24 -0
  83. package/src/skill/docs/configure/domains.md +84 -0
  84. package/src/skill/docs/define/firewall.md +1 -0
  85. package/src/skill/docs/define/relationships.md +35 -0
  86. package/src/skill/docs/platform/database/d1.md +14 -0
  87. package/src/skill/docs/platform/database/neon.md +12 -5
  88. package/src/skill/docs/start/deploy-browser.md +3 -0
  89. package/src/skill/docs/tooling/output.md +28 -10
@@ -0,0 +1,344 @@
1
+ /**
2
+ * Client-side implementations of the six migration postprocessors the
3
+ * compiler names in `ClientMigrationTarget.postprocessors`.
4
+ *
5
+ * These are behavior-for-behavior ports of `apps/compiler/src/runner/
6
+ * migrations.ts`, which is what makes the cutover verifiable: the output
7
+ * matrix normalizes drizzle's known nondeterminism (codenames, journal
8
+ * `when`, snapshot ids), so a correct port leaves every golden unchanged.
9
+ *
10
+ * Two differences from the server, both deliberate and both narrowing:
11
+ *
12
+ * - **Per-target, not a sweep.** The server iterated a fixed list of three
13
+ * journal paths because it could not know which targets ran. The executor
14
+ * invokes each postprocessor with the target that just generated, so each
15
+ * handler touches exactly one migration directory. The executor's
16
+ * `assertNewPathsBelongToTarget` enforces that.
17
+ *
18
+ * - **`harden-audit` uses the real prior inventory.** The server approximated
19
+ * "files that existed before this compile" from the uploaded `existingFiles`
20
+ * map. The executor hands us `inventoryBeforeTarget` — the actual on-disk
21
+ * state before drizzle ran — which is a strictly better hash-drift guard.
22
+ *
23
+ * `d1-safety` is intentionally a NO-OP. It is named on every sqlite target but
24
+ * has never had an implementation on either side, and plan 001 never specifies
25
+ * one. Making it do something here would change behavior relative to the
26
+ * server path and break golden parity — it must stay inert until it is
27
+ * specified and landed as its own reviewed change.
28
+ */
29
+ import { readdir, readFile, rm, writeFile } from 'node:fs/promises';
30
+ import { join } from 'node:path';
31
+ import { pathExists } from '../../async-utils.js';
32
+ import { resolvePathWithinRoot } from '../paths.js';
33
+ import { hardenAuditMigrationSql } from './audit-migration-hardening.js';
34
+ import { reorderPgConstraintStatements } from './migration-reorder.js';
35
+ import { RLS_MIGRATION_TAG_RE, TRIGGER_MIGRATION_FILE_RE, TRIGGER_MIGRATION_TAG_RE, composeTriggerMigrationSql, extractTriggerNamesFromSql, } from './trigger-sql.js';
36
+ /** Resolve the migration directory this target generated into. */
37
+ function targetDir(context) {
38
+ return resolvePathWithinRoot(context.stagingRoot, context.target.outPath, `migration target ${context.target.id} outPath`);
39
+ }
40
+ /** Compiler-owned migrations carry no drizzle snapshot and no drizzle ordering. */
41
+ function isCompilerOwnedTag(tag) {
42
+ return RLS_MIGRATION_TAG_RE.test(tag) || TRIGGER_MIGRATION_TAG_RE.test(tag);
43
+ }
44
+ async function readJournal(journalPath) {
45
+ if (!(await pathExists(journalPath)))
46
+ return null;
47
+ try {
48
+ return JSON.parse(await readFile(journalPath, 'utf-8'));
49
+ }
50
+ catch {
51
+ return null;
52
+ }
53
+ }
54
+ async function writeJournal(journalPath, journal) {
55
+ await writeFile(journalPath, JSON.stringify(journal, null, 2), 'utf-8');
56
+ }
57
+ async function sqlFilesInOrder(dir) {
58
+ const entries = await readdir(dir).catch(() => []);
59
+ return entries
60
+ .filter((f) => f.endsWith('.sql'))
61
+ .sort((a, b) => {
62
+ const numA = parseInt(a.match(/^(\d+)_/)?.[1] || '0', 10);
63
+ const numB = parseInt(b.match(/^(\d+)_/)?.[1] || '0', 10);
64
+ return numA - numB;
65
+ });
66
+ }
67
+ /**
68
+ * `update-journal` — fold drizzle-kit's newly written .sql files into
69
+ * `meta/_journal.json` so the next generate diffs from them instead of
70
+ * re-emitting the same migration.
71
+ *
72
+ * The root Postgres layout (Neon: `quickback/drizzle/*.sql` +
73
+ * `meta/_journal.json`) behaves differently from the per-database sqlite
74
+ * subdirs, exactly as it did server-side: drizzle-kit writes that journal
75
+ * itself, so entries are never auto-added here — instead an unjournaled
76
+ * .sql file is a leftover from a superseded generate and gets swept.
77
+ * Compiler-owned RLS/trigger files are never swept: they are appended AFTER
78
+ * this pass on a first compile, and arrive already-journaled on recompiles.
79
+ */
80
+ function makeUpdateJournal(deps) {
81
+ return async (context) => {
82
+ const dir = targetDir(context);
83
+ const journalPath = join(dir, 'meta', '_journal.json');
84
+ const journal = await readJournal(journalPath);
85
+ if (!journal)
86
+ return;
87
+ const isRootPostgresJournal = context.target.dialect === 'postgresql';
88
+ const sqlFiles = await sqlFilesInOrder(dir);
89
+ const existingTags = new Set((journal.entries ?? []).map((e) => e.tag));
90
+ if (isRootPostgresJournal) {
91
+ for (const sqlFile of sqlFiles) {
92
+ const tag = sqlFile.replace(/\.sql$/, '');
93
+ if (isCompilerOwnedTag(tag))
94
+ continue;
95
+ if (existingTags.size === 0 || existingTags.has(tag))
96
+ continue;
97
+ await rm(join(dir, sqlFile), { force: true });
98
+ deps.log?.(` Removed stale root migration: ${sqlFile}`);
99
+ }
100
+ }
101
+ else {
102
+ let hasChanges = false;
103
+ for (const sqlFile of sqlFiles) {
104
+ const tag = sqlFile.replace(/\.sql$/, '');
105
+ // Trigger migrations are journaled exclusively by `append-triggers`
106
+ // (breakpoints: true — bodies contain semicolons). Auto-journaling
107
+ // here would stamp breakpoints: false and the migrator would split
108
+ // inside BEGIN/END.
109
+ if (TRIGGER_MIGRATION_TAG_RE.test(tag))
110
+ continue;
111
+ if (existingTags.has(tag))
112
+ continue;
113
+ journal.entries = journal.entries ?? [];
114
+ journal.entries.push({
115
+ idx: journal.entries.length,
116
+ version: journal.version,
117
+ when: Date.now(),
118
+ tag,
119
+ breakpoints: false,
120
+ });
121
+ hasChanges = true;
122
+ deps.log?.(` Added to journal: ${tag}`);
123
+ }
124
+ if (hasChanges)
125
+ await writeJournal(journalPath, journal);
126
+ }
127
+ await warnOnSnapshotDrift(deps, context, dir, journal);
128
+ };
129
+ }
130
+ /**
131
+ * drizzle-kit diffs the schema against the snapshot for the LATEST journal
132
+ * entry. Older snapshots are history and pruning them is legitimate, so the
133
+ * only question that matters is whether the snapshot matching the latest
134
+ * DRIZZLE-authored entry exists — compiler-owned RLS/trigger entries carry
135
+ * no snapshot by design.
136
+ */
137
+ async function warnOnSnapshotDrift(deps, context, dir, journal) {
138
+ const metaDir = join(dir, 'meta');
139
+ const metaEntries = await readdir(metaDir).catch(() => []);
140
+ const snapshotFiles = metaEntries.filter((f) => f.endsWith('_snapshot.json')).sort();
141
+ const drizzleEntries = (journal.entries ?? []).filter((e) => !isCompilerOwnedTag(e.tag ?? ''));
142
+ const latestDrizzle = drizzleEntries[drizzleEntries.length - 1];
143
+ if (!latestDrizzle)
144
+ return;
145
+ const expectedSnapshot = `${String(latestDrizzle.idx).padStart(4, '0')}_snapshot.json`;
146
+ if (metaEntries.includes(expectedSnapshot))
147
+ return;
148
+ const snapshotLatest = snapshotFiles[snapshotFiles.length - 1] ?? '(none)';
149
+ const message = `Drizzle snapshot drift in ${context.target.outPath}: the latest journal entry is ` +
150
+ `${latestDrizzle.tag} (idx ${latestDrizzle.idx}) but ${expectedSnapshot} ` +
151
+ `is missing (newest present: ${snapshotLatest}, ${snapshotFiles.length} total). ` +
152
+ `drizzle-kit diffs against the snapshot for the latest entry, so without ` +
153
+ `it the next compile generates from a stale — or empty — base and can ` +
154
+ `try to re-CREATE tables already in the database. Run ` +
155
+ `\`quickback migrations doctor\` to inspect, or regenerate via ` +
156
+ `\`drizzle-kit introspect\` against your live DB.`;
157
+ deps.log?.(` ⚠️ ${message}`);
158
+ deps.warnings?.push(message);
159
+ }
160
+ /**
161
+ * `reorder-pg-constraints` — ensure a referenced UNIQUE/PRIMARY KEY precedes
162
+ * every foreign key that consumes it, and dependent FKs drop before a
163
+ * referenced key is replaced. drizzle-kit can reverse either order in an
164
+ * upgrade delta, which Postgres rejects at apply time.
165
+ *
166
+ * Byte-identical on any already-correct migration, so it only rewrites files
167
+ * that were genuinely misordered.
168
+ */
169
+ function makeReorderPgConstraints(deps) {
170
+ return async (context) => {
171
+ const dir = targetDir(context);
172
+ for (const file of await sqlFilesInOrder(dir)) {
173
+ if (isCompilerOwnedTag(file.replace(/\.sql$/, '')))
174
+ continue;
175
+ const path = join(dir, file);
176
+ const original = await readFile(path, 'utf-8');
177
+ const reordered = reorderPgConstraintStatements(original);
178
+ if (reordered !== original) {
179
+ await writeFile(path, reordered, 'utf-8');
180
+ deps.log?.(` Reordered Postgres constraint dependencies in: ${file}`);
181
+ }
182
+ }
183
+ };
184
+ }
185
+ /**
186
+ * `harden-audit` — rewrite audit-subsystem CREATEs to `IF NOT EXISTS` and veto
187
+ * generated DROPs against the append-only forensic sink.
188
+ *
189
+ * HASH-DRIFT GUARD: unlike the reorder pass, this transform WOULD change the
190
+ * bytes of an already-applied migration carrying bare audit CREATEs, drifting
191
+ * its migrator hash. Only files absent from the pre-generate inventory may be
192
+ * rewritten.
193
+ */
194
+ function makeHardenAudit(deps) {
195
+ return async (context) => {
196
+ const dir = targetDir(context);
197
+ const priorBasenames = new Set(context.inventoryBeforeTarget.files.map((f) => f.path.split('/').pop() ?? f.path));
198
+ for (const file of await sqlFilesInOrder(dir)) {
199
+ if (isCompilerOwnedTag(file.replace(/\.sql$/, '')))
200
+ continue;
201
+ if (priorBasenames.has(file))
202
+ continue;
203
+ const path = join(dir, file);
204
+ const original = await readFile(path, 'utf-8');
205
+ const hardened = hardenAuditMigrationSql(original);
206
+ if (hardened !== original) {
207
+ await writeFile(path, hardened, 'utf-8');
208
+ deps.log?.(` Hardened audit DDL (IF NOT EXISTS / DROP veto) in: ${file}`);
209
+ }
210
+ }
211
+ };
212
+ }
213
+ /**
214
+ * `append-rls` — append the compiler's RLS document as a custom journal entry
215
+ * AFTER drizzle-kit generate, so it always sorts after the schema migration
216
+ * creating the tables its policies reference.
217
+ *
218
+ * Append-only + content-addressed: when the latest rls-tagged entry already
219
+ * carries the current hash, nothing is appended and the journal stays
220
+ * byte-stable across recompiles.
221
+ */
222
+ function makeAppendRls(deps) {
223
+ return async (context) => {
224
+ const migration = deps.rlsJournalMigration;
225
+ if (!migration)
226
+ return;
227
+ const dir = targetDir(context);
228
+ const journalPath = join(dir, 'meta', '_journal.json');
229
+ const journal = await readJournal(journalPath);
230
+ if (!journal) {
231
+ // No journal means drizzle-kit never generated here — nothing for the
232
+ // migrator to order against. Refuse rather than invent a journal the
233
+ // schema migrations aren't in.
234
+ deps.log?.(` Cannot append RLS migration: ${journalPath} does not exist (drizzle-kit generate produced no journal)`);
235
+ return;
236
+ }
237
+ journal.entries = journal.entries ?? [];
238
+ const rlsEntries = journal.entries.filter((e) => RLS_MIGRATION_TAG_RE.test(e?.tag ?? ''));
239
+ const latest = rlsEntries[rlsEntries.length - 1];
240
+ if (latest?.tag?.endsWith(`_${migration.hash}`)) {
241
+ deps.log?.(` RLS migration unchanged (${latest.tag}) — journal stable`);
242
+ return;
243
+ }
244
+ const idx = journal.entries.length;
245
+ const tag = `${String(idx).padStart(4, '0')}_quickback_rls_${migration.hash}`;
246
+ await writeFile(join(dir, `${tag}.sql`), migration.sql, 'utf-8');
247
+ journal.entries.push({
248
+ idx,
249
+ version: journal.version,
250
+ when: Date.now(),
251
+ // No `--> statement-breakpoint` markers: plpgsql bodies contain
252
+ // semicolons, so the file executes as one multi-statement batch.
253
+ tag,
254
+ breakpoints: false,
255
+ });
256
+ await writeJournal(journalPath, journal);
257
+ deps.log?.(` Appended journaled RLS migration: ${tag}`);
258
+ };
259
+ }
260
+ /**
261
+ * `append-triggers` — same shape as `append-rls`, with two differences:
262
+ *
263
+ * - The DROP section is composed HERE from the staged prior
264
+ * `*_quickback_triggers_*.sql` files (previous ∪ current names), so a
265
+ * removed trigger is dropped exactly once and hand-applied copies
266
+ * converge. The content hash covers only the CREATE section.
267
+ * - `breakpoints: true` — trigger bodies contain `;` inside BEGIN/END, so
268
+ * the migrator must split on `--> statement-breakpoint`, never semicolons.
269
+ */
270
+ function makeAppendTriggers(deps) {
271
+ return async (context) => {
272
+ const migration = deps.triggerJournalMigration;
273
+ if (!migration)
274
+ return;
275
+ const dir = targetDir(context);
276
+ const journalPath = join(dir, 'meta', '_journal.json');
277
+ // Previous trigger names from staged prior trigger migrations — the DROP
278
+ // section must cover triggers a removed config no longer renders.
279
+ const previousNames = new Set();
280
+ for (const file of await readdir(dir).catch(() => [])) {
281
+ if (!TRIGGER_MIGRATION_FILE_RE.test(file))
282
+ continue;
283
+ const sql = await readFile(join(dir, file), 'utf-8').catch(() => '');
284
+ for (const name of extractTriggerNamesFromSql(sql))
285
+ previousNames.add(name);
286
+ }
287
+ // Trigger-less project with no trigger history → nothing to establish or
288
+ // tear down; don't append an empty migration.
289
+ if (migration.names.length === 0 && previousNames.size === 0)
290
+ return;
291
+ const journal = await readJournal(journalPath);
292
+ if (!journal) {
293
+ if (migration.names.length > 0) {
294
+ deps.log?.(` Cannot append trigger migration: ${journalPath} does not exist (drizzle-kit generate produced no journal)`);
295
+ }
296
+ return;
297
+ }
298
+ journal.entries = journal.entries ?? [];
299
+ const triggerEntries = journal.entries.filter((e) => TRIGGER_MIGRATION_TAG_RE.test(e?.tag ?? ''));
300
+ const latest = triggerEntries[triggerEntries.length - 1];
301
+ if (latest?.tag?.endsWith(`_${migration.hash}`)) {
302
+ deps.log?.(` Trigger migration unchanged (${latest.tag}) — journal stable`);
303
+ return;
304
+ }
305
+ const sql = composeTriggerMigrationSql(migration, Array.from(previousNames));
306
+ const idx = journal.entries.length;
307
+ const tag = `${String(idx).padStart(4, '0')}_quickback_triggers_${migration.hash}`;
308
+ await writeFile(join(dir, `${tag}.sql`), sql, 'utf-8');
309
+ journal.entries.push({
310
+ idx,
311
+ version: journal.version,
312
+ when: Date.now(),
313
+ tag,
314
+ breakpoints: true,
315
+ });
316
+ await writeJournal(journalPath, journal);
317
+ deps.log?.(` Appended journaled trigger migration: ${tag}`);
318
+ };
319
+ }
320
+ /**
321
+ * `d1-safety` — declared on every sqlite target, never implemented on either
322
+ * side, never specified in plan 001. Inert by design: see the module docblock.
323
+ */
324
+ const d1Safety = async () => {
325
+ // Intentionally empty. Do not add behavior here without a spec and a
326
+ // golden-parity run — this handler is on the path of every D1 project.
327
+ };
328
+ /**
329
+ * Build the complete handler registry the executor requires. Every member of
330
+ * `ClientMigrationPostprocessor` must be present — the executor throws on an
331
+ * unregistered operation, which is the behavior that catches a compiler that
332
+ * starts naming a postprocessor this CLI does not implement.
333
+ */
334
+ export function createMigrationPostprocessors(deps = {}) {
335
+ return {
336
+ 'd1-safety': d1Safety,
337
+ 'update-journal': makeUpdateJournal(deps),
338
+ 'reorder-pg-constraints': makeReorderPgConstraints(deps),
339
+ 'harden-audit': makeHardenAudit(deps),
340
+ 'append-rls': makeAppendRls(deps),
341
+ 'append-triggers': makeAppendTriggers(deps),
342
+ };
343
+ }
344
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/migrations/postprocessors/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,OAAO,EAAE,QA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;QACnF,MAAM,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;QACvD,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;YACnB,GAAG;YACH,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;YAChB,GAAG;YACH,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;QACH,MAAM,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QACzC,IAAI,CAAC,GAAG,EAAE,CAAC,2CAA2C,GAAG,EAAE,CAAC,CAAC;IAC/D,CAAC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,QAAQ,GAAkC,KAAK,IAAI,EAAE;IACzD,qEAAqE;IACrE,uEAAuE;AACzE,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,6BAA6B,CAC3C,OAAmC,EAAE;IAErC,OAAO;QACL,WAAW,EAAE,QAAQ;QACrB,gBAAgB,EAAE,iBAAiB,CAAC,IAAI,CAAC;QACzC,wBAAwB,EAAE,wBAAwB,CAAC,IAAI,CAAC;QACxD,cAAc,EAAE,eAAe,CAAC,IAAI,CAAC;QACrC,YAAY,EAAE,aAAa,CAAC,IAAI,CAAC;QACjC,iBAAiB,EAAE,kBAAkB,CAAC,IAAI,CAAC;KAC5C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../../src/lib/migrations/postprocessors/index.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,298 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import { mkdir, mkdtemp, readFile, readdir, writeFile } from 'node:fs/promises';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import { inventoryMigrationTree } from '../inventory.js';
6
+ import { createMigrationPostprocessors } from './index.js';
7
+ const SQLITE_TARGET = {
8
+ id: 'features',
9
+ dialect: 'sqlite',
10
+ configPath: 'drizzle.features.config.ts',
11
+ outPath: 'quickback/drizzle/features',
12
+ postprocessors: [],
13
+ };
14
+ const PG_TARGET = {
15
+ id: 'features',
16
+ dialect: 'postgresql',
17
+ configPath: 'drizzle.config.ts',
18
+ outPath: 'quickback/drizzle',
19
+ postprocessors: [],
20
+ };
21
+ /**
22
+ * Build a staging tree shaped like the executor's, with a journal and any
23
+ * seed migrations, then produce a real `MigrationPostprocessorContext`.
24
+ */
25
+ async function fixture(options) {
26
+ const stagingRoot = await mkdtemp(join(tmpdir(), 'qb-postproc-'));
27
+ const dir = join(stagingRoot, options.target.outPath);
28
+ await mkdir(join(dir, 'meta'), { recursive: true });
29
+ if (options.journal !== undefined) {
30
+ await writeFile(join(dir, 'meta', '_journal.json'), JSON.stringify(options.journal, null, 2));
31
+ }
32
+ for (const [name, content] of Object.entries(options.files ?? {})) {
33
+ await writeFile(join(dir, name), content);
34
+ }
35
+ for (const [name, content] of Object.entries(options.meta ?? {})) {
36
+ await writeFile(join(dir, 'meta', name), content);
37
+ }
38
+ const migrationRoot = join(stagingRoot, 'quickback', 'drizzle');
39
+ const inventory = await inventoryMigrationTree(migrationRoot, { allowMissing: true });
40
+ return {
41
+ dir,
42
+ journalPath: join(dir, 'meta', '_journal.json'),
43
+ context: {
44
+ target: options.target,
45
+ stagingRoot,
46
+ outputRoot: stagingRoot,
47
+ migrationRoot,
48
+ inventoryBeforeTarget: inventory,
49
+ inventoryAfterDrizzle: inventory,
50
+ newlyCreatedPaths: [],
51
+ },
52
+ };
53
+ }
54
+ function handlers(deps = {}) {
55
+ return createMigrationPostprocessors(deps);
56
+ }
57
+ async function readJournal(path) {
58
+ return JSON.parse(await readFile(path, 'utf-8'));
59
+ }
60
+ const sqliteJournal = (entries) => ({ version: '7', dialect: 'sqlite', entries });
61
+ describe('update-journal', () => {
62
+ test('journals a newly generated sqlite migration', async () => {
63
+ const { context, journalPath } = await fixture({
64
+ target: SQLITE_TARGET,
65
+ journal: sqliteJournal([{ idx: 0, tag: '0000_existing', when: 1, breakpoints: false }]),
66
+ files: { '0000_existing.sql': 'CREATE TABLE a;', '0001_new.sql': 'CREATE TABLE b;' },
67
+ meta: { '0001_snapshot.json': '{}' },
68
+ });
69
+ await handlers()['update-journal'](context);
70
+ const journal = await readJournal(journalPath);
71
+ expect(journal.entries).toHaveLength(2);
72
+ expect(journal.entries[1]).toMatchObject({ idx: 1, tag: '0001_new', breakpoints: false });
73
+ expect(journal.entries[1].version).toBe('7');
74
+ });
75
+ test('is idempotent — a second run adds nothing', async () => {
76
+ const { context, journalPath } = await fixture({
77
+ target: SQLITE_TARGET,
78
+ journal: sqliteJournal([{ idx: 0, tag: '0000_existing', when: 1 }]),
79
+ files: { '0000_existing.sql': 'CREATE TABLE a;', '0001_new.sql': 'CREATE TABLE b;' },
80
+ meta: { '0001_snapshot.json': '{}' },
81
+ });
82
+ await handlers()['update-journal'](context);
83
+ const first = await readFile(journalPath, 'utf-8');
84
+ await handlers()['update-journal'](context);
85
+ expect(await readFile(journalPath, 'utf-8')).toBe(first);
86
+ });
87
+ test('never auto-journals a trigger migration (append-triggers owns it)', async () => {
88
+ const { context, journalPath } = await fixture({
89
+ target: SQLITE_TARGET,
90
+ journal: sqliteJournal([{ idx: 0, tag: '0000_existing', when: 1 }]),
91
+ files: {
92
+ '0000_existing.sql': 'CREATE TABLE a;',
93
+ '0001_quickback_triggers_abc123def456.sql': 'CREATE TRIGGER "qb_trg_x" ...',
94
+ },
95
+ meta: { '0000_snapshot.json': '{}' },
96
+ });
97
+ await handlers()['update-journal'](context);
98
+ const journal = await readJournal(journalPath);
99
+ expect(journal.entries).toHaveLength(1);
100
+ });
101
+ test('sweeps an unjournaled .sql from the root postgres layout', async () => {
102
+ const { context, dir } = await fixture({
103
+ target: PG_TARGET,
104
+ journal: { version: '7', dialect: 'postgresql', entries: [{ idx: 0, tag: '0000_kept' }] },
105
+ files: { '0000_kept.sql': 'CREATE TABLE a;', '0001_superseded.sql': 'CREATE TABLE b;' },
106
+ meta: { '0000_snapshot.json': '{}' },
107
+ });
108
+ await handlers()['update-journal'](context);
109
+ const remaining = await readdir(dir);
110
+ expect(remaining).toContain('0000_kept.sql');
111
+ expect(remaining).not.toContain('0001_superseded.sql');
112
+ });
113
+ test('never sweeps a compiler-owned rls migration awaiting its append', async () => {
114
+ const { context, dir } = await fixture({
115
+ target: PG_TARGET,
116
+ journal: { version: '7', dialect: 'postgresql', entries: [{ idx: 0, tag: '0000_kept' }] },
117
+ files: {
118
+ '0000_kept.sql': 'CREATE TABLE a;',
119
+ '0001_quickback_rls_abc123def456.sql': 'ALTER TABLE a ENABLE ROW LEVEL SECURITY;',
120
+ },
121
+ meta: { '0000_snapshot.json': '{}' },
122
+ });
123
+ await handlers()['update-journal'](context);
124
+ expect(await readdir(dir)).toContain('0001_quickback_rls_abc123def456.sql');
125
+ });
126
+ test('reports snapshot drift when the latest entry has no snapshot', async () => {
127
+ const warnings = [];
128
+ const { context } = await fixture({
129
+ target: SQLITE_TARGET,
130
+ journal: sqliteJournal([{ idx: 0, tag: '0000_existing', when: 1 }]),
131
+ files: { '0000_existing.sql': 'CREATE TABLE a;' },
132
+ meta: {},
133
+ });
134
+ await handlers({ warnings })['update-journal'](context);
135
+ expect(warnings).toHaveLength(1);
136
+ expect(warnings[0]).toContain('0000_snapshot.json');
137
+ expect(warnings[0]).toContain('quickback migrations doctor');
138
+ });
139
+ test('does not report drift when only compiler-owned entries lack snapshots', async () => {
140
+ const warnings = [];
141
+ const { context } = await fixture({
142
+ target: SQLITE_TARGET,
143
+ journal: sqliteJournal([
144
+ { idx: 0, tag: '0000_existing', when: 1 },
145
+ { idx: 1, tag: '0001_quickback_triggers_abc123def456', when: 2 },
146
+ ]),
147
+ files: { '0000_existing.sql': 'CREATE TABLE a;' },
148
+ meta: { '0000_snapshot.json': '{}' },
149
+ });
150
+ await handlers({ warnings })['update-journal'](context);
151
+ expect(warnings).toHaveLength(0);
152
+ });
153
+ });
154
+ describe('append-rls', () => {
155
+ const rls = { sql: 'ALTER TABLE a ENABLE ROW LEVEL SECURITY;\n', hash: 'abc123def456' };
156
+ test('appends the migration and journals it with breakpoints false', async () => {
157
+ const { context, dir, journalPath } = await fixture({
158
+ target: PG_TARGET,
159
+ journal: { version: '7', dialect: 'postgresql', entries: [{ idx: 0, tag: '0000_schema' }] },
160
+ files: { '0000_schema.sql': 'CREATE TABLE a;' },
161
+ });
162
+ await handlers({ rlsJournalMigration: rls })['append-rls'](context);
163
+ const journal = await readJournal(journalPath);
164
+ expect(journal.entries).toHaveLength(2);
165
+ expect(journal.entries[1]).toMatchObject({
166
+ idx: 1,
167
+ tag: '0001_quickback_rls_abc123def456',
168
+ breakpoints: false,
169
+ });
170
+ expect(await readFile(join(dir, '0001_quickback_rls_abc123def456.sql'), 'utf-8')).toBe(rls.sql);
171
+ });
172
+ test('content-addressed — an unchanged hash leaves the journal byte-stable', async () => {
173
+ const { context, journalPath } = await fixture({
174
+ target: PG_TARGET,
175
+ journal: { version: '7', dialect: 'postgresql', entries: [{ idx: 0, tag: '0000_schema' }] },
176
+ files: { '0000_schema.sql': 'CREATE TABLE a;' },
177
+ });
178
+ await handlers({ rlsJournalMigration: rls })['append-rls'](context);
179
+ const afterFirst = await readFile(journalPath, 'utf-8');
180
+ await handlers({ rlsJournalMigration: rls })['append-rls'](context);
181
+ expect(await readFile(journalPath, 'utf-8')).toBe(afterFirst);
182
+ });
183
+ test('a changed hash appends a new entry rather than rewriting the old', async () => {
184
+ const { context, journalPath } = await fixture({
185
+ target: PG_TARGET,
186
+ journal: { version: '7', dialect: 'postgresql', entries: [{ idx: 0, tag: '0000_schema' }] },
187
+ files: { '0000_schema.sql': 'CREATE TABLE a;' },
188
+ });
189
+ await handlers({ rlsJournalMigration: rls })['append-rls'](context);
190
+ await handlers({
191
+ rlsJournalMigration: { sql: 'ALTER TABLE b ...;\n', hash: '999888777666' },
192
+ })['append-rls'](context);
193
+ const journal = await readJournal(journalPath);
194
+ expect(journal.entries.map((e) => e.tag)).toEqual([
195
+ '0000_schema',
196
+ '0001_quickback_rls_abc123def456',
197
+ '0002_quickback_rls_999888777666',
198
+ ]);
199
+ });
200
+ test('refuses to invent a journal when drizzle-kit produced none', async () => {
201
+ const { context, dir } = await fixture({ target: PG_TARGET, files: {} });
202
+ await handlers({ rlsJournalMigration: rls })['append-rls'](context);
203
+ expect(await readdir(dir)).not.toContain('0000_quickback_rls_abc123def456.sql');
204
+ });
205
+ });
206
+ describe('append-triggers', () => {
207
+ const triggers = {
208
+ createSql: 'CREATE TRIGGER "qb_trg_new" BEGIN SELECT 1; END;',
209
+ hash: 'aaa111bbb222',
210
+ names: ['qb_trg_new'],
211
+ };
212
+ test('journals with breakpoints true — bodies contain semicolons', async () => {
213
+ const { context, journalPath } = await fixture({
214
+ target: SQLITE_TARGET,
215
+ journal: sqliteJournal([{ idx: 0, tag: '0000_schema' }]),
216
+ files: { '0000_schema.sql': 'CREATE TABLE a;' },
217
+ });
218
+ await handlers({ triggerJournalMigration: triggers })['append-triggers'](context);
219
+ const journal = await readJournal(journalPath);
220
+ expect(journal.entries[1]).toMatchObject({
221
+ tag: '0001_quickback_triggers_aaa111bbb222',
222
+ breakpoints: true,
223
+ });
224
+ });
225
+ test('drops triggers a prior migration created but the current set omits', async () => {
226
+ const { context, dir } = await fixture({
227
+ target: SQLITE_TARGET,
228
+ journal: sqliteJournal([
229
+ { idx: 0, tag: '0000_schema' },
230
+ { idx: 1, tag: '0001_quickback_triggers_0d0d0d0d0d0d' },
231
+ ]),
232
+ files: {
233
+ '0000_schema.sql': 'CREATE TABLE a;',
234
+ '0001_quickback_triggers_0d0d0d0d0d0d.sql': 'CREATE TRIGGER "qb_trg_removed" ...',
235
+ },
236
+ });
237
+ await handlers({ triggerJournalMigration: triggers })['append-triggers'](context);
238
+ const sql = await readFile(join(dir, '0002_quickback_triggers_aaa111bbb222.sql'), 'utf-8');
239
+ expect(sql).toContain('DROP TRIGGER IF EXISTS "qb_trg_removed";');
240
+ expect(sql).toContain('DROP TRIGGER IF EXISTS "qb_trg_new";');
241
+ expect(sql).toContain('CREATE TRIGGER "qb_trg_new"');
242
+ });
243
+ test('a trigger-less project with no history appends nothing', async () => {
244
+ const { context, journalPath } = await fixture({
245
+ target: SQLITE_TARGET,
246
+ journal: sqliteJournal([{ idx: 0, tag: '0000_schema' }]),
247
+ files: { '0000_schema.sql': 'CREATE TABLE a;' },
248
+ });
249
+ await handlers({
250
+ triggerJournalMigration: { createSql: '', hash: 'empty0000000', names: [] },
251
+ })['append-triggers'](context);
252
+ expect((await readJournal(journalPath)).entries).toHaveLength(1);
253
+ });
254
+ });
255
+ describe('harden-audit', () => {
256
+ test('does not rewrite a migration that existed before this generate', async () => {
257
+ const applied = 'CREATE TABLE "security_audit_log" ("id" text);\n';
258
+ const { context, dir } = await fixture({
259
+ target: PG_TARGET,
260
+ journal: { version: '7', dialect: 'postgresql', entries: [{ idx: 0, tag: '0000_applied' }] },
261
+ files: { '0000_applied.sql': applied },
262
+ });
263
+ await handlers()['harden-audit'](context);
264
+ // Byte-stable: rewriting an applied migration would drift its migrator hash.
265
+ expect(await readFile(join(dir, '0000_applied.sql'), 'utf-8')).toBe(applied);
266
+ });
267
+ });
268
+ describe('d1-safety', () => {
269
+ test('is inert — declared on every sqlite target but unimplemented by design', async () => {
270
+ const { context, dir, journalPath } = await fixture({
271
+ target: SQLITE_TARGET,
272
+ journal: sqliteJournal([{ idx: 0, tag: '0000_schema' }]),
273
+ files: { '0000_schema.sql': 'CREATE TABLE a;' },
274
+ });
275
+ const before = await readFile(journalPath, 'utf-8');
276
+ await handlers()['d1-safety'](context);
277
+ expect(await readFile(journalPath, 'utf-8')).toBe(before);
278
+ expect(await readdir(dir)).toEqual(expect.arrayContaining(['0000_schema.sql', 'meta']));
279
+ });
280
+ });
281
+ describe('registry', () => {
282
+ test('implements every postprocessor the compiler can name', async () => {
283
+ const registry = createMigrationPostprocessors();
284
+ // Mirrors CLIENT_MIGRATION_POSTPROCESSORS — a compiler that names an
285
+ // operation missing here makes the executor throw, by design.
286
+ for (const op of [
287
+ 'd1-safety',
288
+ 'update-journal',
289
+ 'reorder-pg-constraints',
290
+ 'harden-audit',
291
+ 'append-rls',
292
+ 'append-triggers',
293
+ ]) {
294
+ expect(typeof registry[op]).toBe('function');
295
+ }
296
+ });
297
+ });
298
+ //# sourceMappingURL=index.test.js.map