@substrat-run/model-emit 0.4.0 → 0.5.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.
@@ -16,7 +16,8 @@ export interface EmitSqlOptions {
16
16
  * accepts duplicate rows and a column-wise parity check cannot see it (#804).
17
17
  * - `key` becomes a `UNIQUE` constraint.
18
18
  * - `parents` becomes a `REFERENCES` clause per parent, on `<parent>_id` when the
19
- * entity declares such a column — never invented if it does not.
19
+ * entity declares such a column — never invented if it does not, and pointed at
20
+ * the parent's own key rather than an assumed `id`.
20
21
  */
21
22
  export declare function emitTables<T extends Record<string, EntityDef>>(entities: T, options?: EmitSqlOptions): string;
22
23
  /** One emitted column: its name, its full definition, and whether SQLite could ADD it. */
@@ -1 +1 @@
1
- {"version":3,"file":"emit-sql.d.ts","sourceRoot":"","sources":["../src/emit-sql.ts"],"names":[],"mappings":"AAqBA,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,yBAAyB,CAAC;AA+HpF,MAAM,WAAW,cAAc;IAC7B,wEAAwE;IACxE,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAC5D,QAAQ,EAAE,CAAC,EACX,OAAO,GAAE,cAAmB,GAC3B,MAAM,CAgBR;AAED,0FAA0F;AAC1F,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0DAA0D;IAC1D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,iFAAiF;IACjF,QAAQ,CAAC,sBAAsB,EAAE,OAAO,CAAC;CAC1C;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAC3D,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,S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GAYG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,MAAM,EAAE,CAO3E"}
package/dist/emit-sql.js CHANGED
@@ -137,7 +137,8 @@ function tableOrder(entities) {
137
137
  * accepts duplicate rows and a column-wise parity check cannot see it (#804).
138
138
  * - `key` becomes a `UNIQUE` constraint.
139
139
  * - `parents` becomes a `REFERENCES` clause per parent, on `<parent>_id` when the
140
- * entity declares such a column — never invented if it does not.
140
+ * entity declares such a column — never invented if it does not, and pointed at
141
+ * the parent's own key rather than an assumed `id`.
141
142
  */
142
143
  export function emitTables(entities, options = {}) {
143
144
  const exists = options.ifNotExists ? 'IF NOT EXISTS ' : '';
@@ -187,12 +188,27 @@ export function columnsOf(name, entity, entities) {
187
188
  ddl += ' NOT NULL';
188
189
  if (c.check)
189
190
  ddl += ` ${c.check}`;
190
- // A parent edge whose id column is present becomes a real foreign key.
191
+ // A parent edge whose id column is present becomes a real foreign key
192
+ // pointed at the parent's OWN key, which is not always `id`.
191
193
  for (const parent of entity.parents ?? []) {
192
- const parentTable = entities[parent]?.table;
193
- if (parentTable && c.name === `${String(parent).replace(/([a-z0-9])([A-Z])/g, '$1_$2').toLowerCase()}_id`) {
194
- ddl += ` REFERENCES ${parentTable}(id)`;
194
+ const parentEntity = entities[parent];
195
+ if (!parentEntity)
196
+ continue;
197
+ if (c.name !== `${String(parent).replace(/([a-z0-9])([A-Z])/g, '$1_$2').toLowerCase()}_id`)
198
+ continue;
199
+ const parentKey = primaryKeyOf(String(parent), parentEntity);
200
+ if (parentKey.length > 1) {
201
+ // A one-column reference cannot point at a several-column key. SQLite
202
+ // parses `REFERENCES t(id)` against a table with no `id` quite happily
203
+ // and then rejects every valid child row at INSERT with "foreign key
204
+ // mismatch" — so this must refuse at emit, where someone can read it.
205
+ throw new Error(`emit-sql: ${name}.${c.name} points at '${String(parent)}', which is keyed by ` +
206
+ `(${parentKey.join(', ')}) — a single column cannot reference a composite key. ` +
207
+ 'A composite-keyed table is not something the platform can point at: give the ' +
208
+ 'parent a single-column identity, or drop the parent edge and model the link ' +
209
+ 'in your own columns');
195
210
  }
211
+ ddl += ` REFERENCES ${parentEntity.table}(${parentKey[0]})`;
196
212
  }
197
213
  out.push({ name: c.name, ddl, requiredWithoutDefault: !c.nullable });
198
214
  }
@@ -1 +1 @@
1
- {"version":3,"file":"emit-sql.js","sourceRoot":"","sources":["../src/emit-sql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,YAAY,EAAkB,MAAM,yBAAyB,CAAC;AAWpF,8EAA8E;AAC9E,SAAS,IAAI,CAAC,MAAoB;IAChC,IAAI,CAAC,GAAG,MAAM,CAAC;IACf,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,sEAAsE;IACtE,SAAS,CAAC;QACR,MAAM,GAAG,GAAI,CAAgE,CAAC,IAAI,CAAC;QACnF,MAAM,CAAC,GAAG,GAAG,EAAE,QAAQ,IAAK,CAAuB,CAAC,IAAI,CAAC;QACzD,IAAI,CAAC,CAAC,KAAK,aAAa,IAAI,CAAC,KAAK,aAAa,IAAI,CAAC,KAAK,UAAU,IAAI,CAAC,KAAK,UAAU,CAAC,IAAI,GAAG,EAAE,SAAS,EAAE,CAAC;YAC3G,QAAQ,GAAG,IAAI,CAAC;YAChB,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC;YAClB,SAAS;QACX,CAAC;QACD,2DAA2D;QAC3D,MAAM,MAAM,GAAI,CAAqC,CAAC,MAAM,CAAC;QAC7D,IAAI,OAAO,MAAM,KAAK,UAAU,IAAI,CAAC,CAAC,KAAK,aAAa,IAAI,CAAC,KAAK,aAAa,CAAC,EAAE,CAAC;YACjF,QAAQ,GAAG,IAAI,CAAC;YAChB,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACnB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AK,CAAC,aAAa,IAAI,eAAe,CAAC,yBAAyB,CAAC,CAAC;IACjG,CAAC;IACD,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC9D,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { emitTables, columnsOf, primaryKeyConstraint, uniqueConstraints, type EmitSqlOptions, type EmittedColumn, } from './emit-sql.js';
2
2
  export { journalColumns, journalUniques, journalPrimaryKeys } from './journal.js';
3
+ export { readSchema, statements, type TableSchema } from './replay.js';
3
4
  export { planMigration, parseJournal, type Journal, type JournalEntry, type MigrationPlan, } from './plan.js';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,oBAAoB,EACpB,iBAAiB,EACjB,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EACL,aAAa,EACb,YAAY,EACZ,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,aAAa,GACnB,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,oBAAoB,EACpB,iBAAiB,EACjB,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EACL,aAAa,EACb,YAAY,EACZ,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,aAAa,GACnB,MAAM,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { emitTables, columnsOf, primaryKeyConstraint, uniqueConstraints, } from './emit-sql.js';
2
2
  export { journalColumns, journalUniques, journalPrimaryKeys } from './journal.js';
3
+ export { readSchema, statements } from './replay.js';
3
4
  export { planMigration, parseJournal, } from './plan.js';
4
5
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,oBAAoB,EACpB,iBAAiB,GAGlB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EACL,aAAa,EACb,YAAY,GAIb,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,oBAAoB,EACpB,iBAAiB,GAGlB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EAAE,UAAU,EAAE,UAAU,EAAoB,MAAM,aAAa,CAAC;AACvE,OAAO,EACL,aAAa,EACb,YAAY,GAIb,MAAM,WAAW,CAAC"}
package/dist/journal.d.ts CHANGED
@@ -1,36 +1,35 @@
1
- /**
2
- * Reading a migration journal — the verification half of `emitTables`.
3
- *
4
- * The emitter's claim is "what this emits is what the database ends up with";
5
- * this is how that gets checked. They live together because they are two halves
6
- * of one statement, and a reader that drifts from its emitter checks nothing.
7
- */
8
1
  /**
9
2
  * Column names per table, read out of a migration journal's SQL.
10
3
  *
11
- * Three engines had hand-rolled a copy of this and the copies had already drifted — none followed `RENAME TO`, so a journal that
12
- * rebuilds a table under a temporary name would report the pre-rebuild columns
13
- * forever.
4
+ * Three engines had hand-rolled a copy of this and the copies had already
5
+ * drifted none followed `RENAME TO`, so a journal that rebuilds a table under
6
+ * a temporary name would report the pre-rebuild columns forever.
14
7
  *
15
8
  * It exists because a registry and a journal are two descriptions of one schema
16
9
  * until migrations are derived from the registry. Holding them to each other is
17
10
  * what keeps that duplication safe in the meantime.
18
11
  *
19
- * Handles what real journals do: multi-line `CHECK (...)` constraints (tracked
20
- * by paren depth, so a continuation line is not read as a column), `ADD COLUMN`,
21
- * `DROP TABLE`, `RENAME COLUMN` and `RENAME TO` append-only journals rebuild a table by
22
- * creating a `_new`, copying, dropping the original and renaming onto its name.
12
+ * Everything a real journal does is handled, because SQLite handles it:
13
+ * `ADD COLUMN`, `DROP TABLE`, `RENAME COLUMN`, and the `RENAME TO` that an
14
+ * append-only journal uses to rebuild a table by creating a `_new`, copying,
15
+ * dropping the original and renaming onto its name.
23
16
  */
24
17
  export declare function journalColumns(sql: string): Map<string, Set<string>>;
25
18
  /**
26
19
  * UNIQUE constraints per table, read out of a journal.
27
20
  *
28
- * `journalColumns` deliberately skips constraint lines it answers "which
29
- * columns exist". But a declared `key` is a schema fact too, and adding one to
30
- * an entity that already has a table is a change SQLite cannot make in place.
31
- * Without this the planner reported "up to date" over a missing constraint.
21
+ * `journalColumns` answers "which columns exist". But a declared `key` is a
22
+ * schema fact too, and adding one to an entity that already has a table is a
23
+ * change SQLite cannot make in place. Without this the planner reported "up to
24
+ * date" over a missing constraint.
25
+ *
26
+ * All three spellings count, because the database does not distinguish them:
27
+ * table-level `UNIQUE (a, b)`, column-level `b TEXT UNIQUE`, and
28
+ * `CREATE UNIQUE INDEX … ON t (b)`. A PARTIAL index (`… WHERE deleted_at IS
29
+ * NULL`) is excluded — it constrains a subset of the rows, so counting it would
30
+ * claim a guarantee the database does not make.
32
31
  *
33
- * Normalised to `a, b` (single space, declaration order preserved) so the same
32
+ * Normalised to `a, b` (single space, key order preserved) so the same
34
33
  * constraint written two ways compares equal.
35
34
  */
36
35
  export declare function journalUniques(sql: string): Map<string, Set<string>>;
@@ -43,15 +42,13 @@ export declare function journalUniques(sql: string): Map<string, Set<string>>;
43
42
  * names, types and nullability across 63 tables and reported 63/63 while 15 of
44
43
  * the emitted tables had no primary key at all.
45
44
  *
46
- * Both spellings are read, because journals use both: inline
47
- * (`id TEXT PRIMARY KEY NOT NULL`) for one column, and a table-level
48
- * `PRIMARY KEY (a, b)` for several. A table with no primary key maps to an
49
- * EMPTY array rather than being absent — "the journal never built this table"
50
- * and "the journal built it without a key" are different answers, and only one
51
- * of them is a bug.
45
+ * A table with no primary key maps to an EMPTY array rather than being absent —
46
+ * "the journal never built this table" and "the journal built it without a key"
47
+ * are different answers, and only one of them is a bug.
52
48
  *
53
- * Order is preserved: a composite primary key is the index its columns are
54
- * searched by, so `(a, b)` and `(b, a)` are not the same key.
49
+ * Order is the KEY's order, which is not always declaration order: a composite
50
+ * primary key is the index its columns are searched by, so `(a, b)` and `(b, a)`
51
+ * are not the same key.
55
52
  */
56
53
  export declare function journalPrimaryKeys(sql: string): Map<string, string[]>;
57
54
  //# sourceMappingURL=journal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"journal.d.ts","sourceRoot":"","sources":["../src/journal.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CA4CpE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAwDpE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAyDrE"}
1
+ {"version":3,"file":"journal.d.ts","sourceRoot":"","sources":["../src/journal.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAIpE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAIpE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAIrE"}
package/dist/journal.js CHANGED
@@ -4,127 +4,60 @@
4
4
  * The emitter's claim is "what this emits is what the database ends up with";
5
5
  * this is how that gets checked. They live together because they are two halves
6
6
  * of one statement, and a reader that drifts from its emitter checks nothing.
7
+ *
8
+ * All three readers are now views onto one replay (`./replay.ts`): the journal
9
+ * is run into an in-memory SQLite and the schema read back through `PRAGMA`.
10
+ * Before that they were three hand-rolled parsers over SQL text, and #807 is
11
+ * what that cost — the same table reformatted read as a different schema, and
12
+ * the three `RENAME TO` / `RENAME COLUMN` / `DROP TABLE` replay loops that used
13
+ * to live here, one per reader, were each a re-implementation of what the
14
+ * database does for free.
7
15
  */
16
+ import { readSchema } from './replay.js';
8
17
  /**
9
18
  * Column names per table, read out of a migration journal's SQL.
10
19
  *
11
- * Three engines had hand-rolled a copy of this and the copies had already drifted — none followed `RENAME TO`, so a journal that
12
- * rebuilds a table under a temporary name would report the pre-rebuild columns
13
- * forever.
20
+ * Three engines had hand-rolled a copy of this and the copies had already
21
+ * drifted none followed `RENAME TO`, so a journal that rebuilds a table under
22
+ * a temporary name would report the pre-rebuild columns forever.
14
23
  *
15
24
  * It exists because a registry and a journal are two descriptions of one schema
16
25
  * until migrations are derived from the registry. Holding them to each other is
17
26
  * what keeps that duplication safe in the meantime.
18
27
  *
19
- * Handles what real journals do: multi-line `CHECK (...)` constraints (tracked
20
- * by paren depth, so a continuation line is not read as a column), `ADD COLUMN`,
21
- * `DROP TABLE`, `RENAME COLUMN` and `RENAME TO` append-only journals rebuild a table by
22
- * creating a `_new`, copying, dropping the original and renaming onto its name.
28
+ * Everything a real journal does is handled, because SQLite handles it:
29
+ * `ADD COLUMN`, `DROP TABLE`, `RENAME COLUMN`, and the `RENAME TO` that an
30
+ * append-only journal uses to rebuild a table by creating a `_new`, copying,
31
+ * dropping the original and renaming onto its name.
23
32
  */
24
33
  export function journalColumns(sql) {
25
- const tables = new Map();
26
- for (const [, table, body] of sql.matchAll(/CREATE TABLE (?:IF NOT EXISTS )?([a-z_][a-z0-9_]*)\s*\(([\s\S]*?)\n\s*\);/gi)) {
27
- if (!table || !body)
28
- continue;
29
- const cols = new Set();
30
- let depth = 0;
31
- for (const raw of body.split('\n')) {
32
- const line = raw.trim();
33
- const atTop = depth === 0;
34
- depth += (line.match(/\(/g) ?? []).length - (line.match(/\)/g) ?? []).length;
35
- if (!atTop)
36
- continue;
37
- if (!line || line.startsWith('--') || /^(PRIMARY|FOREIGN|UNIQUE|CHECK|CONSTRAINT)\b/i.test(line))
38
- continue;
39
- const name = /^([a-z_][a-z0-9_]*)\b/i.exec(line)?.[1];
40
- if (name)
41
- cols.add(name);
42
- }
43
- tables.set(table, cols);
44
- }
45
- // Replayed in statement order: a journal may add a column and later rename the
46
- // table, or rename onto a name it has just dropped.
47
- for (const m of sql.matchAll(
48
- // `RENAME COLUMN` comes first: `RENAME TO` must not swallow it. Without this
49
- // branch a renamed column reads as its old name forever, and a planner that
50
- // derives migrations would emit the same rename on every run.
51
- /(?:ALTER TABLE ([a-z_][a-z0-9_]*)\s+ADD COLUMN\s+([a-z_][a-z0-9_]*))|(?:ALTER TABLE ([a-z_][a-z0-9_]*)\s+RENAME COLUMN\s+([a-z_][a-z0-9_]*)\s+TO\s+([a-z_][a-z0-9_]*))|(?:ALTER TABLE ([a-z_][a-z0-9_]*)\s+RENAME TO\s+([a-z_][a-z0-9_]*))|(?:DROP TABLE (?:IF EXISTS )?([a-z_][a-z0-9_]*))/gi)) {
52
- const [, addTable, addCol, renTable, renFrom, renTo, fromTable, toTable, dropped] = m;
53
- if (addTable && addCol)
54
- tables.get(addTable)?.add(addCol);
55
- else if (dropped)
56
- tables.delete(dropped);
57
- else if (renTable && renFrom && renTo) {
58
- const cols = tables.get(renTable);
59
- if (cols?.delete(renFrom))
60
- cols.add(renTo);
61
- }
62
- else if (fromTable && toTable) {
63
- const cols = tables.get(fromTable);
64
- if (cols) {
65
- tables.delete(fromTable);
66
- tables.set(toTable, cols);
67
- }
68
- }
69
- }
70
- return tables;
34
+ const out = new Map();
35
+ for (const [table, schema] of readSchema(sql))
36
+ out.set(table, new Set(schema.columns));
37
+ return out;
71
38
  }
72
39
  /**
73
40
  * UNIQUE constraints per table, read out of a journal.
74
41
  *
75
- * `journalColumns` deliberately skips constraint lines it answers "which
76
- * columns exist". But a declared `key` is a schema fact too, and adding one to
77
- * an entity that already has a table is a change SQLite cannot make in place.
78
- * Without this the planner reported "up to date" over a missing constraint.
42
+ * `journalColumns` answers "which columns exist". But a declared `key` is a
43
+ * schema fact too, and adding one to an entity that already has a table is a
44
+ * change SQLite cannot make in place. Without this the planner reported "up to
45
+ * date" over a missing constraint.
46
+ *
47
+ * All three spellings count, because the database does not distinguish them:
48
+ * table-level `UNIQUE (a, b)`, column-level `b TEXT UNIQUE`, and
49
+ * `CREATE UNIQUE INDEX … ON t (b)`. A PARTIAL index (`… WHERE deleted_at IS
50
+ * NULL`) is excluded — it constrains a subset of the rows, so counting it would
51
+ * claim a guarantee the database does not make.
79
52
  *
80
- * Normalised to `a, b` (single space, declaration order preserved) so the same
53
+ * Normalised to `a, b` (single space, key order preserved) so the same
81
54
  * constraint written two ways compares equal.
82
55
  */
83
56
  export function journalUniques(sql) {
84
- const tables = new Map();
85
- for (const [, table, body] of sql.matchAll(/CREATE TABLE (?:IF NOT EXISTS )?([a-z_][a-z0-9_]*)\s*\(([\s\S]*?)\n\s*\);/gi)) {
86
- if (!table || !body)
87
- continue;
88
- const found = new Set();
89
- for (const [, cols] of body.matchAll(/\bUNIQUE\s*\(([^)]*)\)/gi)) {
90
- if (!cols)
91
- continue;
92
- found.add(cols
93
- .split(',')
94
- .map((c) => c.trim())
95
- .filter(Boolean)
96
- .join(', '));
97
- }
98
- tables.set(table, found);
99
- }
100
- // Replayed in statement order, like `journalColumns`.
101
- for (const m of sql.matchAll(/(?:ALTER TABLE ([a-z_][a-z0-9_]*)\s+RENAME COLUMN\s+([a-z_][a-z0-9_]*)\s+TO\s+([a-z_][a-z0-9_]*))|(?:ALTER TABLE ([a-z_][a-z0-9_]*)\s+RENAME TO\s+([a-z_][a-z0-9_]*))|(?:DROP TABLE (?:IF EXISTS )?([a-z_][a-z0-9_]*))/gi)) {
102
- const [, renTable, renFrom, renTo, fromTable, toTable, dropped] = m;
103
- if (dropped) {
104
- tables.delete(dropped);
105
- }
106
- else if (renTable && renFrom && renTo) {
107
- // SQLite rewrites the constraint when a column is renamed — verified
108
- // against a real database — so the reader has to as well. Missing this
109
- // makes a renamed key look like a key the journal never had.
110
- const cs = tables.get(renTable);
111
- if (cs) {
112
- tables.set(renTable, new Set([...cs].map((c) => c
113
- .split(', ')
114
- .map((col) => (col === renFrom ? renTo : col))
115
- .join(', '))));
116
- }
117
- }
118
- else if (fromTable && toTable) {
119
- // A rebuild renames a table onto another's name; constraints travel with it.
120
- const c = tables.get(fromTable);
121
- if (c) {
122
- tables.delete(fromTable);
123
- tables.set(toTable, c);
124
- }
125
- }
126
- }
127
- return tables;
57
+ const out = new Map();
58
+ for (const [table, schema] of readSchema(sql))
59
+ out.set(table, new Set(schema.uniques));
60
+ return out;
128
61
  }
129
62
  /**
130
63
  * The primary key per table, read out of a journal.
@@ -135,71 +68,18 @@ export function journalUniques(sql) {
135
68
  * names, types and nullability across 63 tables and reported 63/63 while 15 of
136
69
  * the emitted tables had no primary key at all.
137
70
  *
138
- * Both spellings are read, because journals use both: inline
139
- * (`id TEXT PRIMARY KEY NOT NULL`) for one column, and a table-level
140
- * `PRIMARY KEY (a, b)` for several. A table with no primary key maps to an
141
- * EMPTY array rather than being absent — "the journal never built this table"
142
- * and "the journal built it without a key" are different answers, and only one
143
- * of them is a bug.
71
+ * A table with no primary key maps to an EMPTY array rather than being absent —
72
+ * "the journal never built this table" and "the journal built it without a key"
73
+ * are different answers, and only one of them is a bug.
144
74
  *
145
- * Order is preserved: a composite primary key is the index its columns are
146
- * searched by, so `(a, b)` and `(b, a)` are not the same key.
75
+ * Order is the KEY's order, which is not always declaration order: a composite
76
+ * primary key is the index its columns are searched by, so `(a, b)` and `(b, a)`
77
+ * are not the same key.
147
78
  */
148
79
  export function journalPrimaryKeys(sql) {
149
- const tables = new Map();
150
- for (const [, table, body] of sql.matchAll(/CREATE TABLE (?:IF NOT EXISTS )?([a-z_][a-z0-9_]*)\s*\(([\s\S]*?)\n\s*\);/gi)) {
151
- if (!table || !body)
152
- continue;
153
- let key = [];
154
- let depth = 0;
155
- for (const raw of body.split('\n')) {
156
- const line = raw.trim();
157
- const atTop = depth === 0;
158
- depth += (line.match(/\(/g) ?? []).length - (line.match(/\)/g) ?? []).length;
159
- if (!atTop || !line || line.startsWith('--'))
160
- continue;
161
- // Table-level. Written as its own clause, so it wins over any inline
162
- // spelling — a table cannot legally have both, and if one somehow did,
163
- // the explicit list is the one a reader would believe.
164
- const composite = /^(?:CONSTRAINT\s+[a-z_][a-z0-9_]*\s+)?PRIMARY\s+KEY\s*\(([^)]*)\)/i.exec(line);
165
- if (composite?.[1]) {
166
- key = composite[1]
167
- .split(',')
168
- // `PRIMARY KEY (a DESC, b COLLATE NOCASE)` — the column is the first word.
169
- .map((c) => /^([a-z_][a-z0-9_]*)/i.exec(c.trim())?.[1] ?? '')
170
- .filter(Boolean);
171
- continue;
172
- }
173
- if (/^(PRIMARY|FOREIGN|UNIQUE|CHECK|CONSTRAINT)\b/i.test(line))
174
- continue;
175
- // Inline, on the column that carries it.
176
- const name = /^([a-z_][a-z0-9_]*)\b/i.exec(line)?.[1];
177
- if (name && /\bPRIMARY\s+KEY\b/i.test(line) && key.length === 0)
178
- key = [name];
179
- }
180
- tables.set(table, key);
181
- }
182
- // Replayed in statement order, like `journalColumns`. A rebuild renames a
183
- // table onto another's name and the key travels with it; `ADD COLUMN` cannot
184
- // introduce one, because SQLite refuses to add a PRIMARY KEY column.
185
- for (const m of sql.matchAll(/(?:ALTER TABLE ([a-z_][a-z0-9_]*)\s+RENAME COLUMN\s+([a-z_][a-z0-9_]*)\s+TO\s+([a-z_][a-z0-9_]*))|(?:ALTER TABLE ([a-z_][a-z0-9_]*)\s+RENAME TO\s+([a-z_][a-z0-9_]*))|(?:DROP TABLE (?:IF EXISTS )?([a-z_][a-z0-9_]*))/gi)) {
186
- const [, renTable, renFrom, renTo, fromTable, toTable, dropped] = m;
187
- if (dropped) {
188
- tables.delete(dropped);
189
- }
190
- else if (renTable && renFrom && renTo) {
191
- const key = tables.get(renTable);
192
- if (key)
193
- tables.set(renTable, key.map((c) => (c === renFrom ? renTo : c)));
194
- }
195
- else if (fromTable && toTable) {
196
- const key = tables.get(fromTable);
197
- if (key) {
198
- tables.delete(fromTable);
199
- tables.set(toTable, key);
200
- }
201
- }
202
- }
203
- return tables;
80
+ const out = new Map();
81
+ for (const [table, schema] of readSchema(sql))
82
+ out.set(table, [...schema.primaryKey]);
83
+ return out;
204
84
  }
205
85
  //# sourceMappingURL=journal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"journal.js","sourceRoot":"","sources":["../src/journal.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,cAAc,CAAC,GA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CAAC;QAAE,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IACvF,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,MAAM,GAAG,GAAG,IAAI,GAAG,EAAoB,CAAC;IACxC,KAAK,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC;QAAE,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;IACtF,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The journal's statements, split on the semicolons that actually end one.
3
+ *
4
+ * Quote- and comment-aware, because a `;` inside a string literal or a `--`
5
+ * comment ends nothing. This is the only text scanning left in the package, and
6
+ * it exists because the statements have to be filtered before they are run —
7
+ * `db.exec` would happily run the `INSERT`s too.
8
+ */
9
+ export declare function statements(sql: string): string[];
10
+ export interface TableSchema {
11
+ /** Declaration order, as `PRAGMA table_info` reports it. */
12
+ readonly columns: string[];
13
+ /** Key order, not declaration order — `(a, b)` and `(b, a)` are different keys. Empty when the table has none. */
14
+ readonly primaryKey: string[];
15
+ /** Each constraint normalised to `a, b`. Excludes the primary key and any PARTIAL index. */
16
+ readonly uniques: string[];
17
+ }
18
+ /**
19
+ * The schema a journal leaves behind, as SQLite sees it.
20
+ *
21
+ * Throws if a schema statement does not apply — which is a feature, not a
22
+ * regression. A journal that cannot be replayed is a journal that will not apply
23
+ * to a real scope either, and the old readers answered anyway.
24
+ */
25
+ export declare function readSchema(sql: string): Map<string, TableSchema>;
26
+ //# sourceMappingURL=replay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../src/replay.ts"],"names":[],"mappings":"AAmDA;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CA4BhD;AAMD,MAAM,WAAW,WAAW;IAC1B,4DAA4D;IAC5D,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAC3B,kHAAkH;IAClH,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC;IAC9B,4FAA4F;IAC5F,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;CAC5B;AAYD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CA2DhE"}