@zukhruf/schema-drift 0.8.285 → 0.8.287
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 +158 -23
- package/dist/postgres/postgres-declaration.d.ts +3 -3
- package/dist/postgres/postgres-declaration.d.ts.map +1 -1
- package/dist/postgres/postgres-declaration.js +24 -19
- package/dist/postgres/postgres-declaration.js.map +1 -1
- 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 +550 -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
|
@@ -0,0 +1,550 @@
|
|
|
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, options = {}) {
|
|
72
|
+
return this.#report(this.#drifts((await this.#read(session, options)).rows));
|
|
73
|
+
}
|
|
74
|
+
/** Throws SchemaDriftError when the drift is not 'fits'. A package calls it when it opens (ADR 0007). */
|
|
75
|
+
async check(session, options = {}) {
|
|
76
|
+
const { drift, objects } = await this.drift(session, options);
|
|
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, ...queryOptions } = 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
|
+
// The transaction of the session takes no signal: an aborted signal
|
|
86
|
+
// stops apply before it begins one.
|
|
87
|
+
options.signal?.throwIfAborted();
|
|
88
|
+
await session.transaction(async (transaction) => {
|
|
89
|
+
await transaction.query(`SET XACT_ABORT ON;\n${LOCK}`, {}, queryOptions);
|
|
90
|
+
// The read inside the lock runs with XACT_ABORT off: under it, the
|
|
91
|
+
// error of a missing ledger would end the transaction and the lock.
|
|
92
|
+
const read = await this.#read(transaction, queryOptions, 'SET XACT_ABORT OFF;\n');
|
|
93
|
+
const drifts = this.#drifts(read.rows);
|
|
94
|
+
if (drifts.size === 0)
|
|
95
|
+
return;
|
|
96
|
+
const application = new Application(transaction, this.#statements, drifts, rows, queryOptions);
|
|
97
|
+
const made = await application.run();
|
|
98
|
+
if (!read.ledger)
|
|
99
|
+
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))`);
|
|
100
|
+
const written = this.#statements.filter((statement) => made.has(statement));
|
|
101
|
+
await application.query(`MERGE ${this.#ledger} WITH (HOLDLOCK) AS l
|
|
102
|
+
USING (VALUES ${written.map((_, index) => `(@n${index}, @k${index}, @c${index})`).join(', ')}) AS d (name, kind, checksum)
|
|
103
|
+
ON l.kind = d.kind AND l.name = d.name
|
|
104
|
+
WHEN MATCHED THEN UPDATE SET checksum = d.checksum, applied_at = SYSUTCDATETIME()
|
|
105
|
+
WHEN NOT MATCHED THEN INSERT (name, kind, checksum) VALUES (d.name, d.kind, d.checksum);`, Object.fromEntries(written.flatMap(({ qualified, kind, checksum }, index) => [
|
|
106
|
+
[`n${index}`, qualified],
|
|
107
|
+
[`k${index}`, kind],
|
|
108
|
+
[`c${index}`, checksum],
|
|
109
|
+
])));
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
// One query: the declared objects, whether the catalog lists each one, and
|
|
113
|
+
// the checksum of its ledger row. When the ledger table does not exist
|
|
114
|
+
// (error 208), one query of the catalog alone (ADR 0009).
|
|
115
|
+
async #read(session, options, prefix = '') {
|
|
116
|
+
if (this.#statements.length === 0)
|
|
117
|
+
return { rows: [], ledger: true };
|
|
118
|
+
const values = this.#statements.map((_, index) => `(@i${index}, @k${index}, @s${index}, @n${index}, @t${index}, @q${index}, @y${index})`);
|
|
119
|
+
const parameters = Object.fromEntries(this.#statements.flatMap((statement, index) => [
|
|
120
|
+
[`i${index}`, index],
|
|
121
|
+
[`k${index}`, statement.kind],
|
|
122
|
+
[`s${index}`, statement.object.schema],
|
|
123
|
+
[`n${index}`, statement.object.name],
|
|
124
|
+
[`t${index}`, statement.kind === 'index' ? statement.table.name : ''],
|
|
125
|
+
[`q${index}`, statement.qualified],
|
|
126
|
+
[`y${index}`, TYPES[statement.kind]],
|
|
127
|
+
]));
|
|
128
|
+
const query = (ledger) => session.query(`${prefix}SELECT d.position, ${PRESENT} AS present, ${ledger ? 'l.checksum' : 'CAST(NULL AS char(64))'} AS recorded
|
|
129
|
+
FROM (VALUES ${values.join(', ')}) AS d (position, kind, [schema], name, [table], qualified, types)
|
|
130
|
+
${ledger ? `LEFT JOIN ${this.#ledger} AS l ON l.kind = d.kind AND l.name = d.qualified` : ''}
|
|
131
|
+
ORDER BY d.position`, parameters, options);
|
|
132
|
+
try {
|
|
133
|
+
return { rows: await query(true), ledger: true };
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
if (!invalidObjectName(error))
|
|
137
|
+
throw error;
|
|
138
|
+
return { rows: await query(false), ledger: false };
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// A declared schema has only its name, so it is missing or it fits. Each
|
|
142
|
+
// other object fits when it exists and its ledger row has its checksum.
|
|
143
|
+
#drifts(rows) {
|
|
144
|
+
const drifts = new Map();
|
|
145
|
+
for (const row of rows) {
|
|
146
|
+
const statement = this.#statements[Number(row.position)];
|
|
147
|
+
if (statement === undefined)
|
|
148
|
+
continue;
|
|
149
|
+
if (row.present !== 1)
|
|
150
|
+
drifts.set(statement, 'missing');
|
|
151
|
+
else if (statement.kind !== 'schema' &&
|
|
152
|
+
row.recorded !== statement.checksum)
|
|
153
|
+
drifts.set(statement, 'stale');
|
|
154
|
+
}
|
|
155
|
+
return drifts;
|
|
156
|
+
}
|
|
157
|
+
#report(drifts) {
|
|
158
|
+
const objects = this.#statements.flatMap((statement) => {
|
|
159
|
+
const drift = drifts.get(statement);
|
|
160
|
+
return drift === undefined
|
|
161
|
+
? []
|
|
162
|
+
: [{ name: statement.qualified, kind: statement.kind, drift }];
|
|
163
|
+
});
|
|
164
|
+
if (objects.length === 0)
|
|
165
|
+
return { drift: 'fits', objects };
|
|
166
|
+
const none = objects.length === this.#statements.length &&
|
|
167
|
+
objects.every(({ drift }) => drift === 'missing');
|
|
168
|
+
return { drift: none ? 'missing' : 'stale', objects };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// One apply, inside the transaction and the lock: it works on the stale and
|
|
172
|
+
// the missing objects, in the order of the declaration (ADR 0012), and gives
|
|
173
|
+
// each declared object that it made. Each batch runs with XACT_ABORT on, so
|
|
174
|
+
// an error rolls the whole transaction back.
|
|
175
|
+
class Application {
|
|
176
|
+
#session;
|
|
177
|
+
#statements;
|
|
178
|
+
#drifts;
|
|
179
|
+
#rows;
|
|
180
|
+
#queryOptions;
|
|
181
|
+
#made = new Set();
|
|
182
|
+
#temporary = randomBytes(6).toHex();
|
|
183
|
+
#renamed = 0;
|
|
184
|
+
constructor(session, statements, drifts, rows, queryOptions) {
|
|
185
|
+
this.#session = session;
|
|
186
|
+
this.#statements = statements;
|
|
187
|
+
this.#drifts = drifts;
|
|
188
|
+
this.#rows = rows;
|
|
189
|
+
this.#queryOptions = queryOptions;
|
|
190
|
+
}
|
|
191
|
+
async run() {
|
|
192
|
+
for (const statement of this.#statements) {
|
|
193
|
+
if (this.#made.has(statement))
|
|
194
|
+
continue;
|
|
195
|
+
const drift = this.#drifts.get(statement);
|
|
196
|
+
if (drift === 'missing')
|
|
197
|
+
await this.#make(statement);
|
|
198
|
+
else if (drift === 'stale')
|
|
199
|
+
await this.#replace(statement);
|
|
200
|
+
}
|
|
201
|
+
return this.#made;
|
|
202
|
+
}
|
|
203
|
+
query(sql, parameters = {}) {
|
|
204
|
+
return this.#session.query(`SET XACT_ABORT ON;\n${sql}`, parameters, this.#queryOptions);
|
|
205
|
+
}
|
|
206
|
+
async #replace(statement) {
|
|
207
|
+
const name = qualify(statement.object);
|
|
208
|
+
switch (statement.kind) {
|
|
209
|
+
case 'table':
|
|
210
|
+
await this.#tables(this.#rows === 'keep'
|
|
211
|
+
? [statement]
|
|
212
|
+
: await this.#referring(statement));
|
|
213
|
+
return;
|
|
214
|
+
case 'view':
|
|
215
|
+
await this.#view(statement);
|
|
216
|
+
return;
|
|
217
|
+
case 'sequence':
|
|
218
|
+
await this.#sequence(statement);
|
|
219
|
+
return;
|
|
220
|
+
case 'index':
|
|
221
|
+
await this.query(`DROP INDEX ${quote(statement.object.name)} ON ${qualify(statement.table)}`);
|
|
222
|
+
break;
|
|
223
|
+
case 'function':
|
|
224
|
+
await this.query(`DROP FUNCTION ${name}`);
|
|
225
|
+
break;
|
|
226
|
+
case 'procedure':
|
|
227
|
+
await this.query(`DROP PROCEDURE ${name}`);
|
|
228
|
+
break;
|
|
229
|
+
case 'schema':
|
|
230
|
+
// A declared schema has only its name: it is missing or it fits.
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
await this.#make(statement);
|
|
234
|
+
}
|
|
235
|
+
// The stale table, and each declared table that refers to one of them, so
|
|
236
|
+
// no kept row refers to a row that is gone (rows: 'replace').
|
|
237
|
+
async #referring(table) {
|
|
238
|
+
const group = [table];
|
|
239
|
+
for (let index = 0; index < group.length; index += 1) {
|
|
240
|
+
const referred = group[index];
|
|
241
|
+
if (referred === undefined)
|
|
242
|
+
break;
|
|
243
|
+
const referrers = await this.query(`SELECT s.name AS [schema], o.name
|
|
244
|
+
FROM sys.foreign_keys AS k
|
|
245
|
+
JOIN sys.objects AS o ON o.object_id = k.parent_object_id
|
|
246
|
+
JOIN sys.schemas AS s ON s.schema_id = o.schema_id
|
|
247
|
+
WHERE k.referenced_object_id = OBJECT_ID(@table) AND k.parent_object_id <> k.referenced_object_id`, { table: qualify(referred.object) });
|
|
248
|
+
for (const referrer of referrers) {
|
|
249
|
+
const declaredTable = this.#statements.find((statement) => statement.kind === 'table' &&
|
|
250
|
+
sameName(catalogName(referrer), statement.object));
|
|
251
|
+
if (declaredTable !== undefined && !group.includes(declaredTable))
|
|
252
|
+
group.push(declaredTable);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return group.toSorted((a, b) => this.#statements.indexOf(a) - this.#statements.indexOf(b));
|
|
256
|
+
}
|
|
257
|
+
// Replaces (rows: 'replace') or rebuilds (rows: 'keep') each table of the
|
|
258
|
+
// group, and makes again what depends on them (ADR 0012).
|
|
259
|
+
async #tables(group) {
|
|
260
|
+
const captures = [];
|
|
261
|
+
for (const table of group)
|
|
262
|
+
captures.push(await this.#capture(table.object));
|
|
263
|
+
const views = merged(captures.flatMap(({ views }) => views));
|
|
264
|
+
const foreignKeys = captures
|
|
265
|
+
.flatMap(({ foreignKeys }) => foreignKeys)
|
|
266
|
+
.filter(({ table }) => !group.some(({ object }) => sameName(table, object)));
|
|
267
|
+
await this.#dropBound(views);
|
|
268
|
+
for (const { table, name } of foreignKeys)
|
|
269
|
+
await this.query(`ALTER TABLE ${qualify(table)} DROP CONSTRAINT ${quote(name)}`);
|
|
270
|
+
const kept = new Map();
|
|
271
|
+
if (this.#rows === 'keep')
|
|
272
|
+
for (const [index, table] of group.entries()) {
|
|
273
|
+
const capture = captures[index];
|
|
274
|
+
if (capture === undefined)
|
|
275
|
+
continue;
|
|
276
|
+
// The old table and its constraints go away first, so each name
|
|
277
|
+
// that the statement makes is free (ADR 0012). An index name is
|
|
278
|
+
// unique only in its table, so the indexes keep theirs.
|
|
279
|
+
const old = { schema: table.object.schema, name: this.#away() };
|
|
280
|
+
await this.#rename(table.object, old.name);
|
|
281
|
+
for (const constraint of capture.constraints)
|
|
282
|
+
await this.#rename({ schema: table.object.schema, name: constraint }, this.#away());
|
|
283
|
+
kept.set(table, old);
|
|
284
|
+
}
|
|
285
|
+
else
|
|
286
|
+
for (const table of group.toReversed())
|
|
287
|
+
await this.query(`DROP TABLE ${qualify(table.object)}`);
|
|
288
|
+
for (const table of group)
|
|
289
|
+
await this.#make(table);
|
|
290
|
+
for (const [index, table] of group.entries()) {
|
|
291
|
+
const old = kept.get(table);
|
|
292
|
+
const capture = captures[index];
|
|
293
|
+
if (old === undefined || capture === undefined)
|
|
294
|
+
continue;
|
|
295
|
+
await this.#copy(table.object, old, capture.key);
|
|
296
|
+
await this.query(`DROP TABLE ${qualify(old)}`);
|
|
297
|
+
}
|
|
298
|
+
for (const [index, table] of group.entries()) {
|
|
299
|
+
const capture = captures[index];
|
|
300
|
+
if (capture === undefined)
|
|
301
|
+
continue;
|
|
302
|
+
for (const statement of this.#statements)
|
|
303
|
+
if (statement.kind === 'index' &&
|
|
304
|
+
sameName(statement.table, table.object))
|
|
305
|
+
await this.#make(statement);
|
|
306
|
+
for (const index of capture.indexes)
|
|
307
|
+
if (!this.#declaresIndex(table.object, index.name))
|
|
308
|
+
await this.query(index.definition);
|
|
309
|
+
await this.#triggers(capture.triggers);
|
|
310
|
+
}
|
|
311
|
+
for (const { table, name, definition, disabled } of foreignKeys) {
|
|
312
|
+
await this.query(`ALTER TABLE ${qualify(table)} WITH CHECK ADD CONSTRAINT ${quote(name)} ${definition}`);
|
|
313
|
+
if (disabled)
|
|
314
|
+
await this.query(`ALTER TABLE ${qualify(table)} NOCHECK CONSTRAINT ${quote(name)}`);
|
|
315
|
+
}
|
|
316
|
+
await this.#views(views);
|
|
317
|
+
}
|
|
318
|
+
// Copies the columns that both tables have, by name, in the order of the
|
|
319
|
+
// old table's primary key, with the stored values of an identity column.
|
|
320
|
+
// SQL Server moves the identity past the largest value that it inserts.
|
|
321
|
+
async #copy(table, old, key) {
|
|
322
|
+
const columns = await this.query(`SELECT n.name, n.is_identity AS [identity]
|
|
323
|
+
FROM sys.columns AS n
|
|
324
|
+
JOIN sys.columns AS o ON o.object_id = OBJECT_ID(@old) AND o.name = n.name
|
|
325
|
+
WHERE n.object_id = OBJECT_ID(@table) AND n.is_computed = 0 AND n.generated_always_type = 0 AND n.system_type_id <> 189
|
|
326
|
+
ORDER BY n.column_id`, { table: qualify(table), old: qualify(old) });
|
|
327
|
+
if (columns.length === 0)
|
|
328
|
+
return;
|
|
329
|
+
const names = columns.map(({ name }) => quote(String(name))).join(', ');
|
|
330
|
+
const order = key.length === 0 ? '' : ` ORDER BY ${key.map(quote).join(', ')}`;
|
|
331
|
+
const insert = `INSERT INTO ${qualify(table)} (${names}) SELECT ${names} FROM ${qualify(old)}${order};`;
|
|
332
|
+
await this.query(columns.some(({ identity }) => identity === true)
|
|
333
|
+
? `SET IDENTITY_INSERT ${qualify(table)} ON;\n${insert}\nSET IDENTITY_INSERT ${qualify(table)} OFF;`
|
|
334
|
+
: insert);
|
|
335
|
+
}
|
|
336
|
+
// A stale view is dropped with the schema-bound views that read it, made
|
|
337
|
+
// from its statement, and the views that read it are made again or
|
|
338
|
+
// refreshed.
|
|
339
|
+
async #view(view) {
|
|
340
|
+
const views = await this.#dependents(view.object);
|
|
341
|
+
const triggers = await this.#triggersOf(view.object);
|
|
342
|
+
await this.#dropBound(views);
|
|
343
|
+
await this.query(`DROP VIEW ${qualify(view.object)}`);
|
|
344
|
+
await this.#make(view);
|
|
345
|
+
await this.#triggers(triggers);
|
|
346
|
+
await this.#views(views);
|
|
347
|
+
}
|
|
348
|
+
// A stale sequence is made from its statement. With rows: 'keep', it
|
|
349
|
+
// keeps its last value: its next value follows the last one given.
|
|
350
|
+
async #sequence(sequence) {
|
|
351
|
+
const name = qualify(sequence.object);
|
|
352
|
+
const [last] = this.#rows === 'keep'
|
|
353
|
+
? await this.query(`SELECT CONVERT(nvarchar(60), last_used_value) AS value FROM sys.sequences WHERE object_id = OBJECT_ID(@name)`, { name })
|
|
354
|
+
: [];
|
|
355
|
+
await this.query(`DROP SEQUENCE ${name}`);
|
|
356
|
+
await this.#make(sequence);
|
|
357
|
+
if (typeof last?.value === 'string')
|
|
358
|
+
await this.query(`DECLARE @restart nvarchar(max) = N'ALTER SEQUENCE ${name.replaceAll("'", "''")} RESTART WITH '
|
|
359
|
+
+ CONVERT(nvarchar(60), CONVERT(decimal(38, 0), @last) + (SELECT CONVERT(decimal(38, 0), increment) FROM sys.sequences WHERE object_id = OBJECT_ID(@name)));
|
|
360
|
+
EXEC sys.sp_executesql @restart;`, { name, last: last.value });
|
|
361
|
+
}
|
|
362
|
+
// Drops the schema-bound views among the views, the views that read
|
|
363
|
+
// others first. SQL Server refuses to drop or rename what they read
|
|
364
|
+
// (errors 3729, 15336); a view that is not schema-bound stays.
|
|
365
|
+
async #dropBound(views) {
|
|
366
|
+
for (const view of views.toReversed())
|
|
367
|
+
if (view.schemaBound)
|
|
368
|
+
await this.query(`DROP VIEW ${qualify(view.object)}`);
|
|
369
|
+
}
|
|
370
|
+
// Makes each dropped view again, the views that others read first: a
|
|
371
|
+
// declared view from its statement, any other view from its definition.
|
|
372
|
+
// Each view that is not schema-bound gets sp_refreshview.
|
|
373
|
+
async #views(views) {
|
|
374
|
+
for (const view of views) {
|
|
375
|
+
if (!view.schemaBound) {
|
|
376
|
+
await this.query('EXEC sys.sp_refreshview @name', {
|
|
377
|
+
name: qualify(view.object),
|
|
378
|
+
});
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
const statement = this.#statements.find((candidate) => candidate.kind === 'view' && sameName(view.object, candidate.object));
|
|
382
|
+
if (statement !== undefined)
|
|
383
|
+
await this.#make(statement);
|
|
384
|
+
else
|
|
385
|
+
await this.#module(view);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
async #triggers(triggers) {
|
|
389
|
+
for (const trigger of triggers) {
|
|
390
|
+
await this.#module(trigger);
|
|
391
|
+
if (trigger.disabled)
|
|
392
|
+
await this.query(`DISABLE TRIGGER ${qualify(trigger.object)} ON ${qualify(trigger.parent)}`);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
async #capture(table) {
|
|
396
|
+
const name = qualify(table);
|
|
397
|
+
const foreignKeys = await this.query(`SELECT s.name AS [schema], o.name, k.name AS [constraint], k.is_disabled AS disabled,
|
|
398
|
+
k.delete_referential_action_desc AS on_delete, k.update_referential_action_desc AS on_update,
|
|
399
|
+
pc.name AS [column], rc.name AS referenced
|
|
400
|
+
FROM sys.foreign_keys AS k
|
|
401
|
+
JOIN sys.objects AS o ON o.object_id = k.parent_object_id
|
|
402
|
+
JOIN sys.schemas AS s ON s.schema_id = o.schema_id
|
|
403
|
+
JOIN sys.foreign_key_columns AS fc ON fc.constraint_object_id = k.object_id
|
|
404
|
+
JOIN sys.columns AS pc ON pc.object_id = fc.parent_object_id AND pc.column_id = fc.parent_column_id
|
|
405
|
+
JOIN sys.columns AS rc ON rc.object_id = fc.referenced_object_id AND rc.column_id = fc.referenced_column_id
|
|
406
|
+
WHERE k.referenced_object_id = OBJECT_ID(@table) AND k.parent_object_id <> k.referenced_object_id
|
|
407
|
+
ORDER BY s.name, o.name, k.name, fc.constraint_column_id`, { table: name });
|
|
408
|
+
const indexes = await this.query(`SELECT i.name, i.is_unique AS [unique], i.type_desc AS type, i.filter_definition AS filter,
|
|
409
|
+
c.name AS [column], ic.is_descending_key AS descending, ic.is_included_column AS included
|
|
410
|
+
FROM sys.indexes AS i
|
|
411
|
+
JOIN sys.index_columns AS ic ON ic.object_id = i.object_id AND ic.index_id = i.index_id
|
|
412
|
+
JOIN sys.columns AS c ON c.object_id = ic.object_id AND c.column_id = ic.column_id
|
|
413
|
+
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
|
|
414
|
+
ORDER BY i.index_id, ic.is_included_column, ic.key_ordinal, ic.index_column_id`, { table: name });
|
|
415
|
+
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 });
|
|
416
|
+
const key = await this.query(`SELECT c.name
|
|
417
|
+
FROM sys.indexes AS i
|
|
418
|
+
JOIN sys.index_columns AS ic ON ic.object_id = i.object_id AND ic.index_id = i.index_id
|
|
419
|
+
JOIN sys.columns AS c ON c.object_id = ic.object_id AND c.column_id = ic.column_id
|
|
420
|
+
WHERE i.object_id = OBJECT_ID(@table) AND i.is_primary_key = 1 AND ic.key_ordinal > 0
|
|
421
|
+
ORDER BY ic.key_ordinal`, { table: name });
|
|
422
|
+
return {
|
|
423
|
+
views: await this.#dependents(table),
|
|
424
|
+
foreignKeys: grouped(foreignKeys, ({ schema, name, constraint }) => [schema, name, constraint].join('.')).map((columns) => {
|
|
425
|
+
const [first] = columns;
|
|
426
|
+
const action = (value) => String(value).replaceAll('_', ' ');
|
|
427
|
+
return {
|
|
428
|
+
table: catalogName(first ?? {}),
|
|
429
|
+
name: String(first?.constraint),
|
|
430
|
+
disabled: first?.disabled === true,
|
|
431
|
+
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)}`,
|
|
432
|
+
};
|
|
433
|
+
}),
|
|
434
|
+
indexes: grouped(indexes, ({ name }) => String(name)).map((columns) => {
|
|
435
|
+
const [first] = columns;
|
|
436
|
+
const keys = columns
|
|
437
|
+
.filter(({ included }) => included !== true)
|
|
438
|
+
.map(({ column, descending }) => `${quote(String(column))} ${descending === true ? 'DESC' : 'ASC'}`);
|
|
439
|
+
const included = columns
|
|
440
|
+
.filter(({ included }) => included === true)
|
|
441
|
+
.map(({ column }) => quote(String(column)));
|
|
442
|
+
return {
|
|
443
|
+
name: String(first?.name),
|
|
444
|
+
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}` : ''}`,
|
|
445
|
+
};
|
|
446
|
+
}),
|
|
447
|
+
constraints: constraints.map(({ name }) => String(name)),
|
|
448
|
+
triggers: await this.#triggersOf(table),
|
|
449
|
+
key: key.map(({ name }) => String(name)),
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
// The views that read the object, and the views that read those, the
|
|
453
|
+
// views that others read first.
|
|
454
|
+
async #dependents(object) {
|
|
455
|
+
const rows = await this.query(`WITH dependents (id, depth) AS (
|
|
456
|
+
SELECT d.referencing_id, 1
|
|
457
|
+
FROM sys.sql_expression_dependencies AS d
|
|
458
|
+
JOIN sys.views AS v ON v.object_id = d.referencing_id
|
|
459
|
+
WHERE d.referenced_id = OBJECT_ID(@object)
|
|
460
|
+
UNION ALL
|
|
461
|
+
SELECT d.referencing_id, dependents.depth + 1
|
|
462
|
+
FROM dependents
|
|
463
|
+
JOIN sys.sql_expression_dependencies AS d ON d.referenced_id = dependents.id
|
|
464
|
+
JOIN sys.views AS v ON v.object_id = d.referencing_id
|
|
465
|
+
WHERE d.referencing_id <> dependents.id
|
|
466
|
+
)
|
|
467
|
+
SELECT s.name AS [schema], v.name, x.depth, m.definition, m.is_schema_bound AS bound,
|
|
468
|
+
m.uses_ansi_nulls AS ansi_nulls, m.uses_quoted_identifier AS quoted_identifier
|
|
469
|
+
FROM (SELECT id, MAX(depth) AS depth FROM dependents GROUP BY id) AS x
|
|
470
|
+
JOIN sys.views AS v ON v.object_id = x.id
|
|
471
|
+
JOIN sys.schemas AS s ON s.schema_id = v.schema_id
|
|
472
|
+
JOIN sys.sql_modules AS m ON m.object_id = v.object_id
|
|
473
|
+
ORDER BY x.depth, s.name, v.name`, { object: qualify(object) });
|
|
474
|
+
return rows.map((row) => ({
|
|
475
|
+
object: catalogName(row),
|
|
476
|
+
depth: Number(row.depth),
|
|
477
|
+
schemaBound: row.bound === true,
|
|
478
|
+
...module(row),
|
|
479
|
+
}));
|
|
480
|
+
}
|
|
481
|
+
async #triggersOf(object) {
|
|
482
|
+
const rows = await this.query(`SELECT s.name AS [schema], t.name, t.is_disabled AS disabled, m.definition,
|
|
483
|
+
m.uses_ansi_nulls AS ansi_nulls, m.uses_quoted_identifier AS quoted_identifier
|
|
484
|
+
FROM sys.triggers AS t
|
|
485
|
+
JOIN sys.objects AS o ON o.object_id = t.object_id
|
|
486
|
+
JOIN sys.schemas AS s ON s.schema_id = o.schema_id
|
|
487
|
+
JOIN sys.sql_modules AS m ON m.object_id = t.object_id
|
|
488
|
+
WHERE t.parent_id = OBJECT_ID(@object)
|
|
489
|
+
ORDER BY t.name`, { object: qualify(object) });
|
|
490
|
+
return rows.map((row) => ({
|
|
491
|
+
object: catalogName(row),
|
|
492
|
+
parent: object,
|
|
493
|
+
disabled: row.disabled === true,
|
|
494
|
+
...module(row),
|
|
495
|
+
}));
|
|
496
|
+
}
|
|
497
|
+
// Runs the text of a module of the catalog again, as its own batch and
|
|
498
|
+
// with the SET options that it was made under.
|
|
499
|
+
async #module({ definition, ansiNulls, quotedIdentifier, }) {
|
|
500
|
+
await this.query(`SET ANSI_NULLS ${ansiNulls ? 'ON' : 'OFF'};
|
|
501
|
+
SET QUOTED_IDENTIFIER ${quotedIdentifier ? 'ON' : 'OFF'};
|
|
502
|
+
EXEC sys.sp_executesql @definition;`, { definition });
|
|
503
|
+
}
|
|
504
|
+
async #rename(object, name) {
|
|
505
|
+
await this.query(`EXEC sys.sp_rename @objname = @object, @newname = @name, @objtype = N'OBJECT'`, { object: qualify(object), name });
|
|
506
|
+
}
|
|
507
|
+
#declaresIndex(table, name) {
|
|
508
|
+
return this.#statements.some((statement) => statement.kind === 'index' &&
|
|
509
|
+
sameName(statement.table, table) &&
|
|
510
|
+
statement.object.name === name);
|
|
511
|
+
}
|
|
512
|
+
#away() {
|
|
513
|
+
this.#renamed += 1;
|
|
514
|
+
return `zukhruf_schema_drift_${this.#temporary}_${this.#renamed}`;
|
|
515
|
+
}
|
|
516
|
+
// CREATE VIEW, FUNCTION, PROCEDURE and SCHEMA must be the only statement
|
|
517
|
+
// of their batch, so each statement runs through sp_executesql.
|
|
518
|
+
async #make(statement) {
|
|
519
|
+
await this.query('EXEC sys.sp_executesql @statement', {
|
|
520
|
+
statement: statement.statement,
|
|
521
|
+
});
|
|
522
|
+
this.#made.add(statement);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
function catalogName(row) {
|
|
526
|
+
return { schema: String(row.schema), name: String(row.name) };
|
|
527
|
+
}
|
|
528
|
+
function module(row) {
|
|
529
|
+
return {
|
|
530
|
+
definition: String(row.definition),
|
|
531
|
+
ansiNulls: row.ansi_nulls === true,
|
|
532
|
+
quotedIdentifier: row.quoted_identifier === true,
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
// The rows of each key, in the order of their first row.
|
|
536
|
+
function grouped(rows, key) {
|
|
537
|
+
return [...Map.groupBy(rows, key).values()];
|
|
538
|
+
}
|
|
539
|
+
// The views of several tables, each once, at its deepest place.
|
|
540
|
+
function merged(views) {
|
|
541
|
+
const deepest = new Map();
|
|
542
|
+
for (const view of views) {
|
|
543
|
+
const key = qualify(view.object);
|
|
544
|
+
const known = deepest.get(key);
|
|
545
|
+
if (known === undefined || known.depth < view.depth)
|
|
546
|
+
deepest.set(key, view);
|
|
547
|
+
}
|
|
548
|
+
return [...deepest.values()].toSorted((a, b) => a.depth - b.depth);
|
|
549
|
+
}
|
|
550
|
+
//# sourceMappingURL=sqlserver-declaration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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E,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"}
|