@zukhruf/schema-drift 0.0.0-stage → 0.8.282

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.
@@ -0,0 +1,18 @@
1
+ /** How a database stores the objects of a declaration: none of them, each one as declared, or anything else. */
2
+ export type Drift = 'missing' | 'stale' | 'fits';
3
+ /** What apply does with the rows of a stale table. It has no default. */
4
+ export type Rows = 'replace' | 'keep';
5
+ export type ObjectKind = 'table' | 'virtual table' | 'trigger' | 'index' | 'view' | 'sequence' | 'function' | 'procedure' | 'schema';
6
+ /** One declared object that does not fit. */
7
+ export type DriftedObject = {
8
+ /** Qualified on Postgres and SQL Server: '_warehouse.extraction_coverage'. An index on SQL Server: 'dbo.runs.runs_by_name'. */
9
+ readonly name: string;
10
+ readonly kind: ObjectKind;
11
+ readonly drift: 'missing' | 'stale';
12
+ };
13
+ export type DriftReport = {
14
+ readonly drift: Drift;
15
+ /** Each missing or stale object, in the order of the declaration. Empty when drift is 'fits'. */
16
+ readonly objects: readonly DriftedObject[];
17
+ };
18
+ //# sourceMappingURL=drift.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drift.d.ts","sourceRoot":"","sources":["../src/drift.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,MAAM,MAAM,KAAK,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AAEjD,yEAAyE;AACzE,MAAM,MAAM,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC;AAEtC,MAAM,MAAM,UAAU,GAClB,OAAO,GACP,eAAe,GACf,SAAS,GACT,OAAO,GACP,MAAM,GACN,UAAU,GACV,UAAU,GACV,WAAW,GACX,QAAQ,CAAC;AAEb,6CAA6C;AAC7C,MAAM,MAAM,aAAa,GAAG;IAC1B,+HAA+H;IAC/H,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,iGAAiG;IACjG,QAAQ,CAAC,OAAO,EAAE,SAAS,aAAa,EAAE,CAAC;CAC5C,CAAC"}
package/dist/drift.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=drift.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drift.js","sourceRoot":"","sources":["../src/drift.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export type { Drift, DriftedObject, DriftReport, ObjectKind, Rows, } from './drift.ts';
2
+ export { SchemaDriftError } from './schema-drift-error.ts';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,KAAK,EACL,aAAa,EACb,WAAW,EACX,UAAU,EACV,IAAI,GACL,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { SchemaDriftError } from './schema-drift-error.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { DriftedObject } from './drift.ts';
2
+ /**
3
+ * check found an object that is missing or stale (ADR 0016). The next step:
4
+ * apply the declaration.
5
+ */
6
+ export declare class SchemaDriftError extends Error {
7
+ readonly name = "SchemaDriftError";
8
+ readonly objects: readonly DriftedObject[];
9
+ constructor(objects: readonly DriftedObject[]);
10
+ }
11
+ //# sourceMappingURL=schema-drift-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-drift-error.d.ts","sourceRoot":"","sources":["../src/schema-drift-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,SAAkB,IAAI,sBAAsB;IAC5C,QAAQ,CAAC,OAAO,EAAE,SAAS,aAAa,EAAE,CAAC;IAE3C,YAAY,OAAO,EAAE,SAAS,aAAa,EAAE,EAW5C;CACF"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * check found an object that is missing or stale (ADR 0016). The next step:
3
+ * apply the declaration.
4
+ */
5
+ export class SchemaDriftError extends Error {
6
+ name = 'SchemaDriftError';
7
+ objects;
8
+ constructor(objects) {
9
+ super([
10
+ 'The database does not store the declaration as declared:',
11
+ ...objects.map(({ name, kind, drift }) => ` ${name} (${kind}) is ${drift}.`),
12
+ 'Apply the declaration.',
13
+ ].join('\n'));
14
+ this.objects = objects;
15
+ }
16
+ }
17
+ //# sourceMappingURL=schema-drift-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-drift-error.js","sourceRoot":"","sources":["../src/schema-drift-error.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACvB,IAAI,GAAG,kBAAkB,CAAC;IACnC,OAAO,CAA2B;IAE3C,YAAY,OAAiC;QAC3C,KAAK,CACH;YACE,0DAA0D;YAC1D,GAAG,OAAO,CAAC,GAAG,CACZ,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,IAAI,KAAK,IAAI,QAAQ,KAAK,GAAG,CAC9D;YACD,wBAAwB;SACzB,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;QACF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ import type { DatabaseSync } from 'node:sqlite';
2
+ import type { DriftReport, Rows } from '../drift.ts';
3
+ export declare class SqliteDeclaration {
4
+ #private;
5
+ constructor(statements: readonly string[], options?: {
6
+ readonly devDatabase?: () => DatabaseSync;
7
+ });
8
+ drift(database: DatabaseSync): DriftReport;
9
+ check(database: DatabaseSync): void;
10
+ apply(database: DatabaseSync, options: {
11
+ readonly rows: Rows;
12
+ }): void;
13
+ }
14
+ //# sourceMappingURL=sqlite-declaration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-declaration.d.ts","sourceRoot":"","sources":["../../src/sqlite/sqlite-declaration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAKhD,OAAO,KAAK,EAAE,WAAW,EAA6B,IAAI,EAAE,MAAM,aAAa,CAAC;AAqBhF,qBAAa,iBAAiB;;IAO5B,YACE,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,YAAY,CAAA;KAAE,EAKxD;IAID,KAAK,CAAC,QAAQ,EAAE,YAAY,GAAG,WAAW,CAazC;IAGD,KAAK,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAGlC;IAUD,KAAK,CAAC,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;KAAE,GAAG,IAAI,CAoDpE;CA0HF"}
@@ -0,0 +1,407 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { open } from '@zukhruf/sqlite-open';
3
+ import { transaction } from '@zukhruf/sqlite-transaction';
4
+ import { SchemaDriftError } from '../schema-drift-error.js';
5
+ // The tables, indexes, views and triggers a caller owns in a SQLite database,
6
+ // by the CREATE statements that make them, one statement for each object.
7
+ // SQLite keeps the text of each CREATE in sqlite_schema. A declaration makes
8
+ // its objects once in the dev database, so the declared text and
9
+ // the stored text both come from SQLite, and they compare by their tokens. The
10
+ // other rows that a statement adds to sqlite_schema (shadow tables,
11
+ // sqlite_sequence) are owned objects: SQLite makes and drops them with the
12
+ // declared object (ADR 0004).
13
+ export class SqliteDeclaration {
14
+ #objects;
15
+ // devDatabase opens the empty database in memory. SQLite keeps modules,
16
+ // functions and collations on the connection, so the connection that makes
17
+ // the objects must have those that the statements use (ADR 0005). The
18
+ // declaration closes it.
19
+ constructor(statements, options) {
20
+ using blank = (options?.devDatabase ?? (() => open(':memory:')))();
21
+ empty(blank);
22
+ this.#objects = statements.map((statement) => declare(blank, statement));
23
+ }
24
+ // The drift of the declaration, and each declared object that the database
25
+ // does not store as declared, in the order of the declaration (ADR 0008).
26
+ drift(database) {
27
+ const objects = this.#objects.flatMap((object) => {
28
+ const found = stored(database, object.name);
29
+ if (found === undefined)
30
+ return [{ name: object.name, kind: kind(object), drift: 'missing' }];
31
+ if (same(object, found))
32
+ return [];
33
+ return [{ name: object.name, kind: kind(object), drift: 'stale' }];
34
+ });
35
+ if (objects.length === 0)
36
+ return { drift: 'fits', objects };
37
+ const none = objects.length === this.#objects.length &&
38
+ objects.every(({ drift }) => drift === 'missing');
39
+ return { drift: none ? 'missing' : 'stale', objects };
40
+ }
41
+ // A package calls check when it opens, and runs no DDL (ADR 0007).
42
+ check(database) {
43
+ const { drift, objects } = this.drift(database);
44
+ if (drift !== 'fits')
45
+ throw new SchemaDriftError(objects);
46
+ }
47
+ // Creates the objects the database does not store. When any stored object
48
+ // differs from its declaration, rows 'replace' replaces every object of the
49
+ // declaration, with its rows: a table can refer to another, and SQLite drops
50
+ // a table only after nothing refers to its rows. Rows 'keep' makes each stale
51
+ // object again, and moves the rows of a stale table into the new one (ADR
52
+ // 0003). Works inside the caller's transaction, or in a write of its own.
53
+ // Objects the declaration does not name stay. The host gives rows each time
54
+ // it applies, because it knows whether its rows can be made again (ADR 0007).
55
+ apply(database, options) {
56
+ const { rows } = options;
57
+ if (rows !== 'replace' && rows !== 'keep')
58
+ throw new TypeError(`apply needs rows: 'replace' or 'keep'. It has no default. It got ${String(rows)}.`);
59
+ if (this.drift(database).drift === 'fits')
60
+ return;
61
+ if (rows === 'keep')
62
+ for (const { object, found } of this.#stale(database))
63
+ if (virtual(object) || virtual(found))
64
+ throw new Error(`The virtual table ${object.name} cannot keep its rows: declare it in its own declaration, and apply that one with rows: 'replace'.`);
65
+ // SQLite ignores PRAGMA foreign_keys in a transaction. With foreign keys
66
+ // on, the rename of a referenced table changes the references to the old
67
+ // table, and its drop then deletes the rows that refer to it.
68
+ const unchecked = rows === 'keep' && this.#keepNeedsForeignKeysOff(database);
69
+ if (unchecked) {
70
+ if (database.isTransaction)
71
+ throw new Error('Keeping the rows of a table that other tables reference needs foreign keys off, which SQLite cannot change inside a transaction. Call apply outside a transaction, or turn foreign keys off before it.');
72
+ database.exec('PRAGMA foreign_keys = OFF');
73
+ }
74
+ try {
75
+ transaction(database, () => {
76
+ const stale = this.#stale(database);
77
+ const triggered = writable(database);
78
+ if (rows === 'keep') {
79
+ const views = compiled(database);
80
+ const rebuilt = this.#keep(database, stale);
81
+ this.#create(database);
82
+ verify(database, rebuilt, views);
83
+ }
84
+ else {
85
+ if (stale.length > 0)
86
+ for (const object of this.#objects.toReversed()) {
87
+ const found = stored(database, object.name);
88
+ if (found !== undefined)
89
+ drop(database, found);
90
+ }
91
+ this.#create(database);
92
+ }
93
+ for (const table of triggers(database))
94
+ if (triggered.has(table))
95
+ write(database, table);
96
+ }, { mode: 'immediate' });
97
+ }
98
+ finally {
99
+ if (unchecked)
100
+ database.exec('PRAGMA foreign_keys = ON');
101
+ }
102
+ }
103
+ #keepNeedsForeignKeysOff(database) {
104
+ const foreignKeysOn = Number(database.prepare('PRAGMA foreign_keys').get()?.foreign_keys) === 1;
105
+ return (foreignKeysOn &&
106
+ this.#stale(database).some(({ object, found }) => object.type === 'table' &&
107
+ found.type === 'table' &&
108
+ referenced(database, found.name)));
109
+ }
110
+ #create(database) {
111
+ for (const object of this.#objects)
112
+ if (stored(database, object.name) === undefined)
113
+ database.exec(object.sql);
114
+ }
115
+ #stale(database) {
116
+ return this.#objects.flatMap((object) => {
117
+ const found = stored(database, object.name);
118
+ return found !== undefined && !same(object, found)
119
+ ? [{ object, found }]
120
+ : [];
121
+ });
122
+ }
123
+ // Drops each stale index, trigger and view, rebuilds each stale table, and
124
+ // gives the names of the rebuilt tables. SQLite keeps PRAGMA
125
+ // legacy_alter_table after a rollback, so the old value comes back in any
126
+ // case.
127
+ #keep(database, stale) {
128
+ const tables = stale.filter(({ object, found }) => object.type === 'table' && found.type === 'table');
129
+ for (const entry of stale)
130
+ if (!tables.includes(entry))
131
+ drop(database, entry.found);
132
+ if (tables.length === 0)
133
+ return [];
134
+ const legacy = Number(database.prepare('PRAGMA legacy_alter_table').get()?.legacy_alter_table);
135
+ database.exec('PRAGMA legacy_alter_table = ON');
136
+ try {
137
+ for (const { object, found } of tables)
138
+ this.#rebuild(database, object, found);
139
+ }
140
+ finally {
141
+ database.exec(`PRAGMA legacy_alter_table = ${legacy}`);
142
+ }
143
+ const broken = database.prepare('PRAGMA foreign_key_check').get();
144
+ if (broken !== undefined)
145
+ throw new Error(`The kept rows break a foreign key: row ${String(broken.rowid)} of ${String(broken.table)} refers to a row of ${String(broken.parent)} that does not exist.`);
146
+ return tables.map(({ object }) => object.name);
147
+ }
148
+ // Renames the stored table away, makes it from its declared text, and copies
149
+ // the columns that both have, by name. With legacy_alter_table on, the
150
+ // rename leaves the references of other tables, views and triggers to the
151
+ // name. A column only the declaration has gets its default, and a column
152
+ // only the stored table has is discarded. The indexes and triggers on the
153
+ // table go with the old table, so those the declaration does not name are
154
+ // made again here, and the others when apply makes the missing objects.
155
+ #rebuild(database, object, found) {
156
+ const declared = new Set(this.#objects.map(({ name }) => name.toLowerCase()));
157
+ const undeclared = database
158
+ .prepare(`SELECT "name", "sql" FROM sqlite_schema WHERE lower("tbl_name") = lower(?) AND "type" IN ('index', 'trigger') AND "sql" IS NOT NULL`)
159
+ .all(found.name)
160
+ .filter(({ name }) => !declared.has(String(name).toLowerCase()))
161
+ .map(({ sql }) => String(sql));
162
+ const old = `${found.name}_${randomUUID().replaceAll('-', '')}`;
163
+ database.exec(`ALTER TABLE ${quote(found.name)} RENAME TO ${quote(old)}`);
164
+ // The sqlite_sequence row of the table follows the rename.
165
+ const counter = sequence(database, old);
166
+ database.exec(object.sql);
167
+ const columns = new Set(names(database, object.name).map((name) => name.toLowerCase()));
168
+ const shared = names(database, old)
169
+ .filter((name) => columns.has(name.toLowerCase()))
170
+ .map(quote);
171
+ const into = [...shared];
172
+ const from = [...shared];
173
+ // pragma_table_info does not list the rowid, so a copy of the columns
174
+ // gives new rowids. The rowid goes first: when the list also has the
175
+ // INTEGER PRIMARY KEY of the new table, SQLite takes the later value.
176
+ const target = rowid(database, object.name);
177
+ const source = rowid(database, old);
178
+ if (target !== undefined && source !== undefined) {
179
+ into.unshift(target);
180
+ from.unshift(source);
181
+ }
182
+ if (into.length > 0)
183
+ database.exec(`INSERT INTO ${quote(object.name)} (${into.join(', ')}) SELECT ${from.join(', ')} FROM ${quote(old)}`);
184
+ // AUTOINCREMENT gives no id that the table gave before, also when its row
185
+ // is gone. sqlite_sequence keeps the largest such id. The copy gives no
186
+ // id larger than the old counter.
187
+ if (counter !== undefined && /\bAUTOINCREMENT\b/i.test(object.sql)) {
188
+ database
189
+ .prepare('DELETE FROM sqlite_sequence WHERE "name" = ?')
190
+ .run(object.name);
191
+ database
192
+ .prepare('INSERT INTO sqlite_sequence ("name", "seq") VALUES (?, ?)')
193
+ .run(object.name, counter);
194
+ }
195
+ database.exec(`DROP TABLE ${quote(old)}`);
196
+ for (const sql of undeclared)
197
+ database.exec(sql);
198
+ }
199
+ }
200
+ // A declared object is the first row that a statement adds, so an object
201
+ // that is already in the dev database cannot be part of the declaration.
202
+ // Atlas also refuses a dev database that is not clean.
203
+ function empty(blank) {
204
+ const object = blank.prepare('SELECT "name" FROM sqlite_schema').get();
205
+ if (object !== undefined)
206
+ throw new Error(`The dev database must be empty. It holds ${String(object.name)}.`);
207
+ }
208
+ // Runs one element of a declaration in the blank database, and gives the
209
+ // object that the element declares: the first row that it adds to
210
+ // sqlite_schema. The other rows that it adds (the shadow tables of a virtual
211
+ // table, sqlite_sequence, the index of a UNIQUE column) belong to that object:
212
+ // SQLite makes and drops them with it (ADR 0004).
213
+ function declare(blank, element) {
214
+ const last = Number(blank
215
+ .prepare('SELECT coalesce(max(rowid), 0) AS "last" FROM sqlite_schema')
216
+ .get()?.last);
217
+ // prepare compiles the first statement of the text and ignores the rest.
218
+ const statement = blank.prepare(element);
219
+ statement.run();
220
+ if (holds(blank, element.slice(statement.sourceSQL.length)))
221
+ throw new Error(`An element of a declaration holds one statement. This element holds more: ${element}`);
222
+ const made = blank
223
+ .prepare('SELECT "type", "name", "sql" FROM sqlite_schema WHERE rowid > ? ORDER BY rowid')
224
+ .get(last);
225
+ if (made === undefined)
226
+ throw new Error(`An element of a declaration makes one object. This element makes none: ${element}`);
227
+ return {
228
+ type: String(made.type),
229
+ name: String(made.name),
230
+ sql: String(made.sql),
231
+ };
232
+ }
233
+ // Whether the text holds a statement. SQLite compiles no statement from a
234
+ // text of spaces, comments and semicolons, and prepare then throws
235
+ // ERR_INVALID_ARG_VALUE. Any other failure means that the text holds a
236
+ // statement that does not compile.
237
+ function holds(database, text) {
238
+ try {
239
+ database.prepare(text);
240
+ return true;
241
+ }
242
+ catch (error) {
243
+ return !(Error.isError(error) &&
244
+ 'code' in error &&
245
+ error.code === 'ERR_INVALID_ARG_VALUE');
246
+ }
247
+ }
248
+ // Whether two objects have the same tokens. A comment or a change of the
249
+ // spaces between tokens does not change the object, so it does not rebuild a
250
+ // table (Röthlisberger and Manley compare tables by normalise_sql too).
251
+ function same(object, found) {
252
+ return tokens(object.sql) === tokens(found.sql);
253
+ }
254
+ // The text without its comments, with one space between two tokens, and none
255
+ // next to ( ) , or ;. A string or a quoted name stays as it is, by the rules
256
+ // of the tokenizer of SQLite (tokenize.c). The text that sqlite_schema keeps
257
+ // ends at the last token of the statement, so no comment, string or name in it
258
+ // runs to the end of the text without its end.
259
+ function tokens(sql) {
260
+ const tight = new Set(['(', ')', ',', ';']);
261
+ let text = '';
262
+ let previous = '';
263
+ let gap = false;
264
+ for (const [token] of sql.matchAll(/[ \t\n\f\r]+|--[^\n]*|\/\*[^]*?\*\/|'(?:[^']|'')*'|"(?:[^"]|"")*"|`(?:[^`]|``)*`|\[[^\]]*\]|[^]/gy)) {
265
+ if (/^(?:[ \t\n\f\r]|--|\/\*)/.test(token)) {
266
+ gap = true;
267
+ continue;
268
+ }
269
+ if (gap && text !== '' && !tight.has(previous) && !tight.has(token))
270
+ text += ' ';
271
+ text += token;
272
+ previous = token;
273
+ gap = false;
274
+ }
275
+ return text;
276
+ }
277
+ function virtual(object) {
278
+ return /^CREATE VIRTUAL TABLE /i.test(object.sql);
279
+ }
280
+ // The type of sqlite_schema, which names a virtual table a table.
281
+ function kind(object) {
282
+ if (virtual(object))
283
+ return 'virtual table';
284
+ switch (object.type) {
285
+ case 'table':
286
+ case 'index':
287
+ case 'view':
288
+ case 'trigger':
289
+ return object.type;
290
+ default:
291
+ throw new Error(`sqlite_schema lists ${object.name} with the type ${object.type}.`);
292
+ }
293
+ }
294
+ // The name that reads the rowid of the table: none for a WITHOUT ROWID table,
295
+ // and none when columns have each of the three names of the rowid.
296
+ function rowid(database, table) {
297
+ const list = database
298
+ .prepare('SELECT "wr" FROM pragma_table_list(?)')
299
+ .get(table);
300
+ if (Number(list?.wr) === 1)
301
+ return undefined;
302
+ const columns = new Set(names(database, table).map((name) => name.toLowerCase()));
303
+ return ['rowid', '_rowid_', 'oid'].find((name) => !columns.has(name));
304
+ }
305
+ // The largest id that an AUTOINCREMENT table gave, as sqlite_sequence keeps it.
306
+ function sequence(database, table) {
307
+ if (stored(database, 'sqlite_sequence') === undefined)
308
+ return undefined;
309
+ const row = database
310
+ .prepare('SELECT "seq" FROM sqlite_sequence WHERE "name" = ?')
311
+ .get(table);
312
+ return row === undefined ? undefined : Number(row.seq);
313
+ }
314
+ // SQLite takes names that differ only in ASCII case for one object.
315
+ function stored(database, name) {
316
+ const row = database
317
+ .prepare('SELECT "type", "name", "sql" FROM sqlite_schema WHERE lower("name") = lower(?)')
318
+ .get(name);
319
+ return row === undefined
320
+ ? undefined
321
+ : { type: String(row.type), name: String(row.name), sql: String(row.sql) };
322
+ }
323
+ function quote(name) {
324
+ return `"${name.replaceAll('"', '""')}"`;
325
+ }
326
+ function drop(database, object) {
327
+ database.exec(`DROP ${object.type.toUpperCase()} ${quote(object.name)}`);
328
+ }
329
+ function names(database, table) {
330
+ return database
331
+ .prepare('SELECT "name" FROM pragma_table_info(?)')
332
+ .all(table)
333
+ .map(({ name }) => String(name));
334
+ }
335
+ // The names of the views that SQLite can compile now.
336
+ function compiled(database) {
337
+ return new Set(database
338
+ .prepare(`SELECT "name" FROM sqlite_schema WHERE "type" = 'view'`)
339
+ .all()
340
+ .map(({ name }) => String(name))
341
+ .filter((name) => {
342
+ try {
343
+ database.prepare(`SELECT * FROM ${quote(name)} WHERE 0`);
344
+ return true;
345
+ }
346
+ catch {
347
+ // The view was broken before apply.
348
+ return false;
349
+ }
350
+ }));
351
+ }
352
+ // SQLite checks the columns of a trigger or a view only when it compiles a
353
+ // statement that uses it, not at CREATE. Each statement here compiles every
354
+ // trigger on the table for its event, and runs no row: an UPDATE trigger OF a
355
+ // column compiles only when SET names that column.
356
+ function write(database, table) {
357
+ const columns = names(database, table).map(quote);
358
+ const name = quote(table);
359
+ database.prepare(`DELETE FROM ${name} WHERE 0`);
360
+ database.prepare(`INSERT INTO ${name} (${columns.join(', ')}) SELECT ${columns.join(', ')} FROM ${name} WHERE 0`);
361
+ database.prepare(`UPDATE ${name} SET ${columns.map((column) => `${column} = ${column}`).join(', ')} WHERE 0`);
362
+ }
363
+ // The tables that have triggers.
364
+ function triggers(database) {
365
+ return new Set(database
366
+ .prepare(`SELECT DISTINCT "tbl_name" FROM sqlite_schema WHERE "type" = 'trigger'`)
367
+ .all()
368
+ .map(({ tbl_name }) => String(tbl_name)));
369
+ }
370
+ // The tables with triggers whose writes SQLite can compile now. A trigger can
371
+ // read any table, so a change to one table can break the trigger of another.
372
+ // A table here whose writes do not compile after the change fails apply; a
373
+ // table whose trigger was broken before apply does not.
374
+ function writable(database) {
375
+ return new Set([...triggers(database)].filter((table) => {
376
+ try {
377
+ write(database, table);
378
+ return true;
379
+ }
380
+ catch {
381
+ return false;
382
+ }
383
+ }));
384
+ }
385
+ // Each rebuilt table must compile its writes. A view that compiled before the
386
+ // rebuilds and does not compile now fails apply; a view that was already
387
+ // broken does not.
388
+ function verify(database, tables, views) {
389
+ for (const table of tables)
390
+ write(database, table);
391
+ for (const view of views)
392
+ try {
393
+ database.prepare(`SELECT * FROM ${quote(view)} WHERE 0`);
394
+ }
395
+ catch (error) {
396
+ throw new Error(`The rebuild breaks the view ${view}.`, {
397
+ cause: error,
398
+ });
399
+ }
400
+ }
401
+ // Whether a table, the same one too, has a foreign key to the table.
402
+ function referenced(database, table) {
403
+ return (database
404
+ .prepare(`SELECT 1 FROM sqlite_schema AS "s", pragma_foreign_key_list("s"."name") AS "f" WHERE "s"."type" = 'table' AND lower("f"."table") = lower(?)`)
405
+ .get(table) !== undefined);
406
+ }
407
+ //# sourceMappingURL=sqlite-declaration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-declaration.js","sourceRoot":"","sources":["../../src/sqlite/sqlite-declaration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAG1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAY5D,8EAA8E;AAC9E,0EAA0E;AAC1E,6EAA6E;AAC7E,iEAAiE;AACjE,+EAA+E;AAC/E,oEAAoE;AACpE,2EAA2E;AAC3E,8BA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QAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACnD,KAAK,MAAM,IAAI,IAAI,KAAK;QACtB,IAAI,CAAC;YACH,QAAQ,CAAC,OAAO,CAAC,iBAAiB,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC3D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,+BAA+B,IAAI,GAAG,EAAE;gBACtD,KAAK,EAAE,KAAK;aACb,CAAC,CAAC;QACL,CAAC;AACL,CAAC;AAED,qEAAqE;AACrE,SAAS,UAAU,CAAC,QAAsB,EAAE,KAAa;IACvD,OAAO,CACL,QAAQ;SACL,OAAO,CACN,6IAA6I,CAC9I;SACA,GAAG,CAAC,KAAK,CAAC,KAAK,SAAS,CAC5B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { SqliteDeclaration } from './sqlite/sqlite-declaration.ts';
2
+ //# sourceMappingURL=sqlite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../src/sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC"}
package/dist/sqlite.js ADDED
@@ -0,0 +1,2 @@
1
+ export { SqliteDeclaration } from './sqlite/sqlite-declaration.js';
2
+ //# sourceMappingURL=sqlite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../src/sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,60 @@
1
1
  {
2
2
  "name": "@zukhruf/schema-drift",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.8.282",
4
+ "description": "Declarative schema management for SQLite, Postgres and SQL Server: a package exports the CREATE statements of its objects, the host applies them, and the package checks and throws SchemaDriftError for each missing or stale object.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/JanuaryLabs/zukhruf",
9
+ "directory": "packages/schema-drift"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/JanuaryLabs/zukhruf/issues"
13
+ },
14
+ "homepage": "https://github.com/JanuaryLabs/zukhruf/tree/main/packages/schema-drift#readme",
15
+ "keywords": [
16
+ "schema-drift",
17
+ "declarative-schema",
18
+ "schema",
19
+ "migration",
20
+ "ddl",
21
+ "sqlite",
22
+ "node-sqlite",
23
+ "postgres",
24
+ "sql-server"
25
+ ],
26
+ "type": "module",
27
+ "exports": {
28
+ "./package.json": "./package.json",
29
+ ".": {
30
+ "@zukhruf/source": "./src/index.ts",
31
+ "types": "./dist/index.d.ts",
32
+ "import": "./dist/index.js",
33
+ "default": "./dist/index.js"
34
+ },
35
+ "./sqlite": {
36
+ "@zukhruf/source": "./src/sqlite.ts",
37
+ "types": "./dist/sqlite.d.ts",
38
+ "import": "./dist/sqlite.js",
39
+ "default": "./dist/sqlite.js"
40
+ }
41
+ },
42
+ "files": [
43
+ "dist",
44
+ "!dist/spec/**",
45
+ "!**/*.tsbuildinfo",
46
+ "!**/*.test.*"
47
+ ],
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "dependencies": {
52
+ "@zukhruf/sqlite-open": "^0.8.282",
53
+ "@zukhruf/sqlite-transaction": "^0.8.282"
54
+ },
55
+ "devDependencies": {
56
+ "@zukhruf/fs": "^0.8.282",
57
+ "@zukhruf/parameterized-test": "^0.8.282",
58
+ "@zukhruf/testing": "^0.8.282"
59
+ }
60
+ }