ddd-ts-kit 0.23.1 → 0.24.0

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 (239) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.fr.md +42 -7
  3. package/README.md +38 -6
  4. package/dist/check/canonical/stray-entry.d.ts +8 -0
  5. package/dist/check/canonical/stray-entry.d.ts.map +1 -0
  6. package/dist/check/canonical/stray-entry.js +75 -0
  7. package/dist/check/canonical/stray-entry.js.map +1 -0
  8. package/dist/check/catalogue/architecture-rules.d.ts.map +1 -1
  9. package/dist/check/catalogue/architecture-rules.js +2 -0
  10. package/dist/check/catalogue/architecture-rules.js.map +1 -1
  11. package/dist/check/catalogue/default-severities.d.ts.map +1 -1
  12. package/dist/check/catalogue/default-severities.js +1 -0
  13. package/dist/check/catalogue/default-severities.js.map +1 -1
  14. package/dist/check/explain/persistence-docs.js +1 -1
  15. package/dist/check/explain/persistence-docs.js.map +1 -1
  16. package/dist/check/explain/tree-docs.d.ts.map +1 -1
  17. package/dist/check/explain/tree-docs.js +5 -0
  18. package/dist/check/explain/tree-docs.js.map +1 -1
  19. package/dist/check/fixtures/tree-fixtures.d.ts.map +1 -1
  20. package/dist/check/fixtures/tree-fixtures.js +17 -0
  21. package/dist/check/fixtures/tree-fixtures.js.map +1 -1
  22. package/dist/check/migrations/drizzle-history-findings.js +1 -1
  23. package/dist/check/migrations/drizzle-history-findings.js.map +1 -1
  24. package/dist/check/rules/tree-closed.d.ts.map +1 -1
  25. package/dist/check/rules/tree-closed.js +4 -68
  26. package/dist/check/rules/tree-closed.js.map +1 -1
  27. package/dist/check/rules/tree-documented-paths.d.ts +3 -0
  28. package/dist/check/rules/tree-documented-paths.d.ts.map +1 -0
  29. package/dist/check/rules/tree-documented-paths.js +54 -0
  30. package/dist/check/rules/tree-documented-paths.js.map +1 -0
  31. package/dist/commands/drizzle-generate.d.ts +6 -1
  32. package/dist/commands/drizzle-generate.d.ts.map +1 -1
  33. package/dist/commands/drizzle-generate.js +39 -6
  34. package/dist/commands/drizzle-generate.js.map +1 -1
  35. package/dist/commands/plan-waves.d.ts +9 -0
  36. package/dist/commands/plan-waves.d.ts.map +1 -0
  37. package/dist/commands/plan-waves.js +36 -0
  38. package/dist/commands/plan-waves.js.map +1 -0
  39. package/dist/commands/status.d.ts +1 -0
  40. package/dist/commands/status.d.ts.map +1 -1
  41. package/dist/commands/status.js +4 -2
  42. package/dist/commands/status.js.map +1 -1
  43. package/dist/help/notes.d.ts +1 -1
  44. package/dist/help/notes.d.ts.map +1 -1
  45. package/dist/help/notes.js +19 -3
  46. package/dist/help/notes.js.map +1 -1
  47. package/dist/help/usage.d.ts +1 -1
  48. package/dist/help/usage.d.ts.map +1 -1
  49. package/dist/help/usage.js +2 -0
  50. package/dist/help/usage.js.map +1 -1
  51. package/dist/init/files/persistence-files.d.ts.map +1 -1
  52. package/dist/init/files/persistence-files.js +7 -1
  53. package/dist/init/files/persistence-files.js.map +1 -1
  54. package/dist/init/manifest/versions.js +24 -24
  55. package/dist/migration/branch-migration.d.ts +9 -0
  56. package/dist/migration/branch-migration.d.ts.map +1 -0
  57. package/dist/migration/branch-migration.js +2 -0
  58. package/dist/migration/branch-migration.js.map +1 -0
  59. package/dist/migration/branch-migrations.d.ts +16 -0
  60. package/dist/migration/branch-migrations.d.ts.map +1 -0
  61. package/dist/migration/branch-migrations.js +48 -0
  62. package/dist/migration/branch-migrations.js.map +1 -0
  63. package/dist/migration/delete-branch-migrations.d.ts +9 -0
  64. package/dist/migration/delete-branch-migrations.d.ts.map +1 -0
  65. package/dist/migration/delete-branch-migrations.js +23 -0
  66. package/dist/migration/delete-branch-migrations.js.map +1 -0
  67. package/dist/migration/drizzle-run.d.ts +7 -0
  68. package/dist/migration/drizzle-run.d.ts.map +1 -0
  69. package/dist/migration/drizzle-run.js +2 -0
  70. package/dist/migration/drizzle-run.js.map +1 -0
  71. package/dist/migration/drizzle-silent-failures.js +1 -1
  72. package/dist/migration/drizzle-silent-failures.js.map +1 -1
  73. package/dist/migration/find-project-formatter.d.ts +8 -0
  74. package/dist/migration/find-project-formatter.d.ts.map +1 -0
  75. package/dist/migration/find-project-formatter.js +52 -0
  76. package/dist/migration/find-project-formatter.js.map +1 -0
  77. package/dist/migration/format-written-files.d.ts +9 -0
  78. package/dist/migration/format-written-files.d.ts.map +1 -0
  79. package/dist/migration/format-written-files.js +32 -0
  80. package/dist/migration/format-written-files.js.map +1 -0
  81. package/dist/migration/generate-and-read.d.ts +6 -0
  82. package/dist/migration/generate-and-read.d.ts.map +1 -0
  83. package/dist/migration/generate-and-read.js +14 -0
  84. package/dist/migration/generate-and-read.js.map +1 -0
  85. package/dist/migration/index.d.ts +4 -0
  86. package/dist/migration/index.d.ts.map +1 -1
  87. package/dist/migration/index.js +4 -0
  88. package/dist/migration/index.js.map +1 -1
  89. package/dist/migration/known-primary-keys.d.ts +3 -0
  90. package/dist/migration/known-primary-keys.d.ts.map +1 -0
  91. package/dist/migration/known-primary-keys.js +2 -0
  92. package/dist/migration/known-primary-keys.js.map +1 -0
  93. package/dist/migration/migration-files.d.ts +7 -0
  94. package/dist/migration/migration-files.d.ts.map +1 -0
  95. package/dist/migration/migration-files.js +29 -0
  96. package/dist/migration/migration-files.js.map +1 -0
  97. package/dist/migration/plan-replay.d.ts +9 -0
  98. package/dist/migration/plan-replay.d.ts.map +1 -0
  99. package/dist/migration/plan-replay.js +68 -0
  100. package/dist/migration/plan-replay.js.map +1 -0
  101. package/dist/migration/previous-primary-keys.d.ts +9 -0
  102. package/dist/migration/previous-primary-keys.d.ts.map +1 -0
  103. package/dist/migration/previous-primary-keys.js +55 -0
  104. package/dist/migration/previous-primary-keys.js.map +1 -0
  105. package/dist/migration/primary-key-order-finding.d.ts +12 -0
  106. package/dist/migration/primary-key-order-finding.d.ts.map +1 -0
  107. package/dist/migration/primary-key-order-finding.js +2 -0
  108. package/dist/migration/primary-key-order-finding.js.map +1 -0
  109. package/dist/migration/primary-key-order-findings.d.ts +12 -0
  110. package/dist/migration/primary-key-order-findings.d.ts.map +1 -0
  111. package/dist/migration/primary-key-order-findings.js +55 -0
  112. package/dist/migration/primary-key-order-findings.js.map +1 -0
  113. package/dist/migration/project-formatter.d.ts +9 -0
  114. package/dist/migration/project-formatter.d.ts.map +1 -0
  115. package/dist/migration/project-formatter.js +2 -0
  116. package/dist/migration/project-formatter.js.map +1 -0
  117. package/dist/migration/replay-drizzle-migrations.d.ts +15 -0
  118. package/dist/migration/replay-drizzle-migrations.d.ts.map +1 -0
  119. package/dist/migration/replay-drizzle-migrations.js +63 -0
  120. package/dist/migration/replay-drizzle-migrations.js.map +1 -0
  121. package/dist/migration/replay-plan.d.ts +11 -0
  122. package/dist/migration/replay-plan.d.ts.map +1 -0
  123. package/dist/migration/replay-plan.js +2 -0
  124. package/dist/migration/replay-plan.js.map +1 -0
  125. package/dist/migration/replayed-name.d.ts +7 -0
  126. package/dist/migration/replayed-name.d.ts.map +1 -0
  127. package/dist/migration/replayed-name.js +12 -0
  128. package/dist/migration/replayed-name.js.map +1 -0
  129. package/dist/migration/sql-statement.d.ts +6 -0
  130. package/dist/migration/sql-statement.d.ts.map +1 -0
  131. package/dist/migration/sql-statement.js +2 -0
  132. package/dist/migration/sql-statement.js.map +1 -0
  133. package/dist/migration/sql-statements.d.ts +4 -0
  134. package/dist/migration/sql-statements.d.ts.map +1 -0
  135. package/dist/migration/sql-statements.js +36 -0
  136. package/dist/migration/sql-statements.js.map +1 -0
  137. package/dist/migration/table-change.d.ts +12 -0
  138. package/dist/migration/table-change.d.ts.map +1 -0
  139. package/dist/migration/table-change.js +2 -0
  140. package/dist/migration/table-change.js.map +1 -0
  141. package/dist/migration/table-changes.d.ts +9 -0
  142. package/dist/migration/table-changes.d.ts.map +1 -0
  143. package/dist/migration/table-changes.js +55 -0
  144. package/dist/migration/table-changes.js.map +1 -0
  145. package/dist/migration/tidy-written-migration.d.ts +5 -0
  146. package/dist/migration/tidy-written-migration.d.ts.map +1 -0
  147. package/dist/migration/tidy-written-migration.js +8 -0
  148. package/dist/migration/tidy-written-migration.js.map +1 -0
  149. package/dist/migration/wait-for-next-second.d.ts +6 -0
  150. package/dist/migration/wait-for-next-second.d.ts.map +1 -0
  151. package/dist/migration/wait-for-next-second.js +11 -0
  152. package/dist/migration/wait-for-next-second.js.map +1 -0
  153. package/dist/migration/warn-primary-key-order.d.ts +5 -0
  154. package/dist/migration/warn-primary-key-order.d.ts.map +1 -0
  155. package/dist/migration/warn-primary-key-order.js +16 -0
  156. package/dist/migration/warn-primary-key-order.js.map +1 -0
  157. package/dist/migration/written-migration.d.ts +9 -0
  158. package/dist/migration/written-migration.d.ts.map +1 -0
  159. package/dist/migration/written-migration.js +2 -0
  160. package/dist/migration/written-migration.js.map +1 -0
  161. package/dist/migration/written-paths.d.ts +3 -0
  162. package/dist/migration/written-paths.d.ts.map +1 -0
  163. package/dist/migration/written-paths.js +5 -0
  164. package/dist/migration/written-paths.js.map +1 -0
  165. package/dist/plan/aggregates-of.d.ts +6 -0
  166. package/dist/plan/aggregates-of.d.ts.map +1 -0
  167. package/dist/plan/aggregates-of.js +13 -0
  168. package/dist/plan/aggregates-of.js.map +1 -0
  169. package/dist/plan/batched-waves.d.ts +18 -0
  170. package/dist/plan/batched-waves.d.ts.map +1 -0
  171. package/dist/plan/batched-waves.js +73 -0
  172. package/dist/plan/batched-waves.js.map +1 -0
  173. package/dist/plan/cycles-of.d.ts +8 -0
  174. package/dist/plan/cycles-of.d.ts.map +1 -0
  175. package/dist/plan/cycles-of.js +30 -0
  176. package/dist/plan/cycles-of.js.map +1 -0
  177. package/dist/plan/format-plan.d.ts +4 -0
  178. package/dist/plan/format-plan.d.ts.map +1 -0
  179. package/dist/plan/format-plan.js +53 -0
  180. package/dist/plan/format-plan.js.map +1 -0
  181. package/dist/plan/merge-order.d.ts +8 -0
  182. package/dist/plan/merge-order.d.ts.map +1 -0
  183. package/dist/plan/merge-order.js +32 -0
  184. package/dist/plan/merge-order.js.map +1 -0
  185. package/dist/plan/plan-problems.d.ts +8 -0
  186. package/dist/plan/plan-problems.d.ts.map +1 -0
  187. package/dist/plan/plan-problems.js +57 -0
  188. package/dist/plan/plan-problems.js.map +1 -0
  189. package/dist/plan/plan-waves.d.ts +16 -0
  190. package/dist/plan/plan-waves.d.ts.map +1 -0
  191. package/dist/plan/plan-waves.js +23 -0
  192. package/dist/plan/plan-waves.js.map +1 -0
  193. package/dist/plan/rows-to-plan.d.ts +7 -0
  194. package/dist/plan/rows-to-plan.d.ts.map +1 -0
  195. package/dist/plan/rows-to-plan.js +19 -0
  196. package/dist/plan/rows-to-plan.js.map +1 -0
  197. package/dist/plan/wave-numbers.d.ts +8 -0
  198. package/dist/plan/wave-numbers.d.ts.map +1 -0
  199. package/dist/plan/wave-numbers.js +27 -0
  200. package/dist/plan/wave-numbers.js.map +1 -0
  201. package/dist/plan/wave-plan.d.ts +48 -0
  202. package/dist/plan/wave-plan.d.ts.map +1 -0
  203. package/dist/plan/wave-plan.js +2 -0
  204. package/dist/plan/wave-plan.js.map +1 -0
  205. package/dist/progress/format-progress.d.ts.map +1 -1
  206. package/dist/progress/format-progress.js +16 -1
  207. package/dist/progress/format-progress.js.map +1 -1
  208. package/dist/progress/progress.d.ts +11 -1
  209. package/dist/progress/progress.d.ts.map +1 -1
  210. package/dist/progress/read-progress.d.ts +6 -2
  211. package/dist/progress/read-progress.d.ts.map +1 -1
  212. package/dist/progress/read-progress.js +10 -5
  213. package/dist/progress/read-progress.js.map +1 -1
  214. package/dist/progress/status-row-of.d.ts +16 -0
  215. package/dist/progress/status-row-of.d.ts.map +1 -0
  216. package/dist/progress/status-row-of.js +23 -0
  217. package/dist/progress/status-row-of.js.map +1 -0
  218. package/dist/run.d.ts.map +1 -1
  219. package/dist/run.js +2 -0
  220. package/dist/run.js.map +1 -1
  221. package/dist/version.d.ts +1 -1
  222. package/dist/version.js +1 -1
  223. package/dist/worker/rows-on-branches.d.ts +8 -0
  224. package/dist/worker/rows-on-branches.d.ts.map +1 -0
  225. package/dist/worker/rows-on-branches.js +9 -0
  226. package/dist/worker/rows-on-branches.js.map +1 -0
  227. package/package.json +2 -2
  228. package/templates/e2e/e2e.spec.ts.tpl +2 -2
  229. package/templates/init/e2e/start-application.database.ts.tpl +30 -1
  230. package/templates/init/e2e/start-application.memory.ts.tpl +30 -1
  231. package/templates/init/e2e/vitest.e2e.config.ts.tpl +4 -0
  232. package/templates/init/platform/database/open-test-database.drizzle.ts.tpl +18 -1
  233. package/templates/init/platform/database/open-test-database.knex.ts.tpl +18 -1
  234. package/templates/init/platform/database/open-test-database.prisma.ts.tpl +18 -1
  235. package/templates/init/platform/database/open-test-database.typeorm.ts.tpl +18 -1
  236. package/templates/init/platform/database/test-database-template.ts.tpl +23 -0
  237. package/templates/init/rules/tests.md.tpl +1 -1
  238. package/templates/pipeline/package-scripts.json +1 -1
  239. package/templates/pipeline/vitest.config.ts.tpl +6 -0
