@zukhruf/schema-drift 0.8.284 → 0.8.286
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.
- package/README.md +133 -4
- package/dist/postgres/postgres-statement.js +1 -1
- package/dist/postgres/postgres-statement.js.map +1 -1
- package/dist/sqlserver/sqlserver-declaration.d.ts +41 -0
- package/dist/sqlserver/sqlserver-declaration.d.ts.map +1 -0
- package/dist/sqlserver/sqlserver-declaration.js +545 -0
- package/dist/sqlserver/sqlserver-declaration.js.map +1 -0
- package/dist/sqlserver/sqlserver-statement.d.ts +29 -0
- package/dist/sqlserver/sqlserver-statement.d.ts.map +1 -0
- package/dist/sqlserver/sqlserver-statement.js +246 -0
- package/dist/sqlserver/sqlserver-statement.js.map +1 -0
- package/dist/sqlserver.d.ts +2 -0
- package/dist/sqlserver.d.ts.map +1 -0
- package/dist/sqlserver.js +2 -0
- package/dist/sqlserver.js.map +1 -0
- package/package.json +12 -6
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @zukhruf/schema-drift
|
|
2
2
|
|
|
3
|
-
> **Design accepted 2026-12-01.** The root entry point, `./sqlite
|
|
3
|
+
> **Design accepted 2026-12-01.** The root entry point, `./sqlite`, `./postgres` and `./sqlserver` are built (backlog #2625).
|
|
4
4
|
|
|
5
5
|
A package keeps tables, indexes, views and other objects in a database. A later version of the package can declare them otherwise, for example with one more column. The database still stores the objects as the earlier version made them, and the new code fails on them, for example with `column "reloading" does not exist` (elt #2625). This package compares the objects of a database with their **declaration**, and makes the database store them as declared. No person keeps a version number. The industry calls this declarative schema management, and the difference that it finds schema drift (Atlas, Liquibase).
|
|
6
6
|
|
|
@@ -251,6 +251,131 @@ Apply the declaration.
|
|
|
251
251
|
[ { stream: 'orders', target_schema: 'raw', reloading: false } ]
|
|
252
252
|
```
|
|
253
253
|
|
|
254
|
+
## Work on SQL Server
|
|
255
|
+
|
|
256
|
+
`@zukhruf/schema-drift/sqlserver` imports no driver. The host gives a `SqlServerSession` over its own driver. The example writes one over mssql, makes the table as an older elt did, and repairs it.
|
|
257
|
+
|
|
258
|
+
```ts
|
|
259
|
+
import mssql from 'mssql';
|
|
260
|
+
|
|
261
|
+
import {
|
|
262
|
+
SqlServerDeclaration,
|
|
263
|
+
type SqlServerSession,
|
|
264
|
+
} from '@zukhruf/schema-drift/sqlserver';
|
|
265
|
+
|
|
266
|
+
const pool = await new mssql.ConnectionPool(
|
|
267
|
+
process.env.DATABASE_URL ?? '',
|
|
268
|
+
).connect();
|
|
269
|
+
const bind = (
|
|
270
|
+
request: mssql.Request,
|
|
271
|
+
parameters: Readonly<Record<string, unknown>>,
|
|
272
|
+
) => {
|
|
273
|
+
for (const [name, value] of Object.entries(parameters))
|
|
274
|
+
request.input(name, value);
|
|
275
|
+
return request;
|
|
276
|
+
};
|
|
277
|
+
// The session over mssql: queries on the pool, and a transaction of the pool.
|
|
278
|
+
// apply runs with XACT_ABORT on, so an error rolls the transaction back in
|
|
279
|
+
// the server, and mssql then refuses a second rollback.
|
|
280
|
+
const session: SqlServerSession = {
|
|
281
|
+
query: async (sql, parameters) =>
|
|
282
|
+
(await bind(pool.request(), parameters).query(sql)).recordset ?? [],
|
|
283
|
+
transaction: async (work) => {
|
|
284
|
+
const transaction = new mssql.Transaction(pool);
|
|
285
|
+
let aborted = false;
|
|
286
|
+
transaction.on('rollback', (byServer: boolean) => {
|
|
287
|
+
aborted = byServer;
|
|
288
|
+
});
|
|
289
|
+
await transaction.begin();
|
|
290
|
+
try {
|
|
291
|
+
const inner: SqlServerSession = {
|
|
292
|
+
query: async (sql, parameters) =>
|
|
293
|
+
(await bind(transaction.request(), parameters).query(sql))
|
|
294
|
+
.recordset ?? [],
|
|
295
|
+
transaction: async (nested) => nested(inner),
|
|
296
|
+
};
|
|
297
|
+
await work(inner);
|
|
298
|
+
await transaction.commit();
|
|
299
|
+
} catch (error) {
|
|
300
|
+
if (!aborted) await transaction.rollback();
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
// An older elt made the table behind a guard, without reloading.
|
|
306
|
+
await pool.query('CREATE SCHEMA _warehouse');
|
|
307
|
+
await pool.query(`IF OBJECT_ID(N'_warehouse.extraction_coverage', N'U') IS NULL
|
|
308
|
+
CREATE TABLE _warehouse.extraction_coverage (stream nvarchar(200) PRIMARY KEY, target_schema nvarchar(200) NOT NULL);
|
|
309
|
+
INSERT INTO _warehouse.extraction_coverage VALUES (N'orders', N'raw')`);
|
|
310
|
+
|
|
311
|
+
const warehouse = new SqlServerDeclaration(
|
|
312
|
+
[
|
|
313
|
+
'CREATE SCHEMA _warehouse',
|
|
314
|
+
`CREATE TABLE _warehouse.extraction_coverage (
|
|
315
|
+
stream nvarchar(200) PRIMARY KEY,
|
|
316
|
+
target_schema nvarchar(200) NOT NULL,
|
|
317
|
+
reloading bit NOT NULL DEFAULT 0
|
|
318
|
+
)`,
|
|
319
|
+
'CREATE INDEX extraction_coverage_target ON _warehouse.extraction_coverage (target_schema)',
|
|
320
|
+
],
|
|
321
|
+
{ ledgerSchema: '_warehouse' },
|
|
322
|
+
);
|
|
323
|
+
console.log(await warehouse.drift(session));
|
|
324
|
+
try {
|
|
325
|
+
await warehouse.check(session);
|
|
326
|
+
} catch (error) {
|
|
327
|
+
console.log(String(error));
|
|
328
|
+
}
|
|
329
|
+
await warehouse.apply(session, { rows: 'keep' });
|
|
330
|
+
console.log(await warehouse.drift(session));
|
|
331
|
+
console.log(
|
|
332
|
+
(await pool.query('SELECT * FROM _warehouse.extraction_coverage')).recordset,
|
|
333
|
+
);
|
|
334
|
+
await pool.close();
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
Output:
|
|
338
|
+
|
|
339
|
+
```
|
|
340
|
+
{
|
|
341
|
+
drift: 'stale',
|
|
342
|
+
objects: [
|
|
343
|
+
{
|
|
344
|
+
name: '_warehouse.extraction_coverage',
|
|
345
|
+
kind: 'table',
|
|
346
|
+
drift: 'stale'
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
name: '_warehouse.extraction_coverage.extraction_coverage_target',
|
|
350
|
+
kind: 'index',
|
|
351
|
+
drift: 'missing'
|
|
352
|
+
}
|
|
353
|
+
]
|
|
354
|
+
}
|
|
355
|
+
SchemaDriftError: The database does not store the declaration as declared:
|
|
356
|
+
_warehouse.extraction_coverage (table) is stale.
|
|
357
|
+
_warehouse.extraction_coverage.extraction_coverage_target (index) is missing.
|
|
358
|
+
Apply the declaration.
|
|
359
|
+
{ drift: 'fits', objects: [] }
|
|
360
|
+
[ { stream: 'orders', target_schema: 'raw', reloading: false } ]
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
- The qualified name of an index has its table: `_warehouse.extraction_coverage.extraction_coverage_target`. SQL Server keeps an index name unique only in its table.
|
|
364
|
+
- The catalog compares names by the collation of the database, as SQL Server does.
|
|
365
|
+
- `apply` runs each declared statement through `sp_executesql`, so `CREATE VIEW`, `CREATE FUNCTION`, `CREATE PROCEDURE` and `CREATE SCHEMA` each run as the only statement of their batch. The body of a function or a procedure can hold statements of its own, with `;` between them. Each other kind is one statement.
|
|
366
|
+
- The constructor refuses a `GO` on its own line, as two statements, and a statement that starts with `IF`, such as `IF OBJECT_ID(…) IS NULL CREATE TABLE …`, as `IF NOT EXISTS`: the guard hides a stale object behind its name.
|
|
367
|
+
- `apply` starts each batch of its transaction with `SET XACT_ABORT ON`. A `SET` inside `sp_executesql` ends with it, and drivers such as mssql send each query with parameters through `sp_executesql`. Thus an error rolls the whole transaction back in the server. A session must then not roll back again: mssql refuses a second rollback with `EABORT` and hides the error of the database. The example listens for the `rollback` event of the transaction.
|
|
368
|
+
- Inside the lock, `apply` reads the ledger with `XACT_ABORT` off: under it, error 208 of a missing ledger would end the transaction and its lock.
|
|
369
|
+
|
|
370
|
+
### Keep the rows on SQL Server
|
|
371
|
+
|
|
372
|
+
- `apply` renames the old table away with `sp_rename`, and renames away each of its constraints (primary key, unique, default, check, foreign key), also those that SQL Server named. A constraint name is unique in its schema; an index name is unique only in its table, so the indexes of the old table keep their names.
|
|
373
|
+
- SQL Server refuses to rename or drop a table that a schema-bound view reads (errors 15336, 3729). `apply` drops the schema-bound views that read the table, and makes them again after it: a declared view from its statement, any other view from `sys.sql_modules`, with the `ANSI_NULLS` and `QUOTED_IDENTIFIER` that it was made under. A view that is not schema-bound stays, and `apply` runs `sp_refreshview` on it, so a `SELECT *` view sees the declared columns.
|
|
374
|
+
- It makes again the clustered and nonclustered indexes that the declaration does not name, with `UNIQUE`, `DESC`, `INCLUDE` and the filter, from `sys.indexes` and `sys.index_columns`. Their options (fill factor, compression, partitions) are not made again. A columnstore, XML or spatial index is not made again.
|
|
375
|
+
- It makes again the triggers of the table from `sys.sql_modules`, and the foreign keys of other tables `WITH CHECK`, with their `ON DELETE` and `ON UPDATE`. A trigger or a foreign key that was disabled is disabled again.
|
|
376
|
+
- It copies with `SET IDENTITY_INSERT … ON` when the declared table has an identity column that both tables have. It does not copy a computed column, a `rowversion` column or a column of a temporal period.
|
|
377
|
+
- A stale sequence with `rows: 'keep'` restarts at its `last_used_value` plus the increment of the declared sequence. A sequence that never gave a value starts at the `START WITH` of its statement.
|
|
378
|
+
|
|
254
379
|
## Work on SQLite
|
|
255
380
|
|
|
256
381
|
`@zukhruf/schema-drift/sqlite` is `@zukhruf/sqlite-drift`, moved in with its behaviour. It uses only `node:sqlite`.
|
|
@@ -463,15 +588,15 @@ The key is `(kind, name)`. The table lives in the schema that `ledgerSchema` nam
|
|
|
463
588
|
| `SchemaDriftError` | `check` found an object that is missing or stale. `objects` lists each one with its name, kind and drift. Apply the declaration ([ADR 0016](./docs/adr/0016-the-package-owns-one-error-class-schemadrifterror-and-every-other-error-is-the-error-of-the-database.md)). |
|
|
464
589
|
| `A statement of a declaration must start with CREATE …` | The Postgres or SQL Server constructor cannot read the kind and the name from the head of a statement. |
|
|
465
590
|
| `A declared object needs a schema in its name: …` | The Postgres or SQL Server constructor found a name with no schema. |
|
|
466
|
-
| `A declaration does not use IF NOT EXISTS: …` | A constructor found `IF NOT EXISTS`. On SQLite, the message of sqlite-drift: `An element of a declaration makes one object. …`.
|
|
591
|
+
| `A declaration does not use IF NOT EXISTS: …` | A constructor found `IF NOT EXISTS`. On SQL Server, also a statement that starts with `IF`, such as `IF OBJECT_ID(…) IS NULL CREATE TABLE …`. On SQLite, the message of sqlite-drift: `An element of a declaration makes one object. …`. |
|
|
467
592
|
| `A declared schema has only its name: …` | A `CREATE SCHEMA` has `AUTHORIZATION` or objects in it. |
|
|
468
|
-
| `A statement of a declaration must close each …` | The Postgres constructor found a string, a quoted name, a dollar-quoted body or a comment that does not close.
|
|
593
|
+
| `A statement of a declaration must close each …` | The Postgres or SQL Server constructor found a string, a quoted name, a dollar-quoted body, a `[bracketed]` name or a comment that does not close. |
|
|
469
594
|
| `A declaration names each object once: …` | Two statements make objects of one kind and one qualified name, also two overloads of one function. |
|
|
470
595
|
| `apply needs rows: 'replace' or 'keep'. …` (`TypeError`) | A JavaScript caller gave `apply` no `rows`. TypeScript refuses the call. Nothing changes. |
|
|
471
596
|
| The error of SQLite | `new SqliteDeclaration` fails when a statement does not run in the dev database. |
|
|
472
597
|
| `The dev database must be empty. …` | `new SqliteDeclaration` fails when the dev database has an object. |
|
|
473
598
|
| `no such module: …`, `no such function: …` | `new SqliteDeclaration`, or SQLite `apply` on the target database, when that connection does not have a module or a function that a statement uses. |
|
|
474
|
-
| `An element of a declaration holds one statement. …` | `new SqliteDeclaration` fails when one string holds two statements. The Postgres
|
|
599
|
+
| `An element of a declaration holds one statement. …` | `new SqliteDeclaration` fails when one string holds two statements. The Postgres and SQL Server constructors end the message with `:` and the element; on SQL Server, a `GO` on its own line is a second statement. |
|
|
475
600
|
| `An element of a declaration makes one object. …` | `new SqliteDeclaration` fails when a statement makes no object, for example `CREATE TABLE IF NOT EXISTS` of a declared table, a `TEMP` table, or an `INSERT`. |
|
|
476
601
|
| `The virtual table … cannot keep its rows: …` | SQLite `apply` with `rows: 'keep'`, and a virtual table is stale. Nothing changes. |
|
|
477
602
|
| `database is locked` | SQLite `apply` with no transaction waits for the busy timeout of the connection, then fails. |
|
|
@@ -723,4 +848,8 @@ src/
|
|
|
723
848
|
postgres/postgres-statement.ts the tokens, the checksum and the head of a statement
|
|
724
849
|
postgres/postgres-declaration.ts PostgresDeclaration, PostgresSession
|
|
725
850
|
postgres/postgres-declaration.test.ts the tests, on a real Postgres of @zukhruf/testing/postgres
|
|
851
|
+
sqlserver.ts the ./sqlserver entry point
|
|
852
|
+
sqlserver/sqlserver-statement.ts the tokens, the checksum and the head of a statement
|
|
853
|
+
sqlserver/sqlserver-declaration.ts SqlServerDeclaration, SqlServerSession
|
|
854
|
+
sqlserver/sqlserver-declaration.test.ts the tests, on a real SQL Server of @zukhruf/testing/sqlserver
|
|
726
855
|
```
|
|
@@ -2,7 +2,7 @@ import { createHash } from 'node:crypto';
|
|
|
2
2
|
const OPERATOR = /[+\-*/<>=~!@#%^&|`?]/;
|
|
3
3
|
const WORD_START = /[A-Za-z_\u0080-]/;
|
|
4
4
|
const WORD = /[A-Za-z0-9_$\u0080-]/;
|
|
5
|
-
const NUMBER =
|
|
5
|
+
const NUMBER = /(?:0[xXoObB][0-9a-fA-F_]+|(?:\d[\d_]*(?:\.[\d_]*)?|\.\d[\d_]*)(?:[eE][+-]?\d+)?)/y;
|
|
6
6
|
const DOLLAR_TAG = /\$(?:[A-Za-z_\u0080-][A-Za-z0-9_\u0080-]*)?\$/y;
|
|
7
7
|
// The tokens of a statement by the lexical rules of Postgres (ADR 0010): a
|
|
8
8
|
// string, an escape string, a quoted name and a dollar-quoted body are each one
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-statement.js","sourceRoot":"","sources":["../../src/postgres/postgres-statement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAgCzC,MAAM,QAAQ,GAAG,sBAAsB,CAAC;AACxC,MAA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,EAAE,CAAC;QAC1B,IAAI,EAAE,KAAK,KAAK,CAAC,MAAM;YACrB,MAAM,IAAI,KAAK,CAAC,wCAAwC,SAAS,EAAE,CAAC,CAAC;QACvE,OAAO;YACL,SAAS;YACT,IAAI;YACJ,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE;YAC9B,SAAS,EAAE,IAAI;YACf,QAAQ,EAAE,GAAG;SACd,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACrB,IAAI,IAAI,EAAE,KAAK,cAAc;YAAE,UAAU,EAAE,CAAC;QAC5C,MAAM,IAAI,GAAG,UAAU,EAAE,CAAC;QAC1B,IAAI,GAAG,EAAE;YAAE,UAAU,EAAE,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,UAAU,EAAE,CAAC;QAC9B,IAAI,CAAC,MAAM,CAAC,CAAC;QACb,MAAM,KAAK,GAAG,aAAa,EAAE,CAAC;QAC9B,OAAO;YACL,SAAS;YACT,IAAI;YACJ,MAAM,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE;YACtC,SAAS,EAAE,GAAG,KAAK,CAAC,MAAM,IAAI,IAAI,EAAE;YACpC,KAAK;YACL,QAAQ,EAAE,GAAG;SACd,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC;IAC/B,OAAO;QACL,SAAS;QACT,IAAI;QACJ,MAAM;QACN,SAAS,EAAE,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE;QAC5C,QAAQ,EAAE,GAAG;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { DriftReport, Rows } from '../drift.ts';
|
|
2
|
+
export type SignalOption = {
|
|
3
|
+
readonly signal?: AbortSignal;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* The port through which the declaration sends its SQL: the host writes it
|
|
7
|
+
* over its own driver. The parameters are named, `@p0` for the key `p0`.
|
|
8
|
+
* `transaction(work)` runs the work on one connection in one transaction.
|
|
9
|
+
* A copy of the SqlServerSession of @zukhruf/checkpoint
|
|
10
|
+
* (docs/copied-session-ports.md).
|
|
11
|
+
*/
|
|
12
|
+
export type SqlServerSession = {
|
|
13
|
+
query(sql: string, parameters: Readonly<Record<string, unknown>>, options?: SignalOption): Promise<readonly Record<string, unknown>[]>;
|
|
14
|
+
transaction(work: (session: SqlServerSession) => Promise<void>): Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The tables, indexes, views, sequences, functions, procedures and schemas
|
|
18
|
+
* that a package owns in a SQL Server database, by the CREATE statements that
|
|
19
|
+
* make them, one statement for each object. The constructor reads the kind
|
|
20
|
+
* and the qualified name of each statement from its head (ADR 0011), and the
|
|
21
|
+
* checksum of its tokens (ADR 0010). `drift` compares each checksum with the
|
|
22
|
+
* ledger row of its object (ADR 0009); `apply` makes each missing object and
|
|
23
|
+
* replaces or rebuilds each stale one (ADR 0012), in one transaction with
|
|
24
|
+
* XACT_ABORT on, under the lock of the package (ADR 0014).
|
|
25
|
+
*/
|
|
26
|
+
export declare class SqlServerDeclaration {
|
|
27
|
+
#private;
|
|
28
|
+
/** ledgerSchema is the schema of the ledger table. Default: 'dbo'. */
|
|
29
|
+
constructor(statements: readonly string[], options?: {
|
|
30
|
+
readonly ledgerSchema?: string;
|
|
31
|
+
});
|
|
32
|
+
/** The drift of the declaration, and each declared object that is missing or stale, in the order of the declaration. */
|
|
33
|
+
drift(session: SqlServerSession): Promise<DriftReport>;
|
|
34
|
+
/** Throws SchemaDriftError when the drift is not 'fits'. A package calls it when it opens (ADR 0007). */
|
|
35
|
+
check(session: SqlServerSession): Promise<void>;
|
|
36
|
+
/** The host chooses rows when it applies. It has no default. */
|
|
37
|
+
apply(session: SqlServerSession, options: {
|
|
38
|
+
readonly rows: Rows;
|
|
39
|
+
}): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=sqlserver-declaration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlserver-declaration.d.ts","sourceRoot":"","sources":["../../src/sqlserver/sqlserver-declaration.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAiB,IAAI,EAAE,MAAM,aAAa,CAAC;AAQpE,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,CAAC;AAE7D;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,CACH,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAC7C,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IAC/C,WAAW,CACT,IAAI,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,GACjD,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB,CAAC;AAmDF;;;;;;;;;GASG;AACH,qBAAa,oBAAoB;;IAI/B,sEAAsE;IACtE,YACE,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,EAe7C;IAED,wHAAwH;IAClH,KAAK,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,WAAW,CAAC,CAE3D;IAED,yGAAyG;IACnG,KAAK,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAGpD;IAED,gEAAgE;IAC1D,KAAK,CACT,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;KAAE,GAC/B,OAAO,CAAC,IAAI,CAAC,CA0Cf;CA4EF"}
|
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { SchemaDriftError } from '../schema-drift-error.js';
|
|
3
|
+
import { declared, } from './sqlserver-statement.js';
|
|
4
|
+
const LEDGER = 'zukhruf_schema_drift';
|
|
5
|
+
// The types of sys.objects that each kind of object has, between spaces.
|
|
6
|
+
const TYPES = {
|
|
7
|
+
table: ' U ',
|
|
8
|
+
view: ' V ',
|
|
9
|
+
sequence: ' SO ',
|
|
10
|
+
function: ' FN IF TF FS FT ',
|
|
11
|
+
procedure: ' P PC ',
|
|
12
|
+
index: '',
|
|
13
|
+
schema: '',
|
|
14
|
+
};
|
|
15
|
+
// Whether the catalog lists the object of each row of d.
|
|
16
|
+
const PRESENT = `CASE
|
|
17
|
+
WHEN d.kind = N'schema' THEN CASE WHEN EXISTS (SELECT 1 FROM sys.schemas AS s WHERE s.name = d.name) THEN 1 ELSE 0 END
|
|
18
|
+
WHEN d.kind = N'index' THEN CASE WHEN EXISTS (SELECT 1 FROM sys.indexes AS i JOIN sys.objects AS o ON o.object_id = i.object_id JOIN sys.schemas AS s ON s.schema_id = o.schema_id WHERE s.name = d.[schema] AND o.name = d.[table] AND i.name = d.name) THEN 1 ELSE 0 END
|
|
19
|
+
ELSE CASE WHEN EXISTS (SELECT 1 FROM sys.objects AS o JOIN sys.schemas AS s ON s.schema_id = o.schema_id WHERE s.name = d.[schema] AND o.name = d.name AND CHARINDEX(N' ' + RTRIM(o.type) + N' ', d.types) > 0) THEN 1 ELSE 0 END
|
|
20
|
+
END`;
|
|
21
|
+
// The lock of the package, which the transaction owns (ADR 0014).
|
|
22
|
+
const LOCK = `DECLARE @locked int;
|
|
23
|
+
EXEC @locked = sys.sp_getapplock @Resource = N'@zukhruf/schema-drift', @LockMode = 'Exclusive', @LockOwner = 'Transaction';
|
|
24
|
+
IF @locked < 0 THROW 51000, N'apply could not take the lock of @zukhruf/schema-drift.', 1;`;
|
|
25
|
+
function quote(identifier) {
|
|
26
|
+
return `[${identifier.replaceAll(']', ']]')}]`;
|
|
27
|
+
}
|
|
28
|
+
function qualify({ schema, name }) {
|
|
29
|
+
return `${quote(schema)}.${quote(name)}`;
|
|
30
|
+
}
|
|
31
|
+
function sameName(a, b) {
|
|
32
|
+
return a.schema === b.schema && a.name === b.name;
|
|
33
|
+
}
|
|
34
|
+
// The error of a query that names a table that does not exist.
|
|
35
|
+
function invalidObjectName(error) {
|
|
36
|
+
return (typeof error === 'object' &&
|
|
37
|
+
error !== null &&
|
|
38
|
+
'number' in error &&
|
|
39
|
+
error.number === 208);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The tables, indexes, views, sequences, functions, procedures and schemas
|
|
43
|
+
* that a package owns in a SQL Server database, by the CREATE statements that
|
|
44
|
+
* make them, one statement for each object. The constructor reads the kind
|
|
45
|
+
* and the qualified name of each statement from its head (ADR 0011), and the
|
|
46
|
+
* checksum of its tokens (ADR 0010). `drift` compares each checksum with the
|
|
47
|
+
* ledger row of its object (ADR 0009); `apply` makes each missing object and
|
|
48
|
+
* replaces or rebuilds each stale one (ADR 0012), in one transaction with
|
|
49
|
+
* XACT_ABORT on, under the lock of the package (ADR 0014).
|
|
50
|
+
*/
|
|
51
|
+
export class SqlServerDeclaration {
|
|
52
|
+
#statements;
|
|
53
|
+
#ledger;
|
|
54
|
+
/** ledgerSchema is the schema of the ledger table. Default: 'dbo'. */
|
|
55
|
+
constructor(statements, options) {
|
|
56
|
+
const read = statements.map(declared);
|
|
57
|
+
const keys = new Set();
|
|
58
|
+
for (const { kind, qualified } of read) {
|
|
59
|
+
const key = `${kind} ${qualified}`;
|
|
60
|
+
if (keys.has(key))
|
|
61
|
+
throw new Error(`A declaration names each object once: ${key}`);
|
|
62
|
+
keys.add(key);
|
|
63
|
+
}
|
|
64
|
+
this.#statements = read;
|
|
65
|
+
this.#ledger = qualify({
|
|
66
|
+
schema: options?.ledgerSchema ?? 'dbo',
|
|
67
|
+
name: LEDGER,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/** The drift of the declaration, and each declared object that is missing or stale, in the order of the declaration. */
|
|
71
|
+
async drift(session) {
|
|
72
|
+
return this.#report(this.#drifts((await this.#read(session)).rows));
|
|
73
|
+
}
|
|
74
|
+
/** Throws SchemaDriftError when the drift is not 'fits'. A package calls it when it opens (ADR 0007). */
|
|
75
|
+
async check(session) {
|
|
76
|
+
const { drift, objects } = await this.drift(session);
|
|
77
|
+
if (drift !== 'fits')
|
|
78
|
+
throw new SchemaDriftError(objects);
|
|
79
|
+
}
|
|
80
|
+
/** The host chooses rows when it applies. It has no default. */
|
|
81
|
+
async apply(session, options) {
|
|
82
|
+
const { rows } = options;
|
|
83
|
+
if (rows !== 'replace' && rows !== 'keep')
|
|
84
|
+
throw new TypeError(`apply needs rows: 'replace' or 'keep'. It has no default. It got ${String(rows)}.`);
|
|
85
|
+
await session.transaction(async (transaction) => {
|
|
86
|
+
await transaction.query(`SET XACT_ABORT ON;\n${LOCK}`, {});
|
|
87
|
+
// The read inside the lock runs with XACT_ABORT off: under it, the
|
|
88
|
+
// error of a missing ledger would end the transaction and the lock.
|
|
89
|
+
const read = await this.#read(transaction, 'SET XACT_ABORT OFF;\n');
|
|
90
|
+
const drifts = this.#drifts(read.rows);
|
|
91
|
+
if (drifts.size === 0)
|
|
92
|
+
return;
|
|
93
|
+
const application = new Application(transaction, this.#statements, drifts, rows);
|
|
94
|
+
const made = await application.run();
|
|
95
|
+
if (!read.ledger)
|
|
96
|
+
await application.query(`CREATE TABLE ${this.#ledger} (name nvarchar(400) NOT NULL, kind nvarchar(20) NOT NULL, checksum char(64) NOT NULL, applied_at datetime2 NOT NULL DEFAULT SYSUTCDATETIME(), PRIMARY KEY (kind, name))`);
|
|
97
|
+
const written = this.#statements.filter((statement) => made.has(statement));
|
|
98
|
+
await application.query(`MERGE ${this.#ledger} WITH (HOLDLOCK) AS l
|
|
99
|
+
USING (VALUES ${written.map((_, index) => `(@n${index}, @k${index}, @c${index})`).join(', ')}) AS d (name, kind, checksum)
|
|
100
|
+
ON l.kind = d.kind AND l.name = d.name
|
|
101
|
+
WHEN MATCHED THEN UPDATE SET checksum = d.checksum, applied_at = SYSUTCDATETIME()
|
|
102
|
+
WHEN NOT MATCHED THEN INSERT (name, kind, checksum) VALUES (d.name, d.kind, d.checksum);`, Object.fromEntries(written.flatMap(({ qualified, kind, checksum }, index) => [
|
|
103
|
+
[`n${index}`, qualified],
|
|
104
|
+
[`k${index}`, kind],
|
|
105
|
+
[`c${index}`, checksum],
|
|
106
|
+
])));
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
// One query: the declared objects, whether the catalog lists each one, and
|
|
110
|
+
// the checksum of its ledger row. When the ledger table does not exist
|
|
111
|
+
// (error 208), one query of the catalog alone (ADR 0009).
|
|
112
|
+
async #read(session, prefix = '') {
|
|
113
|
+
if (this.#statements.length === 0)
|
|
114
|
+
return { rows: [], ledger: true };
|
|
115
|
+
const values = this.#statements.map((_, index) => `(@i${index}, @k${index}, @s${index}, @n${index}, @t${index}, @q${index}, @y${index})`);
|
|
116
|
+
const parameters = Object.fromEntries(this.#statements.flatMap((statement, index) => [
|
|
117
|
+
[`i${index}`, index],
|
|
118
|
+
[`k${index}`, statement.kind],
|
|
119
|
+
[`s${index}`, statement.object.schema],
|
|
120
|
+
[`n${index}`, statement.object.name],
|
|
121
|
+
[`t${index}`, statement.kind === 'index' ? statement.table.name : ''],
|
|
122
|
+
[`q${index}`, statement.qualified],
|
|
123
|
+
[`y${index}`, TYPES[statement.kind]],
|
|
124
|
+
]));
|
|
125
|
+
const query = (ledger) => session.query(`${prefix}SELECT d.position, ${PRESENT} AS present, ${ledger ? 'l.checksum' : 'CAST(NULL AS char(64))'} AS recorded
|
|
126
|
+
FROM (VALUES ${values.join(', ')}) AS d (position, kind, [schema], name, [table], qualified, types)
|
|
127
|
+
${ledger ? `LEFT JOIN ${this.#ledger} AS l ON l.kind = d.kind AND l.name = d.qualified` : ''}
|
|
128
|
+
ORDER BY d.position`, parameters);
|
|
129
|
+
try {
|
|
130
|
+
return { rows: await query(true), ledger: true };
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
if (!invalidObjectName(error))
|
|
134
|
+
throw error;
|
|
135
|
+
return { rows: await query(false), ledger: false };
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// A declared schema has only its name, so it is missing or it fits. Each
|
|
139
|
+
// other object fits when it exists and its ledger row has its checksum.
|
|
140
|
+
#drifts(rows) {
|
|
141
|
+
const drifts = new Map();
|
|
142
|
+
for (const row of rows) {
|
|
143
|
+
const statement = this.#statements[Number(row.position)];
|
|
144
|
+
if (statement === undefined)
|
|
145
|
+
continue;
|
|
146
|
+
if (row.present !== 1)
|
|
147
|
+
drifts.set(statement, 'missing');
|
|
148
|
+
else if (statement.kind !== 'schema' &&
|
|
149
|
+
row.recorded !== statement.checksum)
|
|
150
|
+
drifts.set(statement, 'stale');
|
|
151
|
+
}
|
|
152
|
+
return drifts;
|
|
153
|
+
}
|
|
154
|
+
#report(drifts) {
|
|
155
|
+
const objects = this.#statements.flatMap((statement) => {
|
|
156
|
+
const drift = drifts.get(statement);
|
|
157
|
+
return drift === undefined
|
|
158
|
+
? []
|
|
159
|
+
: [{ name: statement.qualified, kind: statement.kind, drift }];
|
|
160
|
+
});
|
|
161
|
+
if (objects.length === 0)
|
|
162
|
+
return { drift: 'fits', objects };
|
|
163
|
+
const none = objects.length === this.#statements.length &&
|
|
164
|
+
objects.every(({ drift }) => drift === 'missing');
|
|
165
|
+
return { drift: none ? 'missing' : 'stale', objects };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// One apply, inside the transaction and the lock: it works on the stale and
|
|
169
|
+
// the missing objects, in the order of the declaration (ADR 0012), and gives
|
|
170
|
+
// each declared object that it made. Each batch runs with XACT_ABORT on, so
|
|
171
|
+
// an error rolls the whole transaction back.
|
|
172
|
+
class Application {
|
|
173
|
+
#session;
|
|
174
|
+
#statements;
|
|
175
|
+
#drifts;
|
|
176
|
+
#rows;
|
|
177
|
+
#made = new Set();
|
|
178
|
+
#temporary = randomBytes(6).toHex();
|
|
179
|
+
#renamed = 0;
|
|
180
|
+
constructor(session, statements, drifts, rows) {
|
|
181
|
+
this.#session = session;
|
|
182
|
+
this.#statements = statements;
|
|
183
|
+
this.#drifts = drifts;
|
|
184
|
+
this.#rows = rows;
|
|
185
|
+
}
|
|
186
|
+
async run() {
|
|
187
|
+
for (const statement of this.#statements) {
|
|
188
|
+
if (this.#made.has(statement))
|
|
189
|
+
continue;
|
|
190
|
+
const drift = this.#drifts.get(statement);
|
|
191
|
+
if (drift === 'missing')
|
|
192
|
+
await this.#make(statement);
|
|
193
|
+
else if (drift === 'stale')
|
|
194
|
+
await this.#replace(statement);
|
|
195
|
+
}
|
|
196
|
+
return this.#made;
|
|
197
|
+
}
|
|
198
|
+
query(sql, parameters = {}) {
|
|
199
|
+
return this.#session.query(`SET XACT_ABORT ON;\n${sql}`, parameters);
|
|
200
|
+
}
|
|
201
|
+
async #replace(statement) {
|
|
202
|
+
const name = qualify(statement.object);
|
|
203
|
+
switch (statement.kind) {
|
|
204
|
+
case 'table':
|
|
205
|
+
await this.#tables(this.#rows === 'keep'
|
|
206
|
+
? [statement]
|
|
207
|
+
: await this.#referring(statement));
|
|
208
|
+
return;
|
|
209
|
+
case 'view':
|
|
210
|
+
await this.#view(statement);
|
|
211
|
+
return;
|
|
212
|
+
case 'sequence':
|
|
213
|
+
await this.#sequence(statement);
|
|
214
|
+
return;
|
|
215
|
+
case 'index':
|
|
216
|
+
await this.query(`DROP INDEX ${quote(statement.object.name)} ON ${qualify(statement.table)}`);
|
|
217
|
+
break;
|
|
218
|
+
case 'function':
|
|
219
|
+
await this.query(`DROP FUNCTION ${name}`);
|
|
220
|
+
break;
|
|
221
|
+
case 'procedure':
|
|
222
|
+
await this.query(`DROP PROCEDURE ${name}`);
|
|
223
|
+
break;
|
|
224
|
+
case 'schema':
|
|
225
|
+
// A declared schema has only its name: it is missing or it fits.
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
await this.#make(statement);
|
|
229
|
+
}
|
|
230
|
+
// The stale table, and each declared table that refers to one of them, so
|
|
231
|
+
// no kept row refers to a row that is gone (rows: 'replace').
|
|
232
|
+
async #referring(table) {
|
|
233
|
+
const group = [table];
|
|
234
|
+
for (let index = 0; index < group.length; index += 1) {
|
|
235
|
+
const referred = group[index];
|
|
236
|
+
if (referred === undefined)
|
|
237
|
+
break;
|
|
238
|
+
const referrers = await this.query(`SELECT s.name AS [schema], o.name
|
|
239
|
+
FROM sys.foreign_keys AS k
|
|
240
|
+
JOIN sys.objects AS o ON o.object_id = k.parent_object_id
|
|
241
|
+
JOIN sys.schemas AS s ON s.schema_id = o.schema_id
|
|
242
|
+
WHERE k.referenced_object_id = OBJECT_ID(@table) AND k.parent_object_id <> k.referenced_object_id`, { table: qualify(referred.object) });
|
|
243
|
+
for (const referrer of referrers) {
|
|
244
|
+
const declaredTable = this.#statements.find((statement) => statement.kind === 'table' &&
|
|
245
|
+
sameName(catalogName(referrer), statement.object));
|
|
246
|
+
if (declaredTable !== undefined && !group.includes(declaredTable))
|
|
247
|
+
group.push(declaredTable);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return group.toSorted((a, b) => this.#statements.indexOf(a) - this.#statements.indexOf(b));
|
|
251
|
+
}
|
|
252
|
+
// Replaces (rows: 'replace') or rebuilds (rows: 'keep') each table of the
|
|
253
|
+
// group, and makes again what depends on them (ADR 0012).
|
|
254
|
+
async #tables(group) {
|
|
255
|
+
const captures = [];
|
|
256
|
+
for (const table of group)
|
|
257
|
+
captures.push(await this.#capture(table.object));
|
|
258
|
+
const views = merged(captures.flatMap(({ views }) => views));
|
|
259
|
+
const foreignKeys = captures
|
|
260
|
+
.flatMap(({ foreignKeys }) => foreignKeys)
|
|
261
|
+
.filter(({ table }) => !group.some(({ object }) => sameName(table, object)));
|
|
262
|
+
await this.#dropBound(views);
|
|
263
|
+
for (const { table, name } of foreignKeys)
|
|
264
|
+
await this.query(`ALTER TABLE ${qualify(table)} DROP CONSTRAINT ${quote(name)}`);
|
|
265
|
+
const kept = new Map();
|
|
266
|
+
if (this.#rows === 'keep')
|
|
267
|
+
for (const [index, table] of group.entries()) {
|
|
268
|
+
const capture = captures[index];
|
|
269
|
+
if (capture === undefined)
|
|
270
|
+
continue;
|
|
271
|
+
// The old table and its constraints go away first, so each name
|
|
272
|
+
// that the statement makes is free (ADR 0012). An index name is
|
|
273
|
+
// unique only in its table, so the indexes keep theirs.
|
|
274
|
+
const old = { schema: table.object.schema, name: this.#away() };
|
|
275
|
+
await this.#rename(table.object, old.name);
|
|
276
|
+
for (const constraint of capture.constraints)
|
|
277
|
+
await this.#rename({ schema: table.object.schema, name: constraint }, this.#away());
|
|
278
|
+
kept.set(table, old);
|
|
279
|
+
}
|
|
280
|
+
else
|
|
281
|
+
for (const table of group.toReversed())
|
|
282
|
+
await this.query(`DROP TABLE ${qualify(table.object)}`);
|
|
283
|
+
for (const table of group)
|
|
284
|
+
await this.#make(table);
|
|
285
|
+
for (const [index, table] of group.entries()) {
|
|
286
|
+
const old = kept.get(table);
|
|
287
|
+
const capture = captures[index];
|
|
288
|
+
if (old === undefined || capture === undefined)
|
|
289
|
+
continue;
|
|
290
|
+
await this.#copy(table.object, old, capture.key);
|
|
291
|
+
await this.query(`DROP TABLE ${qualify(old)}`);
|
|
292
|
+
}
|
|
293
|
+
for (const [index, table] of group.entries()) {
|
|
294
|
+
const capture = captures[index];
|
|
295
|
+
if (capture === undefined)
|
|
296
|
+
continue;
|
|
297
|
+
for (const statement of this.#statements)
|
|
298
|
+
if (statement.kind === 'index' &&
|
|
299
|
+
sameName(statement.table, table.object))
|
|
300
|
+
await this.#make(statement);
|
|
301
|
+
for (const index of capture.indexes)
|
|
302
|
+
if (!this.#declaresIndex(table.object, index.name))
|
|
303
|
+
await this.query(index.definition);
|
|
304
|
+
await this.#triggers(capture.triggers);
|
|
305
|
+
}
|
|
306
|
+
for (const { table, name, definition, disabled } of foreignKeys) {
|
|
307
|
+
await this.query(`ALTER TABLE ${qualify(table)} WITH CHECK ADD CONSTRAINT ${quote(name)} ${definition}`);
|
|
308
|
+
if (disabled)
|
|
309
|
+
await this.query(`ALTER TABLE ${qualify(table)} NOCHECK CONSTRAINT ${quote(name)}`);
|
|
310
|
+
}
|
|
311
|
+
await this.#views(views);
|
|
312
|
+
}
|
|
313
|
+
// Copies the columns that both tables have, by name, in the order of the
|
|
314
|
+
// old table's primary key, with the stored values of an identity column.
|
|
315
|
+
// SQL Server moves the identity past the largest value that it inserts.
|
|
316
|
+
async #copy(table, old, key) {
|
|
317
|
+
const columns = await this.query(`SELECT n.name, n.is_identity AS [identity]
|
|
318
|
+
FROM sys.columns AS n
|
|
319
|
+
JOIN sys.columns AS o ON o.object_id = OBJECT_ID(@old) AND o.name = n.name
|
|
320
|
+
WHERE n.object_id = OBJECT_ID(@table) AND n.is_computed = 0 AND n.generated_always_type = 0 AND n.system_type_id <> 189
|
|
321
|
+
ORDER BY n.column_id`, { table: qualify(table), old: qualify(old) });
|
|
322
|
+
if (columns.length === 0)
|
|
323
|
+
return;
|
|
324
|
+
const names = columns.map(({ name }) => quote(String(name))).join(', ');
|
|
325
|
+
const order = key.length === 0 ? '' : ` ORDER BY ${key.map(quote).join(', ')}`;
|
|
326
|
+
const insert = `INSERT INTO ${qualify(table)} (${names}) SELECT ${names} FROM ${qualify(old)}${order};`;
|
|
327
|
+
await this.query(columns.some(({ identity }) => identity === true)
|
|
328
|
+
? `SET IDENTITY_INSERT ${qualify(table)} ON;\n${insert}\nSET IDENTITY_INSERT ${qualify(table)} OFF;`
|
|
329
|
+
: insert);
|
|
330
|
+
}
|
|
331
|
+
// A stale view is dropped with the schema-bound views that read it, made
|
|
332
|
+
// from its statement, and the views that read it are made again or
|
|
333
|
+
// refreshed.
|
|
334
|
+
async #view(view) {
|
|
335
|
+
const views = await this.#dependents(view.object);
|
|
336
|
+
const triggers = await this.#triggersOf(view.object);
|
|
337
|
+
await this.#dropBound(views);
|
|
338
|
+
await this.query(`DROP VIEW ${qualify(view.object)}`);
|
|
339
|
+
await this.#make(view);
|
|
340
|
+
await this.#triggers(triggers);
|
|
341
|
+
await this.#views(views);
|
|
342
|
+
}
|
|
343
|
+
// A stale sequence is made from its statement. With rows: 'keep', it
|
|
344
|
+
// keeps its last value: its next value follows the last one given.
|
|
345
|
+
async #sequence(sequence) {
|
|
346
|
+
const name = qualify(sequence.object);
|
|
347
|
+
const [last] = this.#rows === 'keep'
|
|
348
|
+
? await this.query(`SELECT CONVERT(nvarchar(60), last_used_value) AS value FROM sys.sequences WHERE object_id = OBJECT_ID(@name)`, { name })
|
|
349
|
+
: [];
|
|
350
|
+
await this.query(`DROP SEQUENCE ${name}`);
|
|
351
|
+
await this.#make(sequence);
|
|
352
|
+
if (typeof last?.value === 'string')
|
|
353
|
+
await this.query(`DECLARE @restart nvarchar(max) = N'ALTER SEQUENCE ${name.replaceAll("'", "''")} RESTART WITH '
|
|
354
|
+
+ CONVERT(nvarchar(60), CONVERT(decimal(38, 0), @last) + (SELECT CONVERT(decimal(38, 0), increment) FROM sys.sequences WHERE object_id = OBJECT_ID(@name)));
|
|
355
|
+
EXEC sys.sp_executesql @restart;`, { name, last: last.value });
|
|
356
|
+
}
|
|
357
|
+
// Drops the schema-bound views among the views, the views that read
|
|
358
|
+
// others first. SQL Server refuses to drop or rename what they read
|
|
359
|
+
// (errors 3729, 15336); a view that is not schema-bound stays.
|
|
360
|
+
async #dropBound(views) {
|
|
361
|
+
for (const view of views.toReversed())
|
|
362
|
+
if (view.schemaBound)
|
|
363
|
+
await this.query(`DROP VIEW ${qualify(view.object)}`);
|
|
364
|
+
}
|
|
365
|
+
// Makes each dropped view again, the views that others read first: a
|
|
366
|
+
// declared view from its statement, any other view from its definition.
|
|
367
|
+
// Each view that is not schema-bound gets sp_refreshview.
|
|
368
|
+
async #views(views) {
|
|
369
|
+
for (const view of views) {
|
|
370
|
+
if (!view.schemaBound) {
|
|
371
|
+
await this.query('EXEC sys.sp_refreshview @name', {
|
|
372
|
+
name: qualify(view.object),
|
|
373
|
+
});
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
const statement = this.#statements.find((candidate) => candidate.kind === 'view' && sameName(view.object, candidate.object));
|
|
377
|
+
if (statement !== undefined)
|
|
378
|
+
await this.#make(statement);
|
|
379
|
+
else
|
|
380
|
+
await this.#module(view);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
async #triggers(triggers) {
|
|
384
|
+
for (const trigger of triggers) {
|
|
385
|
+
await this.#module(trigger);
|
|
386
|
+
if (trigger.disabled)
|
|
387
|
+
await this.query(`DISABLE TRIGGER ${qualify(trigger.object)} ON ${qualify(trigger.parent)}`);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
async #capture(table) {
|
|
391
|
+
const name = qualify(table);
|
|
392
|
+
const foreignKeys = await this.query(`SELECT s.name AS [schema], o.name, k.name AS [constraint], k.is_disabled AS disabled,
|
|
393
|
+
k.delete_referential_action_desc AS on_delete, k.update_referential_action_desc AS on_update,
|
|
394
|
+
pc.name AS [column], rc.name AS referenced
|
|
395
|
+
FROM sys.foreign_keys AS k
|
|
396
|
+
JOIN sys.objects AS o ON o.object_id = k.parent_object_id
|
|
397
|
+
JOIN sys.schemas AS s ON s.schema_id = o.schema_id
|
|
398
|
+
JOIN sys.foreign_key_columns AS fc ON fc.constraint_object_id = k.object_id
|
|
399
|
+
JOIN sys.columns AS pc ON pc.object_id = fc.parent_object_id AND pc.column_id = fc.parent_column_id
|
|
400
|
+
JOIN sys.columns AS rc ON rc.object_id = fc.referenced_object_id AND rc.column_id = fc.referenced_column_id
|
|
401
|
+
WHERE k.referenced_object_id = OBJECT_ID(@table) AND k.parent_object_id <> k.referenced_object_id
|
|
402
|
+
ORDER BY s.name, o.name, k.name, fc.constraint_column_id`, { table: name });
|
|
403
|
+
const indexes = await this.query(`SELECT i.name, i.is_unique AS [unique], i.type_desc AS type, i.filter_definition AS filter,
|
|
404
|
+
c.name AS [column], ic.is_descending_key AS descending, ic.is_included_column AS included
|
|
405
|
+
FROM sys.indexes AS i
|
|
406
|
+
JOIN sys.index_columns AS ic ON ic.object_id = i.object_id AND ic.index_id = i.index_id
|
|
407
|
+
JOIN sys.columns AS c ON c.object_id = ic.object_id AND c.column_id = ic.column_id
|
|
408
|
+
WHERE i.object_id = OBJECT_ID(@table) AND i.type IN (1, 2) AND i.is_primary_key = 0 AND i.is_unique_constraint = 0 AND i.is_hypothetical = 0
|
|
409
|
+
ORDER BY i.index_id, ic.is_included_column, ic.key_ordinal, ic.index_column_id`, { table: name });
|
|
410
|
+
const constraints = await this.query(`SELECT name FROM sys.objects WHERE parent_object_id = OBJECT_ID(@table) AND type IN ('PK', 'UQ', 'D', 'C', 'F', 'EC') ORDER BY name`, { table: name });
|
|
411
|
+
const key = await this.query(`SELECT c.name
|
|
412
|
+
FROM sys.indexes AS i
|
|
413
|
+
JOIN sys.index_columns AS ic ON ic.object_id = i.object_id AND ic.index_id = i.index_id
|
|
414
|
+
JOIN sys.columns AS c ON c.object_id = ic.object_id AND c.column_id = ic.column_id
|
|
415
|
+
WHERE i.object_id = OBJECT_ID(@table) AND i.is_primary_key = 1 AND ic.key_ordinal > 0
|
|
416
|
+
ORDER BY ic.key_ordinal`, { table: name });
|
|
417
|
+
return {
|
|
418
|
+
views: await this.#dependents(table),
|
|
419
|
+
foreignKeys: grouped(foreignKeys, ({ schema, name, constraint }) => [schema, name, constraint].join('.')).map((columns) => {
|
|
420
|
+
const [first] = columns;
|
|
421
|
+
const action = (value) => String(value).replaceAll('_', ' ');
|
|
422
|
+
return {
|
|
423
|
+
table: catalogName(first ?? {}),
|
|
424
|
+
name: String(first?.constraint),
|
|
425
|
+
disabled: first?.disabled === true,
|
|
426
|
+
definition: `FOREIGN KEY (${columns.map(({ column }) => quote(String(column))).join(', ')}) REFERENCES ${name} (${columns.map(({ referenced }) => quote(String(referenced))).join(', ')}) ON DELETE ${action(first?.on_delete)} ON UPDATE ${action(first?.on_update)}`,
|
|
427
|
+
};
|
|
428
|
+
}),
|
|
429
|
+
indexes: grouped(indexes, ({ name }) => String(name)).map((columns) => {
|
|
430
|
+
const [first] = columns;
|
|
431
|
+
const keys = columns
|
|
432
|
+
.filter(({ included }) => included !== true)
|
|
433
|
+
.map(({ column, descending }) => `${quote(String(column))} ${descending === true ? 'DESC' : 'ASC'}`);
|
|
434
|
+
const included = columns
|
|
435
|
+
.filter(({ included }) => included === true)
|
|
436
|
+
.map(({ column }) => quote(String(column)));
|
|
437
|
+
return {
|
|
438
|
+
name: String(first?.name),
|
|
439
|
+
definition: `CREATE ${first?.unique === true ? 'UNIQUE ' : ''}${String(first?.type)} INDEX ${quote(String(first?.name))} ON ${name} (${keys.join(', ')})${included.length > 0 ? ` INCLUDE (${included.join(', ')})` : ''}${typeof first?.filter === 'string' ? ` WHERE ${first.filter}` : ''}`,
|
|
440
|
+
};
|
|
441
|
+
}),
|
|
442
|
+
constraints: constraints.map(({ name }) => String(name)),
|
|
443
|
+
triggers: await this.#triggersOf(table),
|
|
444
|
+
key: key.map(({ name }) => String(name)),
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
// The views that read the object, and the views that read those, the
|
|
448
|
+
// views that others read first.
|
|
449
|
+
async #dependents(object) {
|
|
450
|
+
const rows = await this.query(`WITH dependents (id, depth) AS (
|
|
451
|
+
SELECT d.referencing_id, 1
|
|
452
|
+
FROM sys.sql_expression_dependencies AS d
|
|
453
|
+
JOIN sys.views AS v ON v.object_id = d.referencing_id
|
|
454
|
+
WHERE d.referenced_id = OBJECT_ID(@object)
|
|
455
|
+
UNION ALL
|
|
456
|
+
SELECT d.referencing_id, dependents.depth + 1
|
|
457
|
+
FROM dependents
|
|
458
|
+
JOIN sys.sql_expression_dependencies AS d ON d.referenced_id = dependents.id
|
|
459
|
+
JOIN sys.views AS v ON v.object_id = d.referencing_id
|
|
460
|
+
WHERE d.referencing_id <> dependents.id
|
|
461
|
+
)
|
|
462
|
+
SELECT s.name AS [schema], v.name, x.depth, m.definition, m.is_schema_bound AS bound,
|
|
463
|
+
m.uses_ansi_nulls AS ansi_nulls, m.uses_quoted_identifier AS quoted_identifier
|
|
464
|
+
FROM (SELECT id, MAX(depth) AS depth FROM dependents GROUP BY id) AS x
|
|
465
|
+
JOIN sys.views AS v ON v.object_id = x.id
|
|
466
|
+
JOIN sys.schemas AS s ON s.schema_id = v.schema_id
|
|
467
|
+
JOIN sys.sql_modules AS m ON m.object_id = v.object_id
|
|
468
|
+
ORDER BY x.depth, s.name, v.name`, { object: qualify(object) });
|
|
469
|
+
return rows.map((row) => ({
|
|
470
|
+
object: catalogName(row),
|
|
471
|
+
depth: Number(row.depth),
|
|
472
|
+
schemaBound: row.bound === true,
|
|
473
|
+
...module(row),
|
|
474
|
+
}));
|
|
475
|
+
}
|
|
476
|
+
async #triggersOf(object) {
|
|
477
|
+
const rows = await this.query(`SELECT s.name AS [schema], t.name, t.is_disabled AS disabled, m.definition,
|
|
478
|
+
m.uses_ansi_nulls AS ansi_nulls, m.uses_quoted_identifier AS quoted_identifier
|
|
479
|
+
FROM sys.triggers AS t
|
|
480
|
+
JOIN sys.objects AS o ON o.object_id = t.object_id
|
|
481
|
+
JOIN sys.schemas AS s ON s.schema_id = o.schema_id
|
|
482
|
+
JOIN sys.sql_modules AS m ON m.object_id = t.object_id
|
|
483
|
+
WHERE t.parent_id = OBJECT_ID(@object)
|
|
484
|
+
ORDER BY t.name`, { object: qualify(object) });
|
|
485
|
+
return rows.map((row) => ({
|
|
486
|
+
object: catalogName(row),
|
|
487
|
+
parent: object,
|
|
488
|
+
disabled: row.disabled === true,
|
|
489
|
+
...module(row),
|
|
490
|
+
}));
|
|
491
|
+
}
|
|
492
|
+
// Runs the text of a module of the catalog again, as its own batch and
|
|
493
|
+
// with the SET options that it was made under.
|
|
494
|
+
async #module({ definition, ansiNulls, quotedIdentifier, }) {
|
|
495
|
+
await this.query(`SET ANSI_NULLS ${ansiNulls ? 'ON' : 'OFF'};
|
|
496
|
+
SET QUOTED_IDENTIFIER ${quotedIdentifier ? 'ON' : 'OFF'};
|
|
497
|
+
EXEC sys.sp_executesql @definition;`, { definition });
|
|
498
|
+
}
|
|
499
|
+
async #rename(object, name) {
|
|
500
|
+
await this.query(`EXEC sys.sp_rename @objname = @object, @newname = @name, @objtype = N'OBJECT'`, { object: qualify(object), name });
|
|
501
|
+
}
|
|
502
|
+
#declaresIndex(table, name) {
|
|
503
|
+
return this.#statements.some((statement) => statement.kind === 'index' &&
|
|
504
|
+
sameName(statement.table, table) &&
|
|
505
|
+
statement.object.name === name);
|
|
506
|
+
}
|
|
507
|
+
#away() {
|
|
508
|
+
this.#renamed += 1;
|
|
509
|
+
return `zukhruf_schema_drift_${this.#temporary}_${this.#renamed}`;
|
|
510
|
+
}
|
|
511
|
+
// CREATE VIEW, FUNCTION, PROCEDURE and SCHEMA must be the only statement
|
|
512
|
+
// of their batch, so each statement runs through sp_executesql.
|
|
513
|
+
async #make(statement) {
|
|
514
|
+
await this.query('EXEC sys.sp_executesql @statement', {
|
|
515
|
+
statement: statement.statement,
|
|
516
|
+
});
|
|
517
|
+
this.#made.add(statement);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
function catalogName(row) {
|
|
521
|
+
return { schema: String(row.schema), name: String(row.name) };
|
|
522
|
+
}
|
|
523
|
+
function module(row) {
|
|
524
|
+
return {
|
|
525
|
+
definition: String(row.definition),
|
|
526
|
+
ansiNulls: row.ansi_nulls === true,
|
|
527
|
+
quotedIdentifier: row.quoted_identifier === true,
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
// The rows of each key, in the order of their first row.
|
|
531
|
+
function grouped(rows, key) {
|
|
532
|
+
return [...Map.groupBy(rows, key).values()];
|
|
533
|
+
}
|
|
534
|
+
// The views of several tables, each once, at its deepest place.
|
|
535
|
+
function merged(views) {
|
|
536
|
+
const deepest = new Map();
|
|
537
|
+
for (const view of views) {
|
|
538
|
+
const key = qualify(view.object);
|
|
539
|
+
const known = deepest.get(key);
|
|
540
|
+
if (known === undefined || known.depth < view.depth)
|
|
541
|
+
deepest.set(key, view);
|
|
542
|
+
}
|
|
543
|
+
return [...deepest.values()].toSorted((a, b) => a.depth - b.depth);
|
|
544
|
+
}
|
|
545
|
+
//# sourceMappingURL=sqlserver-declaration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlserver-declaration.js","sourceRoot":"","sources":["../../src/sqlserver/sqlserver-declaration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAGL,QAAQ,GACT,MAAM,0BAA0B,CAAC;AAwBlC,MAAM,MAAM,GAAG,sBAAsB,CAAC;AAEtC,yEAAyE;AACzE,MAAM,KAAK,GAAwD;IACjE,KAAK,EAAE,KAAK;IACZ,IAAI,EAAE,KAAK;IACX,QAAQ,EAAE,MAAM;IAChB,QAAQ,EAAE,kBAAkB;IAC5B,SAAS,EAAE,QAAQ;IACnB,KAAK,EAAE,EAAE;IACT,MAAM,EAAE,EAAE;CACX,CAAC;AAEF,yDAAyD;AACzD,MAAM,OAAO,GAAG;;;;IAIZ,CAAC;AAEL,kEAAkE;AAClE,MAAM,IAAI,GAAG;;2FAE8E,CAAC;AAE5F,SAAS,KAAK,CAAC,UAAkB;IAC/B,OAAO,IAAI,UAAU,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;AACjD,CAAC;AAED,SAAS,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,EAAe;IAC5C,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;AAC3C,CAAC;A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AAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ObjectKind } from '../drift.ts';
|
|
2
|
+
/** A name of the catalog: its schema and its own name, as the statement writes them. */
|
|
3
|
+
export type CatalogName = {
|
|
4
|
+
readonly schema: string;
|
|
5
|
+
readonly name: string;
|
|
6
|
+
};
|
|
7
|
+
type Kind = Exclude<ObjectKind, 'virtual table' | 'trigger'>;
|
|
8
|
+
/** One element of a declaration, read: what it makes, and the checksum of its tokens. */
|
|
9
|
+
export type DeclaredStatement = {
|
|
10
|
+
readonly statement: string;
|
|
11
|
+
readonly kind: Exclude<Kind, 'index'>;
|
|
12
|
+
readonly object: CatalogName;
|
|
13
|
+
/** The qualified name of the report and the ledger: 'dbo.runs'. */
|
|
14
|
+
readonly qualified: string;
|
|
15
|
+
readonly checksum: string;
|
|
16
|
+
} | {
|
|
17
|
+
readonly statement: string;
|
|
18
|
+
readonly kind: 'index';
|
|
19
|
+
/** The schema of its table, and its own name. */
|
|
20
|
+
readonly object: CatalogName;
|
|
21
|
+
/** The qualified name of the report and the ledger: 'dbo.runs.runs_by_name'. */
|
|
22
|
+
readonly qualified: string;
|
|
23
|
+
/** The table of the index, from the head after ON. */
|
|
24
|
+
readonly table: CatalogName;
|
|
25
|
+
readonly checksum: string;
|
|
26
|
+
};
|
|
27
|
+
export declare function declared(statement: string): DeclaredStatement;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=sqlserver-statement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlserver-statement.d.ts","sourceRoot":"","sources":["../../src/sqlserver/sqlserver-statement.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAQ9C,wFAAwF;AACxF,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7E,KAAK,IAAI,GAAG,OAAO,CAAC,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CAAC;AAE7D,yFAAyF;AACzF,MAAM,MAAM,iBAAiB,GACzB;IACE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,mEAAmE;IACnE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B,GACD;IACE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,iDAAiD;IACjD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,gFAAgF;IAChF,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,sDAAsD;IACtD,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B,CAAC;AAmIN,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,iBAAiB,CA2G7D"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
const OPERATOR = /[+\-*/%&|^~=<>!]/;
|
|
3
|
+
const WORD_START = /[A-Za-z_@#\u0080-]/;
|
|
4
|
+
const WORD = /[A-Za-z0-9_@#$\u0080-]/;
|
|
5
|
+
const NUMBER = /(?:0[xX][0-9a-fA-F]*|(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?)/y;
|
|
6
|
+
// The rest of a line after GO: a count and a comment, as sqlcmd reads it.
|
|
7
|
+
const BATCH_END = /[ \t]*(?:\d+)?[ \t]*(?:--[^\n]*)?(?:\r?\n|$)/y;
|
|
8
|
+
// The tokens of a statement by the lexical rules of SQL Server (ADR 0010): a
|
|
9
|
+
// string, an N'' string, a "quoted" name and a [bracketed] name are each one
|
|
10
|
+
// token, kept as written; comments (nested /* */ too) and the spaces between
|
|
11
|
+
// tokens are not tokens. A GO on its own line ends a batch of sqlcmd, so the
|
|
12
|
+
// element would hold two statements.
|
|
13
|
+
function tokens(statement) {
|
|
14
|
+
const found = [];
|
|
15
|
+
let at = 0;
|
|
16
|
+
let lineStart = true;
|
|
17
|
+
const unclosed = (what) => {
|
|
18
|
+
throw new Error(`A statement of a declaration must close each ${what}: ${statement}`);
|
|
19
|
+
};
|
|
20
|
+
const delimited = (open, close) => {
|
|
21
|
+
let end = open;
|
|
22
|
+
for (;;) {
|
|
23
|
+
if (end >= statement.length)
|
|
24
|
+
return -1;
|
|
25
|
+
if (statement[end] === close && statement[end + 1] === close)
|
|
26
|
+
end += 2;
|
|
27
|
+
else if (statement[end] === close)
|
|
28
|
+
return end;
|
|
29
|
+
else
|
|
30
|
+
end += 1;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
while (at < statement.length) {
|
|
34
|
+
const char = statement[at] ?? '';
|
|
35
|
+
const next = statement[at + 1] ?? '';
|
|
36
|
+
if (/\s/.test(char)) {
|
|
37
|
+
if (char === '\n')
|
|
38
|
+
lineStart = true;
|
|
39
|
+
at += 1;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const first = lineStart;
|
|
43
|
+
lineStart = false;
|
|
44
|
+
if (char === '-' && next === '-') {
|
|
45
|
+
const end = statement.indexOf('\n', at);
|
|
46
|
+
at = end === -1 ? statement.length : end;
|
|
47
|
+
}
|
|
48
|
+
else if (char === '/' && next === '*') {
|
|
49
|
+
let depth = 0;
|
|
50
|
+
do {
|
|
51
|
+
if (at >= statement.length)
|
|
52
|
+
unclosed('comment');
|
|
53
|
+
if (statement.startsWith('/*', at)) {
|
|
54
|
+
depth += 1;
|
|
55
|
+
at += 2;
|
|
56
|
+
}
|
|
57
|
+
else if (statement.startsWith('*/', at)) {
|
|
58
|
+
depth -= 1;
|
|
59
|
+
at += 2;
|
|
60
|
+
}
|
|
61
|
+
else
|
|
62
|
+
at += 1;
|
|
63
|
+
} while (depth > 0);
|
|
64
|
+
}
|
|
65
|
+
else if (char === "'" ||
|
|
66
|
+
((char === 'N' || char === 'n') && next === "'")) {
|
|
67
|
+
const open = char === "'" ? at + 1 : at + 2;
|
|
68
|
+
const end = delimited(open, "'");
|
|
69
|
+
if (end === -1)
|
|
70
|
+
unclosed('string');
|
|
71
|
+
found.push({ type: 'string', text: statement.slice(at, end + 1) });
|
|
72
|
+
at = end + 1;
|
|
73
|
+
}
|
|
74
|
+
else if (char === '"' || char === '[') {
|
|
75
|
+
const end = delimited(at + 1, char === '"' ? '"' : ']');
|
|
76
|
+
if (end === -1)
|
|
77
|
+
unclosed('quoted name');
|
|
78
|
+
found.push({ type: 'quoted', text: statement.slice(at, end + 1) });
|
|
79
|
+
at = end + 1;
|
|
80
|
+
}
|
|
81
|
+
else if (/\d/.test(char) || (char === '.' && /\d/.test(next))) {
|
|
82
|
+
NUMBER.lastIndex = at;
|
|
83
|
+
const number = NUMBER.exec(statement)?.[0] ?? char;
|
|
84
|
+
found.push({ type: 'number', text: number });
|
|
85
|
+
at += number.length;
|
|
86
|
+
}
|
|
87
|
+
else if (WORD_START.test(char)) {
|
|
88
|
+
let end = at + 1;
|
|
89
|
+
while (WORD.test(statement[end] ?? ''))
|
|
90
|
+
end += 1;
|
|
91
|
+
const text = statement.slice(at, end);
|
|
92
|
+
BATCH_END.lastIndex = end;
|
|
93
|
+
if (first && text.toUpperCase() === 'GO' && BATCH_END.test(statement))
|
|
94
|
+
throw new Error(`An element of a declaration holds one statement: ${statement}`);
|
|
95
|
+
found.push({ type: 'word', text });
|
|
96
|
+
at = end;
|
|
97
|
+
}
|
|
98
|
+
else if (OPERATOR.test(char)) {
|
|
99
|
+
let end = at + 1;
|
|
100
|
+
while (OPERATOR.test(statement[end] ?? '') &&
|
|
101
|
+
!statement.startsWith('--', end) &&
|
|
102
|
+
!statement.startsWith('/*', end))
|
|
103
|
+
end += 1;
|
|
104
|
+
found.push({ type: 'operator', text: statement.slice(at, end) });
|
|
105
|
+
at = end;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
found.push({ type: 'symbol', text: char });
|
|
109
|
+
at += 1;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (found.at(-1)?.text === ';')
|
|
113
|
+
found.pop();
|
|
114
|
+
return found;
|
|
115
|
+
}
|
|
116
|
+
// The SHA-256 of the tokens, each followed by a byte that no token holds (ADR 0010).
|
|
117
|
+
function checksum(found) {
|
|
118
|
+
const hash = createHash('sha256');
|
|
119
|
+
for (const { text } of found)
|
|
120
|
+
hash.update(`${text}\0`);
|
|
121
|
+
return hash.digest('hex');
|
|
122
|
+
}
|
|
123
|
+
const KINDS = new Map([
|
|
124
|
+
['TABLE', 'table'],
|
|
125
|
+
['INDEX', 'index'],
|
|
126
|
+
['VIEW', 'view'],
|
|
127
|
+
['SEQUENCE', 'sequence'],
|
|
128
|
+
['FUNCTION', 'function'],
|
|
129
|
+
['PROCEDURE', 'procedure'],
|
|
130
|
+
['PROC', 'procedure'],
|
|
131
|
+
['SCHEMA', 'schema'],
|
|
132
|
+
]);
|
|
133
|
+
// The body of a function or a procedure runs to the end of its batch, so it
|
|
134
|
+
// can hold statements of its own; each other kind is one statement.
|
|
135
|
+
const MODULES = new Set(['function', 'procedure']);
|
|
136
|
+
// Reads the kind and the qualified name from the head of a statement, and
|
|
137
|
+
// refuses a head it cannot read (ADR 0011).
|
|
138
|
+
export function declared(statement) {
|
|
139
|
+
const found = tokens(statement);
|
|
140
|
+
let at = 0;
|
|
141
|
+
const unreadable = () => {
|
|
142
|
+
throw new Error(`A statement of a declaration must start with CREATE, a kind (TABLE, INDEX, VIEW, SEQUENCE, FUNCTION, PROCEDURE or SCHEMA) and its name: ${statement}`);
|
|
143
|
+
};
|
|
144
|
+
const notExists = () => {
|
|
145
|
+
throw new Error(`A declaration does not use IF NOT EXISTS: ${statement}`);
|
|
146
|
+
};
|
|
147
|
+
const word = (offset = 0) => {
|
|
148
|
+
const token = found[at + offset];
|
|
149
|
+
return token?.type === 'word' ? token.text.toUpperCase() : undefined;
|
|
150
|
+
};
|
|
151
|
+
const take = (expected) => {
|
|
152
|
+
if (word() !== expected)
|
|
153
|
+
return false;
|
|
154
|
+
at += 1;
|
|
155
|
+
return true;
|
|
156
|
+
};
|
|
157
|
+
const identifier = () => {
|
|
158
|
+
const token = found[at];
|
|
159
|
+
if (token?.type === 'word') {
|
|
160
|
+
at += 1;
|
|
161
|
+
return token.text;
|
|
162
|
+
}
|
|
163
|
+
if (token?.type === 'quoted') {
|
|
164
|
+
at += 1;
|
|
165
|
+
const close = token.text.startsWith('[') ? ']' : '"';
|
|
166
|
+
return token.text.slice(1, -1).replaceAll(close + close, close);
|
|
167
|
+
}
|
|
168
|
+
return unreadable();
|
|
169
|
+
};
|
|
170
|
+
const dot = () => {
|
|
171
|
+
const token = found[at];
|
|
172
|
+
if (token?.type !== 'symbol' || token.text !== '.')
|
|
173
|
+
return false;
|
|
174
|
+
at += 1;
|
|
175
|
+
return true;
|
|
176
|
+
};
|
|
177
|
+
const qualifiedName = () => {
|
|
178
|
+
const first = identifier();
|
|
179
|
+
if (!dot())
|
|
180
|
+
throw new Error(`A declared object needs a schema in its name: ${statement}`);
|
|
181
|
+
const name = identifier();
|
|
182
|
+
if (dot())
|
|
183
|
+
unreadable();
|
|
184
|
+
return { schema: first, name };
|
|
185
|
+
};
|
|
186
|
+
// IF NOT EXISTS (…) CREATE …, IF OBJECT_ID(…) IS NULL CREATE …: a guard
|
|
187
|
+
// hides a stale object behind its name, as IF NOT EXISTS does.
|
|
188
|
+
if (word() === 'IF')
|
|
189
|
+
notExists();
|
|
190
|
+
if (!take('CREATE'))
|
|
191
|
+
unreadable();
|
|
192
|
+
const orAlter = take('OR') ? take('ALTER') || unreadable() : false;
|
|
193
|
+
const unique = take('UNIQUE');
|
|
194
|
+
const clustering = take('CLUSTERED') || take('NONCLUSTERED');
|
|
195
|
+
const kind = KINDS.get(word() ?? '');
|
|
196
|
+
if (kind === undefined)
|
|
197
|
+
return unreadable();
|
|
198
|
+
at += 1;
|
|
199
|
+
if ((unique || clustering) && kind !== 'index')
|
|
200
|
+
unreadable();
|
|
201
|
+
if (orAlter && !['view', 'function', 'procedure'].includes(kind))
|
|
202
|
+
unreadable();
|
|
203
|
+
if (word() === 'IF' && word(1) === 'NOT' && word(2) === 'EXISTS')
|
|
204
|
+
notExists();
|
|
205
|
+
if (!MODULES.has(kind) &&
|
|
206
|
+
found.some(({ type, text }) => type === 'symbol' && text === ';'))
|
|
207
|
+
throw new Error(`An element of a declaration holds one statement: ${statement}`);
|
|
208
|
+
const sum = checksum(found);
|
|
209
|
+
if (kind === 'schema') {
|
|
210
|
+
const name = identifier();
|
|
211
|
+
if (at !== found.length)
|
|
212
|
+
throw new Error(`A declared schema has only its name: ${statement}`);
|
|
213
|
+
return {
|
|
214
|
+
statement,
|
|
215
|
+
kind,
|
|
216
|
+
object: { schema: name, name },
|
|
217
|
+
qualified: name,
|
|
218
|
+
checksum: sum,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
if (kind === 'index') {
|
|
222
|
+
const name = identifier();
|
|
223
|
+
if (dot())
|
|
224
|
+
unreadable();
|
|
225
|
+
if (!take('ON'))
|
|
226
|
+
unreadable();
|
|
227
|
+
const table = qualifiedName();
|
|
228
|
+
return {
|
|
229
|
+
statement,
|
|
230
|
+
kind,
|
|
231
|
+
object: { schema: table.schema, name },
|
|
232
|
+
qualified: `${table.schema}.${table.name}.${name}`,
|
|
233
|
+
table,
|
|
234
|
+
checksum: sum,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
const object = qualifiedName();
|
|
238
|
+
return {
|
|
239
|
+
statement,
|
|
240
|
+
kind,
|
|
241
|
+
object,
|
|
242
|
+
qualified: `${object.schema}.${object.name}`,
|
|
243
|
+
checksum: sum,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=sqlserver-statement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlserver-statement.js","sourceRoot":"","sources":["../../src/sqlserver/sqlserver-statement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAqCzC,MAAM,QAAQ,GAAG,kBAAkB,CAAC;AACpC,MAAM,UAAU,GAAG,qBAAqB,CAAC;AACzC,MAAM,IAAI,GAAG,yBAAyB,CAAC;AACvC,MAAM,MAAM,GACV,iEAAiE,CAAC;AACpE,0EAA0E;AAC1E,MAAM,SAAS,GAAG,+CAA+C,CAAC;AAElE,6EAA6E;AAC7E,6EAA6E;AAC7E,6EAA6E;AAC7E,6EAA6E;AAC7E,qCAAqC;AACrC,SAAS,MAAM,CAAC,SAAiB;IAC/B,MAAM,KAAK,GAAY,EAAE,CAAC;IAC1B,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,IAAI,SAAS,GAAG,IAAI,CAAC;IACrB,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAS,EAAE;QACvC,MAAM,IAAI,KAAK,CACb,gDAAgD,IAAI,KAAK,SAAS,EAAE,CACrE,CAAC;IACJ,CAAC,CAAC;IACF,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,KAAa,EAAU,EAAE;QACxD,IAAI,GAAG,GAAG,IAAI,CAAC;QACf,SAAS,CAAC;YACR,IAAI,GAAG,IAAI,SAAS,CAAC,MAAM;gBAAE,OAAO,CAAC,CAAC,CAAC;YACvC,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,KAAK,IAAI,SAAS,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,KAAK;gBAAE,GAAG,IAAI,CAAC,CAAC;iBAClE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CAAC,MAAM;YACrB,MAAM,IAAI,KAAK,CAAC,wCAAwC,SAAS,EAAE,CAAC,CAAC;QACvE,OAAO;YACL,SAAS;YACT,IAAI;YACJ,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE;YAC9B,SAAS,EAAE,IAAI;YACf,QAAQ,EAAE,GAAG;SACd,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACrB,MAAM,IAAI,GAAG,UAAU,EAAE,CAAC;QAC1B,IAAI,GAAG,EAAE;YAAE,UAAU,EAAE,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,UAAU,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,aAAa,EAAE,CAAC;QAC9B,OAAO;YACL,SAAS;YACT,IAAI;YACJ,MAAM,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE;YACtC,SAAS,EAAE,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,IAAI,IAAI,IAAI,EAAE;YAClD,KAAK;YACL,QAAQ,EAAE,GAAG;SACd,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC;IAC/B,OAAO;QACL,SAAS;QACT,IAAI;QACJ,MAAM;QACN,SAAS,EAAE,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE;QAC5C,QAAQ,EAAE,GAAG;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlserver.d.ts","sourceRoot":"","sources":["../src/sqlserver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,KAAK,YAAY,EACjB,KAAK,gBAAgB,GACtB,MAAM,sCAAsC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlserver.js","sourceRoot":"","sources":["../src/sqlserver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,GAGrB,MAAM,sCAAsC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/schema-drift",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.286",
|
|
4
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
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -43,6 +43,12 @@
|
|
|
43
43
|
"types": "./dist/sqlite.d.ts",
|
|
44
44
|
"import": "./dist/sqlite.js",
|
|
45
45
|
"default": "./dist/sqlite.js"
|
|
46
|
+
},
|
|
47
|
+
"./sqlserver": {
|
|
48
|
+
"@zukhruf/source": "./src/sqlserver.ts",
|
|
49
|
+
"types": "./dist/sqlserver.d.ts",
|
|
50
|
+
"import": "./dist/sqlserver.js",
|
|
51
|
+
"default": "./dist/sqlserver.js"
|
|
46
52
|
}
|
|
47
53
|
},
|
|
48
54
|
"files": [
|
|
@@ -55,12 +61,12 @@
|
|
|
55
61
|
"access": "public"
|
|
56
62
|
},
|
|
57
63
|
"dependencies": {
|
|
58
|
-
"@zukhruf/sqlite-open": "^0.8.
|
|
59
|
-
"@zukhruf/sqlite-transaction": "^0.8.
|
|
64
|
+
"@zukhruf/sqlite-open": "^0.8.286",
|
|
65
|
+
"@zukhruf/sqlite-transaction": "^0.8.286"
|
|
60
66
|
},
|
|
61
67
|
"devDependencies": {
|
|
62
|
-
"@zukhruf/fs": "^0.8.
|
|
63
|
-
"@zukhruf/parameterized-test": "^0.8.
|
|
64
|
-
"@zukhruf/testing": "^0.8.
|
|
68
|
+
"@zukhruf/fs": "^0.8.286",
|
|
69
|
+
"@zukhruf/parameterized-test": "^0.8.286",
|
|
70
|
+
"@zukhruf/testing": "^0.8.286"
|
|
65
71
|
}
|
|
66
72
|
}
|