@intentius/sql-yodeler 0.9.0 → 0.10.1

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 (139) hide show
  1. package/README.md +5 -5
  2. package/dist/chant/apply.d.ts +6 -0
  3. package/dist/chant/apply.js +6 -2
  4. package/dist/chant/apply.js.map +1 -1
  5. package/dist/chant/build.d.ts +1 -0
  6. package/dist/chant/build.js +5 -0
  7. package/dist/chant/build.js.map +1 -1
  8. package/dist/chant/drift.d.ts +12 -1
  9. package/dist/chant/drift.js +41 -1
  10. package/dist/chant/drift.js.map +1 -1
  11. package/dist/chant/export-name.d.ts +9 -0
  12. package/dist/chant/export-name.js +16 -0
  13. package/dist/chant/export-name.js.map +1 -0
  14. package/dist/chant/runnable.d.ts +1 -1
  15. package/dist/chant/runnable.js +1 -1
  16. package/dist/chant/sql-types.d.ts +19 -0
  17. package/dist/chant/sql-types.js +29 -0
  18. package/dist/chant/sql-types.js.map +1 -0
  19. package/dist/check/flyway.d.ts +67 -0
  20. package/dist/check/flyway.js +106 -0
  21. package/dist/check/flyway.js.map +1 -0
  22. package/dist/check/readers.d.ts +77 -0
  23. package/dist/check/readers.js +270 -0
  24. package/dist/check/readers.js.map +1 -0
  25. package/dist/check/run.d.ts +72 -0
  26. package/dist/check/run.js +243 -0
  27. package/dist/check/run.js.map +1 -0
  28. package/dist/ci/render.d.ts +30 -0
  29. package/dist/ci/render.js +150 -21
  30. package/dist/ci/render.js.map +1 -1
  31. package/dist/commands/apply.d.ts +27 -3
  32. package/dist/commands/apply.js +98 -30
  33. package/dist/commands/apply.js.map +1 -1
  34. package/dist/commands/check.d.ts +5 -0
  35. package/dist/commands/check.js +211 -0
  36. package/dist/commands/check.js.map +1 -0
  37. package/dist/commands/config.js +5 -5
  38. package/dist/commands/config.js.map +1 -1
  39. package/dist/commands/drift.js +5 -0
  40. package/dist/commands/drift.js.map +1 -1
  41. package/dist/commands/index.js +2 -0
  42. package/dist/commands/index.js.map +1 -1
  43. package/dist/commands/init.js +15 -6
  44. package/dist/commands/init.js.map +1 -1
  45. package/dist/commands/lint.js +94 -16
  46. package/dist/commands/lint.js.map +1 -1
  47. package/dist/commands/new.js +56 -4
  48. package/dist/commands/new.js.map +1 -1
  49. package/dist/commands/override.js +80 -33
  50. package/dist/commands/override.js.map +1 -1
  51. package/dist/commands/plan.js +62 -30
  52. package/dist/commands/plan.js.map +1 -1
  53. package/dist/commands/revert.js +1 -1
  54. package/dist/config/define.d.ts +21 -0
  55. package/dist/config/define.js.map +1 -1
  56. package/dist/config/load.js +18 -2
  57. package/dist/config/load.js.map +1 -1
  58. package/dist/credentials.d.ts +18 -5
  59. package/dist/credentials.js +29 -11
  60. package/dist/credentials.js.map +1 -1
  61. package/dist/declarative/plan.d.ts +84 -0
  62. package/dist/declarative/plan.js +187 -0
  63. package/dist/declarative/plan.js.map +1 -0
  64. package/dist/declarative/review.d.ts +78 -0
  65. package/dist/declarative/review.js +162 -0
  66. package/dist/declarative/review.js.map +1 -0
  67. package/dist/init/adopt.d.ts +16 -7
  68. package/dist/init/adopt.js +37 -8
  69. package/dist/init/adopt.js.map +1 -1
  70. package/dist/init/baseline.d.ts +2 -1
  71. package/dist/init/baseline.js +3 -3
  72. package/dist/init/baseline.js.map +1 -1
  73. package/dist/init/clickhouse-access.d.ts +29 -10
  74. package/dist/init/clickhouse-access.js +84 -13
  75. package/dist/init/clickhouse-access.js.map +1 -1
  76. package/dist/init/live.d.ts +4 -2
  77. package/dist/init/live.js +8 -3
  78. package/dist/init/live.js.map +1 -1
  79. package/dist/init/unsupported.d.ts +15 -0
  80. package/dist/init/unsupported.js +34 -0
  81. package/dist/init/unsupported.js.map +1 -0
  82. package/dist/lint/annotations.d.ts +1 -1
  83. package/dist/lint/annotations.js +2 -0
  84. package/dist/lint/annotations.js.map +1 -1
  85. package/dist/lint/check.d.ts +5 -1
  86. package/dist/lint/check.js +58 -1
  87. package/dist/lint/check.js.map +1 -1
  88. package/dist/lint/report.js +6 -0
  89. package/dist/lint/report.js.map +1 -1
  90. package/dist/migrations/document.d.ts +6 -0
  91. package/dist/migrations/document.js +1 -0
  92. package/dist/migrations/document.js.map +1 -1
  93. package/dist/migrations/handwritten.d.ts +75 -0
  94. package/dist/migrations/handwritten.js +157 -0
  95. package/dist/migrations/handwritten.js.map +1 -0
  96. package/dist/migrations/index.d.ts +2 -0
  97. package/dist/migrations/index.js +2 -0
  98. package/dist/migrations/index.js.map +1 -1
  99. package/dist/pr/overdue.d.ts +48 -0
  100. package/dist/pr/overdue.js +88 -0
  101. package/dist/pr/overdue.js.map +1 -0
  102. package/dist/pr/part.d.ts +15 -0
  103. package/dist/pr/part.js +30 -0
  104. package/dist/pr/part.js.map +1 -0
  105. package/dist/rebase/index.js +28 -1
  106. package/dist/rebase/index.js.map +1 -1
  107. package/dist/release/index.d.ts +32 -7
  108. package/dist/release/index.js +42 -0
  109. package/dist/release/index.js.map +1 -1
  110. package/dist/replay/replay.d.ts +2 -0
  111. package/dist/replay/replay.js +2 -2
  112. package/dist/replay/replay.js.map +1 -1
  113. package/dist/replay/report.js +3 -1
  114. package/dist/replay/report.js.map +1 -1
  115. package/dist/schemas.d.ts +2 -1
  116. package/dist/schemas.js +1 -0
  117. package/dist/schemas.js.map +1 -1
  118. package/dist/steps/backfill.d.ts +8 -3
  119. package/dist/steps/backfill.js +20 -9
  120. package/dist/steps/backfill.js.map +1 -1
  121. package/dist/versioned/approval.d.ts +27 -7
  122. package/dist/versioned/approval.js +69 -18
  123. package/dist/versioned/approval.js.map +1 -1
  124. package/dist/versioned/engine.js +1 -1
  125. package/dist/versioned/engine.js.map +1 -1
  126. package/dist/versioned/op.d.ts +20 -3
  127. package/dist/versioned/op.js +12 -6
  128. package/dist/versioned/op.js.map +1 -1
  129. package/dist/versioned/policy.d.ts +2 -0
  130. package/dist/versioned/policy.js +2 -2
  131. package/dist/versioned/policy.js.map +1 -1
  132. package/package.json +9 -8
  133. package/schemas/apply.schema.json +36 -2
  134. package/schemas/check.schema.json +78 -0
  135. package/schemas/drift.schema.json +1 -0
  136. package/schemas/init.schema.json +1 -0
  137. package/schemas/lint.schema.json +9 -1
  138. package/schemas/new.schema.json +1 -0
  139. package/schemas/plan.schema.json +33 -0
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Another tool's migrations directory (#1): golang-migrate, goose, Flyway or
3
+ * dbmate, read in the order that tool applies it, the up direction only.
4
+ *
5
+ * golang-migrate `<version>_<title>.up.sql`; the `.down.sql` files are not read
6
+ * goose `<version>_<name>.sql`, the `-- +goose Up` section; a
7
+ * `-- +goose StatementBegin` ... `StatementEnd` block is one
8
+ * statement. A Go migration (`.go`) is refused: its code is not SQL
9
+ * flyway the locations its flyway.toml or flyway.conf names, read
10
+ * recursively (the directory checked when there is none):
11
+ * `V<version>__<description>.sql` by version, starting from
12
+ * the newest `B<version>__` baseline when there is one,
13
+ * then the repeatable `R__<description>.sql` files by
14
+ * description, with placeholders substituted. Undo (`U`)
15
+ * files and callbacks (`beforeMigrate.sql`, ...) are not
16
+ * read; a Java or Kotlin migration is refused (flyway.ts)
17
+ * dbmate `<version>_<name>.sql`, the `-- migrate:up` section
18
+ *
19
+ * Pure but for reading the files: no server, no git.
20
+ */
21
+ export declare const TOOLS: readonly ["golang-migrate", "goose", "flyway", "dbmate"];
22
+ export type Tool = (typeof TOOLS)[number];
23
+ /** One statement of a migration's up section, and the line of the file it starts on. */
24
+ export interface ForeignStatement {
25
+ sql: string;
26
+ line: number;
27
+ }
28
+ /** A `-- yodel:allow <rule> <reason>` line in the file. */
29
+ export interface ForeignAllow {
30
+ rule: string;
31
+ reason: string;
32
+ line: number;
33
+ }
34
+ /** One migration of the other tool, as that tool applies it. */
35
+ export interface ForeignMigration {
36
+ /** The file, relative to the directory, with `/`. */
37
+ file: string;
38
+ /** The version the tool orders by; the description for a Flyway repeatable. */
39
+ version: string;
40
+ /** The name after the version. */
41
+ name: string;
42
+ /** A Flyway repeatable migration (`R__`): applied after the versioned ones, again whenever it changes. */
43
+ repeatable?: true;
44
+ /** A Flyway baseline migration (`B__`): a fresh database starts from it, in place of the versioned files up to its version. */
45
+ baseline?: true;
46
+ /** The up section's statements, in order. */
47
+ statements: ForeignStatement[];
48
+ allows: ForeignAllow[];
49
+ }
50
+ /**
51
+ * Which tool's directory `dir` is, from its file names (a flyway.toml or
52
+ * flyway.conf in it or above it, up to `stopAt`, makes it Flyway's);
53
+ * undefined when none fits.
54
+ */
55
+ export declare function detectTool(dir: string, stopAt?: string): Tool | undefined;
56
+ export interface ReadOptions {
57
+ /** The project's directory: a flyway.toml or flyway.conf is looked for up to it. */
58
+ stopAt?: string;
59
+ /** What Flyway's own placeholders fall back to: the replay scope's default schema. */
60
+ defaults?: {
61
+ defaultSchema?: string | undefined;
62
+ };
63
+ }
64
+ /** The migrations a tool applies, and the directory their `file` names are relative to. */
65
+ export interface ForeignDir {
66
+ root: string;
67
+ /** The Flyway configuration read, when there was one. */
68
+ config?: string;
69
+ migrations: ForeignMigration[];
70
+ }
71
+ /**
72
+ * The migrations in `dir`, in the order `tool` applies them. `split`
73
+ * splits SQL into statements at top-level semicolons (the dialect's).
74
+ */
75
+ export declare function readForeign(dir: string, tool: Tool, split: (sql: string) => string[], options?: ReadOptions): ForeignMigration[];
76
+ /** {@link readForeign}, with the directory the file names are relative to: a Flyway configuration's, when one is read. */
77
+ export declare function readForeignDir(dir: string, tool: Tool, split: (sql: string) => string[], options?: ReadOptions): ForeignDir;
@@ -0,0 +1,270 @@
1
+ /**
2
+ * Another tool's migrations directory (#1): golang-migrate, goose, Flyway or
3
+ * dbmate, read in the order that tool applies it, the up direction only.
4
+ *
5
+ * golang-migrate `<version>_<title>.up.sql`; the `.down.sql` files are not read
6
+ * goose `<version>_<name>.sql`, the `-- +goose Up` section; a
7
+ * `-- +goose StatementBegin` ... `StatementEnd` block is one
8
+ * statement. A Go migration (`.go`) is refused: its code is not SQL
9
+ * flyway the locations its flyway.toml or flyway.conf names, read
10
+ * recursively (the directory checked when there is none):
11
+ * `V<version>__<description>.sql` by version, starting from
12
+ * the newest `B<version>__` baseline when there is one,
13
+ * then the repeatable `R__<description>.sql` files by
14
+ * description, with placeholders substituted. Undo (`U`)
15
+ * files and callbacks (`beforeMigrate.sql`, ...) are not
16
+ * read; a Java or Kotlin migration is refused (flyway.ts)
17
+ * dbmate `<version>_<name>.sql`, the `-- migrate:up` section
18
+ *
19
+ * Pure but for reading the files: no server, no git.
20
+ */
21
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
22
+ import { join, relative, sep } from "node:path";
23
+ import { YodelError } from "../project.js";
24
+ import { codeMigrations, findFlywayConfig, isCallback, readFlywayConfig, substitute, walk } from "./flyway.js";
25
+ export const TOOLS = ["golang-migrate", "goose", "flyway", "dbmate"];
26
+ const GOLANG_MIGRATE = /^(\d+)_(.+)\.up\.sql$/;
27
+ const GOLANG_MIGRATE_ANY = /^\d+_.+\.(up|down)\.sql$/;
28
+ const NUMBERED = /^(\d+)_(.+)\.sql$/;
29
+ const FLYWAY_ANY = /^[VURB]\d*(?:[._]\d+)*__.+\.sql$/;
30
+ const GOOSE_UP = /^--\s*\+goose\s+Up\b/i;
31
+ const GOOSE_DOWN = /^--\s*\+goose\s+Down\b/i;
32
+ const GOOSE_BEGIN = /^--\s*\+goose\s+StatementBegin\b/i;
33
+ const GOOSE_END = /^--\s*\+goose\s+StatementEnd\b/i;
34
+ const DBMATE_UP = /^--\s*migrate:up\b/i;
35
+ const DBMATE_DOWN = /^--\s*migrate:down\b/i;
36
+ const ALLOW = /^\s*--\s*yodel:allow\s+(\S+)(?:\s+(.*))?$/;
37
+ /** The files of `dir`, top level only, sorted. */
38
+ function files(dir) {
39
+ if (!existsSync(dir) || !statSync(dir).isDirectory())
40
+ throw new YodelError(`${dir} is not a directory`);
41
+ return readdirSync(dir).filter((f) => statSync(join(dir, f)).isFile()).sort();
42
+ }
43
+ /**
44
+ * Which tool's directory `dir` is, from its file names (a flyway.toml or
45
+ * flyway.conf in it or above it, up to `stopAt`, makes it Flyway's);
46
+ * undefined when none fits.
47
+ */
48
+ export function detectTool(dir, stopAt) {
49
+ const names = files(dir);
50
+ const sql = names.filter((f) => f.endsWith(".sql"));
51
+ if (sql.length > 0 && sql.every((f) => GOLANG_MIGRATE_ANY.test(f)))
52
+ return "golang-migrate";
53
+ if (findFlywayConfig(dir, stopAt) !== undefined)
54
+ return "flyway";
55
+ // Flyway reads its locations recursively, and its callbacks sit beside the migrations.
56
+ const nested = walk(dir).filter((f) => f.endsWith(".sql") && !isCallback(f));
57
+ if (nested.length > 0 && nested.every((f) => FLYWAY_ANY.test(f.split(sep).pop() ?? "")))
58
+ return "flyway";
59
+ const numbered = names.filter((f) => NUMBERED.test(f) || f.endsWith(".go"));
60
+ if (numbered.length === 0)
61
+ return undefined;
62
+ const text = sql.filter((f) => NUMBERED.test(f)).map((f) => readFileSync(join(dir, f), "utf8"));
63
+ if (names.some((f) => /^\d+_.+\.go$/.test(f)) || text.some((t) => /^--\s*\+goose\s+Up\b/im.test(t)))
64
+ return "goose";
65
+ if (text.some((t) => /^--\s*migrate:up\b/im.test(t)))
66
+ return "dbmate";
67
+ return undefined;
68
+ }
69
+ /** A version's numeric parts, for Flyway's ordering (1.10 after 1.9). */
70
+ const parts = (v) => v.split(/[._]/).map((p) => BigInt(p));
71
+ function compareVersions(a, b) {
72
+ const x = parts(a);
73
+ const y = parts(b);
74
+ for (let i = 0; i < Math.max(x.length, y.length); i++) {
75
+ const p = x[i] ?? 0n;
76
+ const q = y[i] ?? 0n;
77
+ if (p !== q)
78
+ return p < q ? -1 : 1;
79
+ }
80
+ return 0;
81
+ }
82
+ /** The statements of `lines`, split at top-level semicolons by `split`, each with the line it starts on. */
83
+ function statementsOf(lines, split) {
84
+ if (lines.length === 0)
85
+ return [];
86
+ const first = lines[0]?.line ?? 1;
87
+ const text = lines.map((l) => l.text).join("\n");
88
+ const out = [];
89
+ let from = 0;
90
+ for (const s of split(text)) {
91
+ // Its start: the statement's own text, found after the one before it.
92
+ const at = text.indexOf(s.slice(0, Math.min(s.length, 40)), from);
93
+ const start = at >= 0 ? at : from;
94
+ const lead = text.slice(0, start).split("\n").length - 1;
95
+ out.push({ sql: s, line: first + lead + leadingComments(s) });
96
+ if (at >= 0)
97
+ from = at + s.length;
98
+ }
99
+ return out;
100
+ }
101
+ /** How many whole comment lines a statement starts with, so its line is the statement's own. */
102
+ function leadingComments(sql) {
103
+ let n = 0;
104
+ for (const l of sql.split("\n")) {
105
+ if (/^\s*(--.*)?$/.test(l))
106
+ n++;
107
+ else
108
+ break;
109
+ }
110
+ return n;
111
+ }
112
+ function allowsOf(lines) {
113
+ return lines.flatMap((l) => {
114
+ const m = ALLOW.exec(l.text);
115
+ return m ? [{ rule: m[1] ?? "", reason: (m[2] ?? "").trim(), line: l.line }] : [];
116
+ });
117
+ }
118
+ const numbered = (text) => text.split(/\r?\n/).map((t, i) => ({ text: t, line: i + 1 }));
119
+ /** goose: the Up section; a StatementBegin/End block kept whole. */
120
+ function gooseUp(text, file, split) {
121
+ const lines = numbered(text);
122
+ const start = lines.findIndex((l) => GOOSE_UP.test(l.text.trim()));
123
+ if (start < 0)
124
+ throw new YodelError(`${file}: no -- +goose Up line, so goose would run nothing from it`);
125
+ const end = lines.findIndex((l, i) => i > start && GOOSE_DOWN.test(l.text.trim()));
126
+ const up = lines.slice(start + 1, end < 0 ? undefined : end);
127
+ const out = [];
128
+ let plain = [];
129
+ let block;
130
+ for (const l of up) {
131
+ if (GOOSE_BEGIN.test(l.text.trim())) {
132
+ out.push(...statementsOf(plain, split));
133
+ plain = [];
134
+ block = [];
135
+ continue;
136
+ }
137
+ if (GOOSE_END.test(l.text.trim())) {
138
+ if (block === undefined)
139
+ throw new YodelError(`${file}:${String(l.line)}: -- +goose StatementEnd with no StatementBegin before it`);
140
+ const sql = block.map((b) => b.text).join("\n").trim().replace(/;\s*$/, "");
141
+ const at = block.find((b) => b.text.trim() !== "" && !b.text.trim().startsWith("--"));
142
+ if (sql !== "")
143
+ out.push({ sql, line: at?.line ?? block[0]?.line ?? l.line });
144
+ block = undefined;
145
+ continue;
146
+ }
147
+ if (block !== undefined)
148
+ block.push(l);
149
+ else
150
+ plain.push(l);
151
+ }
152
+ if (block !== undefined)
153
+ throw new YodelError(`${file}: -- +goose StatementBegin with no StatementEnd after it`);
154
+ out.push(...statementsOf(plain, split));
155
+ return { statements: out, up };
156
+ }
157
+ /** dbmate: the `-- migrate:up` section. */
158
+ function dbmateUp(text, file) {
159
+ const lines = numbered(text);
160
+ const start = lines.findIndex((l) => DBMATE_UP.test(l.text.trim()));
161
+ if (start < 0)
162
+ throw new YodelError(`${file}: no -- migrate:up line, so dbmate would run nothing from it`);
163
+ const end = lines.findIndex((l, i) => i > start && DBMATE_DOWN.test(l.text.trim()));
164
+ return lines.slice(start + 1, end < 0 ? undefined : end);
165
+ }
166
+ /**
167
+ * The migrations in `dir`, in the order `tool` applies them. `split`
168
+ * splits SQL into statements at top-level semicolons (the dialect's).
169
+ */
170
+ export function readForeign(dir, tool, split, options = {}) {
171
+ return readForeignDir(dir, tool, split, options).migrations;
172
+ }
173
+ /** {@link readForeign}, with the directory the file names are relative to: a Flyway configuration's, when one is read. */
174
+ export function readForeignDir(dir, tool, split, options = {}) {
175
+ if (tool === "flyway")
176
+ return readFlyway(dir, split, options);
177
+ const names = files(dir);
178
+ const read = (f) => readFileSync(join(dir, f), "utf8");
179
+ const byVersion = (out) => ({ root: dir, migrations: out.sort((a, b) => compareVersions(a.version, b.version)) });
180
+ switch (tool) {
181
+ case "golang-migrate":
182
+ return byVersion(names.flatMap((f) => {
183
+ const m = GOLANG_MIGRATE.exec(f);
184
+ if (!m)
185
+ return [];
186
+ const lines = numbered(read(f));
187
+ return [{ file: f, version: m[1] ?? "", name: m[2] ?? "", statements: statementsOf(lines, split), allows: allowsOf(lines) }];
188
+ }));
189
+ case "goose": {
190
+ const go = names.filter((f) => /^\d+_.+\.go$/.test(f));
191
+ if (go.length > 0)
192
+ throw new YodelError(`${go.join(", ")}: a Go migration is code, which yodel check cannot read; only goose's SQL migrations are checked`);
193
+ return byVersion(names.flatMap((f) => {
194
+ const m = NUMBERED.exec(f);
195
+ if (!m)
196
+ return [];
197
+ const { statements, up } = gooseUp(read(f), f, split);
198
+ return [{ file: f, version: m[1] ?? "", name: m[2] ?? "", statements, allows: allowsOf(up) }];
199
+ }));
200
+ }
201
+ case "dbmate":
202
+ return byVersion(names.flatMap((f) => {
203
+ const m = NUMBERED.exec(f);
204
+ if (!m)
205
+ return [];
206
+ const up = dbmateUp(read(f), f);
207
+ return [{ file: f, version: m[1] ?? "", name: m[2] ?? "", statements: statementsOf(up, split), allows: allowsOf(up) }];
208
+ }));
209
+ }
210
+ }
211
+ const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
212
+ /** Flyway: see the module comment, and flyway.ts for the configuration. */
213
+ function readFlyway(dir, split, options) {
214
+ const file = findFlywayConfig(dir, options.stopAt);
215
+ const config = readFlywayConfig(file, dir);
216
+ const code = codeMigrations(config);
217
+ if (code.length > 0)
218
+ throw new YodelError(`${code.join(", ")}: a Java or Kotlin migration is code, which yodel check cannot read or replay; only Flyway's SQL migrations are checked`);
219
+ if (!config.locations.some((l) => existsSync(l))) {
220
+ throw new YodelError(`${config.locations.map((l) => relative(process.cwd(), l) || l).join(", ")}: no such directory${file !== undefined ? ` (the locations ${file} names)` : ""}`);
221
+ }
222
+ const suffix = `(?:${config.sqlMigrationSuffixes.map(esc).join("|")})`;
223
+ const sepr = esc(config.sqlMigrationSeparator);
224
+ const V = new RegExp(`^${esc(config.sqlMigrationPrefix)}(\\d+(?:[._]\\d+)*)${sepr}(.+?)${suffix}$`);
225
+ const B = new RegExp(`^${esc(config.baselineMigrationPrefix)}(\\d+(?:[._]\\d+)*)${sepr}(.+?)${suffix}$`);
226
+ const R = new RegExp(`^${esc(config.repeatableSqlMigrationPrefix)}${sepr}(.+?)${suffix}$`);
227
+ const versioned = [];
228
+ const baselines = [];
229
+ const repeatable = [];
230
+ const seen = new Map();
231
+ for (const abs of [...new Set(config.locations.flatMap((l) => walk(l)))]) {
232
+ const name = abs.split(sep).pop() ?? "";
233
+ if (isCallback(name))
234
+ continue;
235
+ const v = V.exec(name);
236
+ const b = v ? null : B.exec(name);
237
+ const r = v || b ? null : R.exec(name);
238
+ if (!v && !b && !r)
239
+ continue;
240
+ const rel = relative(config.root, abs).split(sep).join("/");
241
+ const lines = numbered(substitute(readFileSync(abs, "utf8"), rel, config, options.defaults));
242
+ const m = { file: rel, statements: statementsOf(lines, split), allows: allowsOf(lines) };
243
+ if (r) {
244
+ repeatable.push({ ...m, version: r[1] ?? "", name: r[1] ?? "", repeatable: true });
245
+ continue;
246
+ }
247
+ const hit = v ?? b;
248
+ const version = hit?.[1] ?? "";
249
+ // 1 and 1.0 are one version to Flyway: trailing zero parts do not count.
250
+ const p = parts(version);
251
+ while (p.length > 1 && p.at(-1) === 0n)
252
+ p.pop();
253
+ const key = `${b ? "B" : "V"}${p.join(".")}`;
254
+ const before = seen.get(key);
255
+ if (before !== undefined)
256
+ throw new YodelError(`${before} and ${rel}: two ${b ? "baseline" : "versioned"} migrations of version ${version}, which Flyway refuses too`);
257
+ seen.set(key, rel);
258
+ if (b)
259
+ baselines.push({ ...m, version, name: hit?.[2] ?? "", baseline: true });
260
+ else
261
+ versioned.push({ ...m, version, name: hit?.[2] ?? "" });
262
+ }
263
+ versioned.sort((a, b) => compareVersions(a.version, b.version));
264
+ repeatable.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
265
+ // A fresh database starts from the newest baseline, then the versioned files after it.
266
+ const baseline = baselines.sort((a, b) => compareVersions(a.version, b.version)).at(-1);
267
+ const after = baseline === undefined ? versioned : versioned.filter((m) => compareVersions(m.version, baseline.version) > 0);
268
+ return { root: config.root, ...(file !== undefined ? { config: file } : {}), migrations: [...(baseline ? [baseline] : []), ...after, ...repeatable] };
269
+ }
270
+ //# sourceMappingURL=readers.js.map
@@ -0,0 +1 @@
1
+ {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,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7H,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC;AACxJ,CAAC"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * `yodel check` (#1): another tool's migrations, replayed and linted.
3
+ *
4
+ * The directory's migrations run, in the tool's order, against a
5
+ * throwaway server (a profile bound to the emulator, `replay` by default).
6
+ * After the ones already on the base branch, and again after each new one,
7
+ * the server's schema is read the way `yodel init --from` reads it and
8
+ * built. Each new migration then becomes the change between two builds:
9
+ * yodel's classifier names what it does (a drop, a rewrite, a lock, a
10
+ * statement that can fail on the rows there), and every `yodel lint` rule
11
+ * runs on it, the project's own policies included. Nothing is applied to
12
+ * an environment that matters: the scope is emptied before and after.
13
+ */
14
+ import { type Environment, type Project } from "../project.js";
15
+ import { type BuildOutput } from "../chant/build.js";
16
+ import { type LintOptions, type LintReport } from "../lint/index.js";
17
+ import type { ForeignMigration } from "./readers.js";
18
+ /** The server a check replays into: its schemas or databases, emptied before and after. */
19
+ export interface CheckServer {
20
+ where: string;
21
+ /** The schemas (Postgres) or databases (ClickHouse) the profile reads. */
22
+ scope: readonly string[];
23
+ /** The ones of {@link scope} that hold anything. */
24
+ occupied(): Promise<string[]>;
25
+ clear(): Promise<void>;
26
+ /** Runs one statement of a migration; throws the server's error. */
27
+ run(sql: string): Promise<void>;
28
+ /** The default schema or database, for the classifier. */
29
+ defaults: {
30
+ defaultSchema?: string;
31
+ defaultDatabase?: string;
32
+ };
33
+ close(): Promise<void>;
34
+ }
35
+ /** The check server for `env`, the profile's scope on its server. */
36
+ export declare function openCheckServer(project: Project, env: Environment, processEnv?: NodeJS.ProcessEnv): Promise<CheckServer>;
37
+ /** The server's schema in scope, read as `yodel init --from` reads it and built; an empty build when it holds nothing. */
38
+ export declare function snapshot(project: Project, env: Environment, processEnv?: NodeJS.ProcessEnv): Promise<BuildOutput>;
39
+ /** A migration name yodel accepts, from the other tool's. */
40
+ export declare function migrationName(name: string): string;
41
+ /** What a check found: the lint report over the new migrations, each finding on the other tool's file. */
42
+ export interface CheckResult {
43
+ report: LintReport;
44
+ /** The other tool's migrations, in order. */
45
+ migrations: string[];
46
+ /** The ones new since the base, which were linted. */
47
+ checked: string[];
48
+ where: string;
49
+ }
50
+ export interface CheckOptions {
51
+ /** The migrations directory, absolute: the findings' files are relative to it. */
52
+ dir: string;
53
+ /** The files new or changed since the base; the rest only replay. */
54
+ isNew: (m: ForeignMigration) => boolean;
55
+ /** Empty the scope first when it holds anything. */
56
+ reset: boolean;
57
+ /** Leave the replayed schema in place. */
58
+ keep: boolean;
59
+ lint: LintOptions;
60
+ processEnv?: NodeJS.ProcessEnv;
61
+ log?: (line: string) => void;
62
+ }
63
+ /** Runs `migrations` in order into `server` and lints each new one; see the module comment. */
64
+ export declare function runCheck(project: Project, env: Environment, server: CheckServer, migrations: readonly ForeignMigration[], options: CheckOptions): Promise<CheckResult>;
65
+ /**
66
+ * The lint report on the other tool's files: findings on the base
67
+ * migration dropped, the rest moved onto the file that made the change, a
68
+ * `-- yodel:allow <rule> <reason>` line in that file silencing that rule
69
+ * there, and a pg-lock finding left out when the file builds or drops the
70
+ * index CONCURRENTLY (the classifier reads the schema, which does not say).
71
+ */
72
+ export declare function onForeignFiles(report: LintReport, byId: ReadonlyMap<string, ForeignMigration>, dir: string): LintReport;