@@ -0,0 +1,55 @@
1
+ import path from 'node:path';
2
+ import { isRecord } from '../check/support/is-record.js';
3
+ /**
4
+ * The primary keys recorded by the snapshot a migration was generated from (the one its own
5
+ * snapshot names as `prevId`), read from the files of the migrations folder: a column marked
6
+ * `primaryKey` gives `<table>_pkey`, as PostgreSQL names it, and `compositePrimaryKeys` their own
7
+ * names. Empty when a snapshot is missing or of another shape.
8
+ */
9
+ export function previousPrimaryKeys(files, sqlPath) {
10
+ const meta = `${path.posix.dirname(sqlPath)}/meta/`;
11
+ const prefix = path.posix.basename(sqlPath, '.sql').split('_')[0] ?? '';
12
+ const own = parsed(files.get(`${meta}${prefix}_snapshot.json`));
13
+ const prevId = isRecord(own) ? own['prevId'] : undefined;
14
+ for (const [file, content] of files) {
15
+ const snapshot = file.startsWith(meta) && file.endsWith('_snapshot.json') ? parsed(content) : undefined;
16
+ if (isRecord(snapshot) && typeof prevId === 'string' && snapshot['id'] === prevId) {
17
+ return new Map(Object.values(recordAt(snapshot, 'tables')).flatMap(keysOf));
18
+ }
19
+ }
20
+ return new Map();
21
+ }
22
+ function keysOf(table) {
23
+ const name = isRecord(table) ? table['name'] : undefined;
24
+ if (!isRecord(table) || typeof name !== 'string') {
25
+ return [];
26
+ }
27
+ const columns = Object.values(recordAt(table, 'columns')).filter((column) => isRecord(column) && column['primaryKey'] === true);
28
+ const single = columns.length === 0 ? [] : [[`${name}_pkey`, columns.flatMap(nameOf)]];
29
+ const composite = Object.values(recordAt(table, 'compositePrimaryKeys')).flatMap(compositeOf);
30
+ return [...single, ...composite];
31
+ }
32
+ function compositeOf(key) {
33
+ const name = isRecord(key) ? key['name'] : undefined;
34
+ const columns = isRecord(key) ? key['columns'] : undefined;
35
+ return typeof name === 'string' && Array.isArray(columns)
36
+ ? [[name, columns.filter((column) => typeof column === 'string')]]
37
+ : [];
38
+ }
39
+ function nameOf(column) {
40
+ const name = isRecord(column) ? column['name'] : undefined;
41
+ return typeof name === 'string' ? [name] : [];
42
+ }
43
+ function recordAt(value, key) {
44
+ const found = value[key];
45
+ return isRecord(found) ? found : {};
46
+ }
47
+ function parsed(text) {
48
+ try {
49
+ return text === undefined ? undefined : JSON.parse(text);
50
+ }
51
+ catch {
52
+ return undefined;
53
+ }
54
+ }
55
+ //# sourceMappingURL=previous-primary-keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"previous-primary-keys.js","sourceRoot":"","sources":["../../src/migration/previous-primary-keys.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAGzD;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAkC,EAAE,OAAe;IACrF,MAAM,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC;IACpD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CA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AAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAChD,CAAC;AAED,SAAS,QAAQ,CAAC,KAA8B,EAAE,GAAW;IAC3D,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IAEzB,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AACtC,CAAC;AAED,SAAS,MAAM,CAAC,IAAwB;IACtC,IAAI,CAAC;QACH,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { SqlStatement } from './sql-statement.js';
2
+ /** Two statements of one migration that change a primary key in an order PostgreSQL refuses. */
3
+ export interface PrimaryKeyOrderFinding {
4
+ readonly table: string;
5
+ /** The statement that runs too early. */
6
+ readonly early: SqlStatement;
7
+ /** The statement that drops the old key, which has to run before it. */
8
+ readonly drop: SqlStatement;
9
+ readonly message: string;
10
+ readonly fix: string;
11
+ }
12
+ //# sourceMappingURL=primary-key-order-finding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primary-key-order-finding.d.ts","sourceRoot":"","sources":["../../src/migration/primary-key-order-finding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,gGAAgG;AAChG,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,yCAAyC;IACzC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,wEAAwE;IACxE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=primary-key-order-finding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primary-key-order-finding.js","sourceRoot":"","sources":["../../src/migration/primary-key-order-finding.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import type { KnownPrimaryKeys } from './known-primary-keys.js';
2
+ import type { PrimaryKeyOrderFinding } from './primary-key-order-finding.js';
3
+ /**
4
+ * The changes of a primary key that a migration of drizzle-kit writes in an order PostgreSQL
5
+ * refuses: the new key of a table added before its old one is dropped (a table has one primary
6
+ * key), and a column dropped before the key that holds it (the column takes the key with it, and
7
+ * the later `DROP CONSTRAINT` finds none). A dropped constraint is a primary key when `known` says
8
+ * so (the snapshot before the migration) or its name ends in `_pkey` or `_pk`; the columns of a
9
+ * key come from `known`, else from the name drizzle-kit gives a composite key.
10
+ */
11
+ export declare function primaryKeyOrderFindings(sql: string, known?: KnownPrimaryKeys): PrimaryKeyOrderFinding[];
12
+ //# sourceMappingURL=primary-key-order-findings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primary-key-order-findings.d.ts","sourceRoot":"","sources":["../../src/migration/primary-key-order-findings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAU7E;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE,gBAA4B,GAAG,sBAAsB,EAAE,CAalH"}
@@ -0,0 +1,55 @@
1
+ import { sqlStatements } from './sql-statements.js';
2
+ import { tableChanges } from './table-changes.js';
3
+ /** PostgreSQL names a key `<table>_pkey`; drizzle-kit names a composite one `<table>_<column>_<column>_pk`. */
4
+ const KEY_NAME = /_(?:pkey|pk)$/;
5
+ const CUSTOM = 'or write the migration yourself (`npm run db:generate -- <name> --custom`)';
6
+ /**
7
+ * The changes of a primary key that a migration of drizzle-kit writes in an order PostgreSQL
8
+ * refuses: the new key of a table added before its old one is dropped (a table has one primary
9
+ * key), and a column dropped before the key that holds it (the column takes the key with it, and
10
+ * the later `DROP CONSTRAINT` finds none). A dropped constraint is a primary key when `known` says
11
+ * so (the snapshot before the migration) or its name ends in `_pkey` or `_pk`; the columns of a
12
+ * key come from `known`, else from the name drizzle-kit gives a composite key.
13
+ */
14
+ export function primaryKeyOrderFindings(sql, known = new Map()) {
15
+ const changes = tableChanges(sqlStatements(sql));
16
+ const drops = changes.filter((change) => change.kind === 'drop-constraint' && isKey(change.name, known));
17
+ return changes.flatMap((early) => {
18
+ const condition = mustFollow(early, known);
19
+ const drop = drops.find((key) => key.table === early.table && key.position > early.position && condition?.(key) === true);
20
+ return drop === undefined ? [] : [finding(early, drop)];
21
+ });
22
+ }
23
+ /** Which later drop of a key the change has to follow: any key of its table for an added key, the key holding it for a dropped column. */
24
+ function mustFollow(early, known) {
25
+ if (early.kind === 'add-key') {
26
+ return () => true;
27
+ }
28
+ return early.kind === 'drop-column' ? (key) => holdsColumn(key, early.name, known) : undefined;
29
+ }
30
+ function finding(early, drop) {
31
+ const { table } = early;
32
+ const words = early.kind === 'add-key'
33
+ ? {
34
+ message: `The new primary key of "${table}" is added before its old one, "${drop.name}", is dropped: PostgreSQL refuses a second primary key on a table, and the migration fails.`,
35
+ fix: `Drop the old key first: move the DROP CONSTRAINT above the ADD of the new key in this migration, still unapplied, ${CUSTOM}.`,
36
+ }
37
+ : {
38
+ message: `The column "${early.name}" of "${table}" is dropped before the primary key "${drop.name}" that holds it: the column takes the key with it, and the later DROP CONSTRAINT fails.`,
39
+ fix: `Drop the key first: move the DROP CONSTRAINT above the DROP COLUMN in this migration, still unapplied, ${CUSTOM}.`,
40
+ };
41
+ return { table, early: early.statement, drop: drop.statement, ...words };
42
+ }
43
+ function isKey(constraint, known) {
44
+ return known.has(constraint) || KEY_NAME.test(constraint);
45
+ }
46
+ function holdsColumn(key, column, known) {
47
+ const columns = known.get(key.name);
48
+ if (columns !== undefined) {
49
+ return columns.includes(column);
50
+ }
51
+ const prefix = `${key.table}_`;
52
+ const named = key.name.startsWith(prefix) && key.name.endsWith('_pk') ? key.name.slice(prefix.length, -3) : '';
53
+ return named !== '' && `_${named}_`.includes(`_${column}_`);
54
+ }
55
+ //# sourceMappingURL=primary-key-order-findings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primary-key-order-findings.js","sourceRoot":"","sources":["../../src/migration/primary-key-order-findings.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,+GAA+G;AAC/G,MAAM,QAAQ,GAAG,eAAe,CAAC;AAEjC,MAAM,MAAM,GAAG,4EAA4E,CAAC;AAE5F;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CAAC,GAAW,EAAE,KAAK,GAAqB,IAAI,GAAG,EAAE;IACtF,MAAM,OAAO,GAAG,YAAY,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;IACjD,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,iBAAiB,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAEzG,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QAC/B,MAAM,SAAS,GAAG,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAE3C,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CACrB,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK,IAAI,GAAG,CAAC,QAAQ,GAAG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,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAC5D,CAAC;AAED,SAAS,WAAW,CAAC,GAAgB,EAAE,MAAc,EAAE,KAAuB;IAC5E,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAEpC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IAED,MAAM,MAAM,GAAG,GAAG,GAAG,CAAC,KAAK,GAAG,CAAC;IAC/B,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAE/G,OAAO,KAAK,KAAK,EAAE,IAAI,IAAI,KAAK,GAAG,CAAC,QAAQ,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,9 @@
1
+ /** The formatter the `format` script of a project runs, found installed, run on given paths by the same node. */
2
+ export interface ProjectFormatter {
3
+ readonly name: 'Biome' | 'Prettier';
4
+ /** The entry file of its command line, under node_modules. */
5
+ readonly bin: string;
6
+ /** What precedes the paths: write in place, and pass over a path its configuration ignores. */
7
+ readonly args: readonly string[];
8
+ }
9
+ //# sourceMappingURL=project-formatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-formatter.d.ts","sourceRoot":"","sources":["../../src/migration/project-formatter.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,UAAU,CAAC;IACpC,8DAA8D;IAC9D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,+FAA+F;IAC/F,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=project-formatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-formatter.js","sourceRoot":"","sources":["../../src/migration/project-formatter.ts"],"names":[],"mappings":""}
@@ -0,0 +1,15 @@
1
+ import type { Io } from '../commands/io.js';
2
+ export interface DrizzleReplay {
3
+ readonly root: string;
4
+ /** The trunk the branch merged: its migrations are kept, the others generated again on top. */
5
+ readonly base: string;
6
+ readonly interactive: boolean;
7
+ }
8
+ /**
9
+ * `drizzle-generate --replay`, after merging the trunk into a branch when both added migrations:
10
+ * deletes the migrations of the branch the base does not have (with their snapshots and journal
11
+ * entries), then generates them again on top of the base, one per deleted one, in their order and
12
+ * under their names. A custom migration gets its statements back.
13
+ */
14
+ export declare function replayDrizzleMigrations(replay: DrizzleReplay, io: Io): number;
15
+ //# sourceMappingURL=replay-drizzle-migrations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replay-drizzle-migrations.d.ts","sourceRoot":"","sources":["../../src/migration/replay-drizzle-migrations.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAY5C,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,+FAA+F;IAC/F,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,aAAa,EAAE,EAAE,EAAE,EAAE,GAAG,MAAM,CAyC7E"}
@@ -0,0 +1,63 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { WORKER_SCOPE_FILE } from '../commit/worker-scope-file.js';
4
+ import { deleteBranchMigrations } from './delete-branch-migrations.js';
5
+ import { generateAndRead } from './generate-and-read.js';
6
+ import { migrationFiles } from './migration-files.js';
7
+ import { planReplay } from './plan-replay.js';
8
+ import { replayedName } from './replayed-name.js';
9
+ import { tidyWrittenMigration } from './tidy-written-migration.js';
10
+ import { waitForNextSecond } from './wait-for-next-second.js';
11
+ /**
12
+ * `drizzle-generate --replay`, after merging the trunk into a branch when both added migrations:
13
+ * deletes the migrations of the branch the base does not have (with their snapshots and journal
14
+ * entries), then generates them again on top of the base, one per deleted one, in their order and
15
+ * under their names. A custom migration gets its statements back.
16
+ */
17
+ export function replayDrizzleMigrations(replay, io) {
18
+ const plan = planReplay(replay);
19
+ if (plan.migrations.length === 0) {
20
+ io.out(`No migration of this branch is missing from ${plan.base}: nothing to replay.`);
21
+ return 0;
22
+ }
23
+ deleteBranchMigrations(plan);
24
+ io.out(`Deleted, with their snapshots and journal entries: ${plan.migrations.map((migration) => migration.tag).join(', ')}.`);
25
+ const written = new Set();
26
+ const inWorker = fs.existsSync(path.join(replay.root, WORKER_SCOPE_FILE));
27
+ let since = 0;
28
+ for (const migration of plan.migrations) {
29
+ waitForNextSecond(since);
30
+ const code = generateAgain({ plan, migration, name: replayedName(migration.tag, inWorker) }, replay, io);
31
+ if (typeof code === 'number') {
32
+ return code;
33
+ }
34
+ for (const file of code) {
35
+ written.add(file);
36
+ }
37
+ since = Date.now();
38
+ }
39
+ const files = migrationFiles(replay.root, plan.folder);
40
+ tidyWrittenMigration({ root: replay.root, paths: [...written], files }, io);
41
+ io.out(`Stage ${plan.folder}/, then run \`npm run check:arch\`.`);
42
+ return 0;
43
+ }
44
+ /** Generates one migration again: what it wrote, or the exit code of drizzle-kit when it failed. */
45
+ function generateAgain({ plan, migration, name }, replay, io) {
46
+ const { root, interactive } = replay;
47
+ const { code, written } = generateAndRead({ root, name, custom: migration.custom, interactive }, io);
48
+ const sql = written.paths.find((file) => file.endsWith('.sql') && path.posix.dirname(file) === plan.folder);
49
+ if (code !== 0) {
50
+ io.err(`drizzle-kit failed on ${name}: the migrations generated above are written, the others stay deleted. Delete what this run generated, restore ${plan.folder}/ as the merge left it (\`git checkout HEAD -- ${plan.folder}\`), fix the cause above and run the replay again.`);
51
+ return code;
52
+ }
53
+ if (sql === undefined) {
54
+ io.err(`Warning: drizzle-kit wrote nothing for ${migration.tag}: ${plan.base} already holds its change.`);
55
+ return written.paths;
56
+ }
57
+ if (migration.custom) {
58
+ fs.writeFileSync(path.join(root, sql), migration.sql);
59
+ }
60
+ io.out(`Generated ${path.posix.basename(sql, '.sql')} in place of ${migration.tag}.`);
61
+ return written.paths;
62
+ }
63
+ //# sourceMappingURL=replay-drizzle-migrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replay-drizzle-migrations.js","sourceRoot":"","sources":["../../src/migration/replay-drizzle-migrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAS9D;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAAqB,EAAE,EAAM;IACnE,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IAEhC,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK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GAAG,CAAC,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC;IACxD,CAAC;IAED,EAAE,CAAC,GAAG,CAAC,aAAa,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,gBAAgB,SAAS,CAAC,GAAG,GAAG,CAAC,CAAC;IAEtF,OAAO,OAAO,CAAC,KAAK,CAAC;AACvB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { BranchMigration } from './branch-migration.js';
2
+ /** What a replay deletes and generates again, read before anything is touched. */
3
+ export interface ReplayPlan {
4
+ readonly root: string;
5
+ readonly base: string;
6
+ /** The migrations folder, relative to the project root. */
7
+ readonly folder: string;
8
+ /** In their order. */
9
+ readonly migrations: readonly BranchMigration[];
10
+ }
11
+ //# sourceMappingURL=replay-plan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replay-plan.d.ts","sourceRoot":"","sources":["../../src/migration/replay-plan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,kFAAkF;AAClF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,2DAA2D;IAC3D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,sBAAsB;IACtB,QAAQ,CAAC,UAAU,EAAE,SAAS,eAAe,EAAE,CAAC;CACjD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=replay-plan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replay-plan.js","sourceRoot":"","sources":["../../src/migration/replay-plan.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The name a migration of the branch is generated again with: what follows its number. In the
3
+ * worktree of a worker it stays a working migration; elsewhere (the conductor, a branch of its
4
+ * own) it becomes the real one, without the `working-` prefix.
5
+ */
6
+ export declare function replayedName(tag: string, inWorker: boolean): string;
7
+ //# sourceMappingURL=replayed-name.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replayed-name.d.ts","sourceRoot":"","sources":["../../src/migration/replayed-name.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,CAKnE"}
@@ -0,0 +1,12 @@
1
+ const WORKING = 'working-';
2
+ /**
3
+ * The name a migration of the branch is generated again with: what follows its number. In the
4
+ * worktree of a worker it stays a working migration; elsewhere (the conductor, a branch of its
5
+ * own) it becomes the real one, without the `working-` prefix.
6
+ */
7
+ export function replayedName(tag, inWorker) {
8
+ const at = tag.indexOf('_');
9
+ const name = at === -1 ? tag : tag.slice(at + 1);
10
+ return inWorker || !name.startsWith(WORKING) || name === WORKING ? name : name.slice(WORKING.length);
11
+ }
12
+ //# sourceMappingURL=replayed-name.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replayed-name.js","sourceRoot":"","sources":["../../src/migration/replayed-name.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG,UAAU,CAAC;AAE3B;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,QAAiB;IACzD,MAAM,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5B,MAAM,IAAI,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IAEjD,OAAO,QAAQ,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AACvG,CAAC"}
@@ -0,0 +1,6 @@
1
+ /** One statement of a SQL file, without its comments, its blanks folded, and the line it starts on. */
2
+ export interface SqlStatement {
3
+ readonly text: string;
4
+ readonly line: number;
5
+ }
6
+ //# sourceMappingURL=sql-statement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-statement.d.ts","sourceRoot":"","sources":["../../src/migration/sql-statement.ts"],"names":[],"mappings":"AAAA,uGAAuG;AACvG,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=sql-statement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-statement.js","sourceRoot":"","sources":["../../src/migration/sql-statement.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import type { SqlStatement } from './sql-statement.js';
2
+ /** The statements of a SQL file in their order, as PostgreSQL runs them; `--> statement-breakpoint` of drizzle-kit is a comment. */
3
+ export declare function sqlStatements(sql: string): SqlStatement[];
4
+ //# sourceMappingURL=sql-statements.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-statements.d.ts","sourceRoot":"","sources":["../../src/migration/sql-statements.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAUvD,oIAAoI;AACpI,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,EAAE,CAqBzD"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * A comment, a string, a quoted name, a dollar-quoted body (a `DO $$ .. $$` block keeps its own
3
+ * semicolons), the semicolon that ends a statement, or anything else. An unterminated one runs to
4
+ * the end of the file.
5
+ */
6
+ const TOKENS = /--[^\n]*|\/\*[\s\S]*?(?:\*\/|$)|'(?:[^']|'')*'?|"(?:[^"]|"")*"?|\$(\w*)\$[\s\S]*?(?:\$\1\$|$)|;|[^-/'"$;]+|[\s\S]/g;
7
+ /** The statements of a SQL file in their order, as PostgreSQL runs them; `--> statement-breakpoint` of drizzle-kit is a comment. */
8
+ export function sqlStatements(sql) {
9
+ const statements = [];
10
+ let text = '';
11
+ let start = 1;
12
+ let line = 1;
13
+ for (const [token] of sql.matchAll(TOKENS)) {
14
+ if (token === ';') {
15
+ statements.push(...folded(text, start));
16
+ text = '';
17
+ }
18
+ else if (token.startsWith('--') || token.startsWith('/*')) {
19
+ text += ' ';
20
+ }
21
+ else {
22
+ start = text.trim() === '' && token.trim() !== '' ? line + newlines(token.slice(0, token.search(/\S/))) : start;
23
+ text += token;
24
+ }
25
+ line += newlines(token);
26
+ }
27
+ return [...statements, ...folded(text, start)];
28
+ }
29
+ function folded(text, line) {
30
+ const statement = text.replace(/\s+/g, ' ').trim();
31
+ return statement === '' ? [] : [{ text: statement, line }];
32
+ }
33
+ function newlines(text) {
34
+ return text.split('\n').length - 1;
35
+ }
36
+ //# sourceMappingURL=sql-statements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-statements.js","sourceRoot":"","sources":["../../src/migration/sql-statements.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,MAAM,GACV,oHAAoH,CAAC;AAEvH,oIAAoI;AACpI,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,MAAM,UAAU,GAAmB,EAAE,CAAC;IACtC,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,IAAI,GAAG,CAAC,CAAC;IAEb,KAAK,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3C,IAAI,KAAK,KAAK,GAAG,EAAE,CAAC;YAClB,UAAU,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;YACxC,IAAI,GAAG,EAAE,CAAC;QACZ,CAAC;aAAM,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YAC5D,IAAI,IAAI,GAAG,CAAC;QACd,CAAC;aAAM,CAAC;YACN,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YAChH,IAAI,IAAI,KAAK,CAAC;QAChB,CAAC;QAED,IAAI,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAED,OAAO,CAAC,GAAG,UAAU,EAAE,GAAG,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AACjD,CAAC;AAED,SAAS,MAAM,CAAC,IAAY,EAAE,IAAY;IACxC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAEnD,OAAO,SAAS,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AACrC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { SqlStatement } from './sql-statement.js';
2
+ /** One action of an `ALTER TABLE` that bears on a primary key, with the position of its statement in the file. */
3
+ export interface TableChange {
4
+ readonly kind: 'add-key' | 'drop-constraint' | 'drop-column';
5
+ /** Unquoted, without its schema; lower case unless it was quoted, as PostgreSQL reads it. */
6
+ readonly table: string;
7
+ /** The dropped constraint or column; empty for an added key. */
8
+ readonly name: string;
9
+ readonly position: number;
10
+ readonly statement: SqlStatement;
11
+ }
12
+ //# sourceMappingURL=table-change.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table-change.d.ts","sourceRoot":"","sources":["../../src/migration/table-change.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,kHAAkH;AAClH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,iBAAiB,GAAG,aAAa,CAAC;IAC7D,6FAA6F;IAC7F,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,gEAAgE;IAChE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;CAClC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=table-change.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table-change.js","sourceRoot":"","sources":["../../src/migration/table-change.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import type { SqlStatement } from './sql-statement.js';
2
+ import type { TableChange } from './table-change.js';
3
+ /**
4
+ * The actions of the `ALTER TABLE` statements of a migration that add a primary key, drop a
5
+ * constraint or drop a column, in the order of the statements. The actions of one statement share
6
+ * its position: PostgreSQL drops before it adds within a statement.
7
+ */
8
+ export declare function tableChanges(statements: readonly SqlStatement[]): TableChange[];
9
+ //# sourceMappingURL=table-changes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table-changes.d.ts","sourceRoot":"","sources":["../../src/migration/table-changes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAgBrD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,SAAS,YAAY,EAAE,GAAG,WAAW,EAAE,CAc/E"}
@@ -0,0 +1,55 @@
1
+ const NAME = String.raw `(?:"(?:[^"]|"")+"|[A-Za-z_][\w$]*)`;
2
+ const ALTER_TABLE = new RegExp(String.raw `^ALTER TABLE (?:IF EXISTS )?(?:ONLY )?(?:${NAME} ?\. ?)?(${NAME}) (.+)$`, 'i');
3
+ const ADD_KEY = new RegExp(String.raw `^ADD (?:CONSTRAINT ${NAME} )?PRIMARY KEY\b`, 'i');
4
+ const DROP_CONSTRAINT = new RegExp(String.raw `^DROP CONSTRAINT (?:IF EXISTS )?(${NAME})`, 'i');
5
+ const DROP_COLUMN = new RegExp(String.raw `^DROP COLUMN (?:IF EXISTS )?(${NAME})`, 'i');
6
+ /** A quoted name, a string, a parenthesis, a comma, or anything else: the actions of one ALTER TABLE are split on the commas outside parentheses. */
7
+ const PIECES = /"(?:[^"]|"")*"|'(?:[^']|'')*'|[(),]|[^"'(),]+/g;
8
+ /**
9
+ * The actions of the `ALTER TABLE` statements of a migration that add a primary key, drop a
10
+ * constraint or drop a column, in the order of the statements. The actions of one statement share
11
+ * its position: PostgreSQL drops before it adds within a statement.
12
+ */
13
+ export function tableChanges(statements) {
14
+ return statements.flatMap((statement, position) => {
15
+ const [, table, actions] = ALTER_TABLE.exec(statement.text) ?? [];
16
+ if (table === undefined || actions === undefined) {
17
+ return [];
18
+ }
19
+ return actionsOf(actions).flatMap((action) => {
20
+ const change = changeOf(action);
21
+ return change === undefined ? [] : [{ ...change, table: unquoted(table), position, statement }];
22
+ });
23
+ });
24
+ }
25
+ function changeOf(action) {
26
+ const constraint = DROP_CONSTRAINT.exec(action)?.[1];
27
+ const column = DROP_COLUMN.exec(action)?.[1];
28
+ if (constraint !== undefined) {
29
+ return { kind: 'drop-constraint', name: unquoted(constraint) };
30
+ }
31
+ if (column !== undefined) {
32
+ return { kind: 'drop-column', name: unquoted(column) };
33
+ }
34
+ return ADD_KEY.test(action) ? { kind: 'add-key', name: '' } : undefined;
35
+ }
36
+ function actionsOf(text) {
37
+ const actions = [];
38
+ let action = '';
39
+ let depth = 0;
40
+ for (const [piece] of text.matchAll(PIECES)) {
41
+ depth += piece === '(' ? 1 : piece === ')' ? -1 : 0;
42
+ if (piece === ',' && depth === 0) {
43
+ actions.push(action.trim());
44
+ action = '';
45
+ }
46
+ else {
47
+ action += piece;
48
+ }
49
+ }
50
+ return [...actions, action.trim()];
51
+ }
52
+ function unquoted(name) {
53
+ return name.startsWith('"') ? name.slice(1, -1).replaceAll('""', '"') : name.toLowerCase();
54
+ }
55
+ //# sourceMappingURL=table-changes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table-changes.js","sourceRoot":"","sources":["../../src/migration/table-changes.ts"],"names":[],"mappings":"AAGA,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAA,oCAAoC,CAAC;AAE5D,MAAM,WAAW,GAAG,IAAI,MAAM,CAC5B,MAAM,CAAC,GAAG,CAAA,4CAA4C,IAAI,YAAY,IAAI,SAAS,EACnF,GAAG,CACJ,CAAC;AAEF,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAA,sBAAsB,IAAI,kBAAkB,EAAE,GAAG,CAAC,CAAC;AACxF,MAAM,eAAe,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAA,oCAAoC,IAAI,GAAG,EAAE,GAAG,CAAC,CAAC;AAC/F,MAAM,WAAW,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAA,gCAAgC,IAAI,GAAG,EAAE,GAAG,CAAC,CAAC;AAEvF,qJAAqJ;AACrJ,MAAM,MAAM,GAAG,gDAAgD,CAAC;AAEhE;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,UAAmC;IAC9D,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE;QAChD,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AC,SAAS,CAAC;AAC1E,CAAC;AAED,SAAS,SAAS,CAAC,IAAY;IAC7B,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,KAAK,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5C,KAAK,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAEpD,IAAI,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YACjC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;YAC5B,MAAM,GAAG,EAAE,CAAC;QACd,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC;QAClB,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,OAAO,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC5B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;AAC7F,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Io } from '../commands/io.js';
2
+ import type { WrittenMigration } from './written-migration.js';
3
+ /** What follows a migration drizzle-kit wrote: its snapshot and journal formatted as the project formats its files, then the warnings on its SQL. */
4
+ export declare function tidyWrittenMigration(written: WrittenMigration, io: Io): void;
5
+ //# sourceMappingURL=tidy-written-migration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tidy-written-migration.d.ts","sourceRoot":"","sources":["../../src/migration/tidy-written-migration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAG5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,qJAAqJ;AACrJ,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,EAAE,EAAE,GAAG,IAAI,CAG5E"}
@@ -0,0 +1,8 @@
1
+ import { formatWrittenFiles } from './format-written-files.js';
2
+ import { warnPrimaryKeyOrder } from './warn-primary-key-order.js';
3
+ /** What follows a migration drizzle-kit wrote: its snapshot and journal formatted as the project formats its files, then the warnings on its SQL. */
4
+ export function tidyWrittenMigration(written, io) {
5
+ formatWrittenFiles(written, io);
6
+ warnPrimaryKeyOrder(written, io);
7
+ }
8
+ //# sourceMappingURL=tidy-written-migration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tidy-written-migration.js","sourceRoot":"","sources":["../../src/migration/tidy-written-migration.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAGlE,qJAAqJ;AACrJ,MAAM,UAAU,oBAAoB,CAAC,OAAyB,EAAE,EAAM;IACpE,kBAAkB,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAChC,mBAAmB,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Blocks until the second after `since` has begun: drizzle-kit numbers a migration with the time to
3
+ * the second (`prefix: 'timestamp'`), so two generated within one second would share a snapshot file.
4
+ */
5
+ export declare function waitForNextSecond(since: number): void;
6
+ //# sourceMappingURL=wait-for-next-second.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wait-for-next-second.d.ts","sourceRoot":"","sources":["../../src/migration/wait-for-next-second.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAMrD"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Blocks until the second after `since` has begun: drizzle-kit numbers a migration with the time to
3
+ * the second (`prefix: 'timestamp'`), so two generated within one second would share a snapshot file.
4
+ */
5
+ export function waitForNextSecond(since) {
6
+ const left = (Math.floor(since / 1000) + 1) * 1000 - Date.now();
7
+ if (left > 0) {
8
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, left);
9
+ }
10
+ }
11
+ //# sourceMappingURL=wait-for-next-second.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wait-for-next-second.js","sourceRoot":"","sources":["../../src/migration/wait-for-next-second.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAEhE,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,IAAI,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IACrE,CAAC;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Io } from '../commands/io.js';
2
+ import type { WrittenMigration } from './written-migration.js';
3
+ /** Warns, without changing the exit code, about each SQL file just written that changes a primary key in an order that fails. */
4
+ export declare function warnPrimaryKeyOrder({ paths, files }: WrittenMigration, io: Io): void;
5
+ //# sourceMappingURL=warn-primary-key-order.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"warn-primary-key-order.d.ts","sourceRoot":"","sources":["../../src/migration/warn-primary-key-order.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAG5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,iIAAiI;AACjI,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,EAAE,EAAE,EAAE,EAAE,GAAG,IAAI,CAapF"}
@@ -0,0 +1,16 @@
1
+ import { previousPrimaryKeys } from './previous-primary-keys.js';
2
+ import { primaryKeyOrderFindings } from './primary-key-order-findings.js';
3
+ /** Warns, without changing the exit code, about each SQL file just written that changes a primary key in an order that fails. */
4
+ export function warnPrimaryKeyOrder({ paths, files }, io) {
5
+ for (const file of paths.filter((written) => written.endsWith('.sql'))) {
6
+ for (const finding of primaryKeyOrderFindings(files.get(file) ?? '', previousPrimaryKeys(files, file))) {
7
+ io.err([
8
+ `Warning: ${file}: ${finding.message}`,
9
+ ` line ${finding.early.line}: ${finding.early.text}`,
10
+ ` line ${finding.drop.line}: ${finding.drop.text}`,
11
+ ` Fix: ${finding.fix}`,
12
+ ].join('\n'));
13
+ }
14
+ }
15
+ }
16
+ //# sourceMappingURL=warn-primary-key-order.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"warn-primary-key-order.js","sourceRoot":"","sources":["../../src/migration/warn-primary-key-order.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAG1E,iIAAiI;AACjI,MAAM,UAAU,mBAAmB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAoB,EAAE,EAAM;IAC5E,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;QACvE,KAAK,MAAM,OAAO,IAAI,uBAAuB,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;YACvG,EAAE,CAAC,GAAG,CACJ;gBACE,YAAY,IAAI,KAAK,OAAO,CAAC,OAAO,EAAE;gBACtC,UAAU,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE;gBACrD,UAAU,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE;gBACnD,UAAU,OAAO,CAAC,GAAG,EAAE;aACxB,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}