@zukhruf/schema-drift 0.0.0-stage → 0.8.283
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/LICENSE +21 -0
- package/README.md +725 -2
- package/dist/drift.d.ts +18 -0
- package/dist/drift.d.ts.map +1 -0
- package/dist/drift.js +2 -0
- package/dist/drift.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/postgres/postgres-declaration.d.ts +41 -0
- package/dist/postgres/postgres-declaration.d.ts.map +1 -0
- package/dist/postgres/postgres-declaration.js +504 -0
- package/dist/postgres/postgres-declaration.js.map +1 -0
- package/dist/postgres/postgres-statement.d.ts +19 -0
- package/dist/postgres/postgres-statement.d.ts.map +1 -0
- package/dist/postgres/postgres-statement.js +253 -0
- package/dist/postgres/postgres-statement.js.map +1 -0
- package/dist/postgres.d.ts +2 -0
- package/dist/postgres.d.ts.map +1 -0
- package/dist/postgres.js +2 -0
- package/dist/postgres.js.map +1 -0
- package/dist/schema-drift-error.d.ts +11 -0
- package/dist/schema-drift-error.d.ts.map +1 -0
- package/dist/schema-drift-error.js +17 -0
- package/dist/schema-drift-error.js.map +1 -0
- package/dist/sqlite/sqlite-declaration.d.ts +14 -0
- package/dist/sqlite/sqlite-declaration.d.ts.map +1 -0
- package/dist/sqlite/sqlite-declaration.js +407 -0
- package/dist/sqlite/sqlite-declaration.js.map +1 -0
- package/dist/sqlite.d.ts +2 -0
- package/dist/sqlite.d.ts.map +1 -0
- package/dist/sqlite.js +2 -0
- package/dist/sqlite.js.map +1 -0
- package/package.json +64 -4
package/dist/drift.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** How a database stores the objects of a declaration: none of them, each one as declared, or anything else. */
|
|
2
|
+
export type Drift = 'missing' | 'stale' | 'fits';
|
|
3
|
+
/** What apply does with the rows of a stale table. It has no default. */
|
|
4
|
+
export type Rows = 'replace' | 'keep';
|
|
5
|
+
export type ObjectKind = 'table' | 'virtual table' | 'trigger' | 'index' | 'view' | 'sequence' | 'function' | 'procedure' | 'schema';
|
|
6
|
+
/** One declared object that does not fit. */
|
|
7
|
+
export type DriftedObject = {
|
|
8
|
+
/** Qualified on Postgres and SQL Server: '_warehouse.extraction_coverage'. An index on SQL Server: 'dbo.runs.runs_by_name'. */
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly kind: ObjectKind;
|
|
11
|
+
readonly drift: 'missing' | 'stale';
|
|
12
|
+
};
|
|
13
|
+
export type DriftReport = {
|
|
14
|
+
readonly drift: Drift;
|
|
15
|
+
/** Each missing or stale object, in the order of the declaration. Empty when drift is 'fits'. */
|
|
16
|
+
readonly objects: readonly DriftedObject[];
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=drift.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drift.d.ts","sourceRoot":"","sources":["../src/drift.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,MAAM,MAAM,KAAK,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AAEjD,yEAAyE;AACzE,MAAM,MAAM,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC;AAEtC,MAAM,MAAM,UAAU,GAClB,OAAO,GACP,eAAe,GACf,SAAS,GACT,OAAO,GACP,MAAM,GACN,UAAU,GACV,UAAU,GACV,WAAW,GACX,QAAQ,CAAC;AAEb,6CAA6C;AAC7C,MAAM,MAAM,aAAa,GAAG;IAC1B,+HAA+H;IAC/H,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,iGAAiG;IACjG,QAAQ,CAAC,OAAO,EAAE,SAAS,aAAa,EAAE,CAAC;CAC5C,CAAC"}
|
package/dist/drift.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drift.js","sourceRoot":"","sources":["../src/drift.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,KAAK,EACL,aAAa,EACb,WAAW,EACX,UAAU,EACV,IAAI,GACL,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,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 positional, `$1` for the first.
|
|
8
|
+
* `transaction(work)` runs the work on one connection in one transaction.
|
|
9
|
+
* A copy of the PostgresSession of @zukhruf/checkpoint
|
|
10
|
+
* (docs/copied-session-ports.md).
|
|
11
|
+
*/
|
|
12
|
+
export type PostgresSession = {
|
|
13
|
+
query(sql: string, parameters: readonly unknown[], options?: SignalOption): Promise<readonly Record<string, unknown>[]>;
|
|
14
|
+
transaction(work: (session: PostgresSession) => Promise<void>): Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The tables, indexes, views, sequences, functions, procedures and schemas
|
|
18
|
+
* that a package owns in a Postgres 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 under the
|
|
24
|
+
* lock of the package (ADR 0014).
|
|
25
|
+
*/
|
|
26
|
+
export declare class PostgresDeclaration {
|
|
27
|
+
#private;
|
|
28
|
+
/** ledgerSchema is the schema of the ledger table, as the catalog names it. Default: 'public'. */
|
|
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: PostgresSession): Promise<DriftReport>;
|
|
34
|
+
/** Throws SchemaDriftError when the drift is not 'fits'. A package calls it when it opens (ADR 0007). */
|
|
35
|
+
check(session: PostgresSession): Promise<void>;
|
|
36
|
+
/** The host chooses rows when it applies. It has no default. */
|
|
37
|
+
apply(session: PostgresSession, options: {
|
|
38
|
+
readonly rows: Rows;
|
|
39
|
+
}): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=postgres-declaration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-declaration.d.ts","sourceRoot":"","sources":["../../src/postgres/postgres-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,eAAe,GAAG;IAC5B,KAAK,CACH,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,SAAS,OAAO,EAAE,EAC9B,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IAC/C,WAAW,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/E,CAAC;AAkDF;;;;;;;;;GASG;AACH,qBAAa,mBAAmB;;IAI9B,kGAAkG;IAClG,YACE,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,EAY7C;IAED,wHAAwH;IAClH,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC,CAS1D;IAED,yGAAyG;IACnG,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAGnD;IAED,gEAAgE;IAC1D,KAAK,CACT,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;KAAE,GAC/B,OAAO,CAAC,IAAI,CAAC,CAyDf;CA6DF"}
|
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { SchemaDriftError } from '../schema-drift-error.js';
|
|
3
|
+
import { declared, } from './postgres-statement.js';
|
|
4
|
+
// The key of the lock of the package: the first 8 bytes of the SHA-256 of
|
|
5
|
+
// '@zukhruf/schema-drift' (48fe45db10fc03c1), as a signed bigint (ADR 0014).
|
|
6
|
+
const LOCK = '5259718222000423873';
|
|
7
|
+
const LEDGER = 'zukhruf_schema_drift';
|
|
8
|
+
// The relkind of pg_class that each kind of relation has.
|
|
9
|
+
const RELKINDS = {
|
|
10
|
+
table: 'rp',
|
|
11
|
+
index: 'iI',
|
|
12
|
+
view: 'v',
|
|
13
|
+
sequence: 'S',
|
|
14
|
+
function: '',
|
|
15
|
+
procedure: '',
|
|
16
|
+
schema: '',
|
|
17
|
+
};
|
|
18
|
+
// Whether the catalog lists the object of each row of d.
|
|
19
|
+
const PRESENT = `CASE d.kind
|
|
20
|
+
WHEN 'schema' THEN EXISTS (SELECT FROM pg_catalog.pg_namespace AS n WHERE n.nspname = d.name)
|
|
21
|
+
WHEN 'function' THEN EXISTS (SELECT FROM pg_catalog.pg_proc AS p JOIN pg_catalog.pg_namespace AS n ON n.oid = p.pronamespace WHERE n.nspname = d.schema AND p.proname = d.name AND p.prokind = 'f')
|
|
22
|
+
WHEN 'procedure' THEN EXISTS (SELECT FROM pg_catalog.pg_proc AS p JOIN pg_catalog.pg_namespace AS n ON n.oid = p.pronamespace WHERE n.nspname = d.schema AND p.proname = d.name AND p.prokind = 'p')
|
|
23
|
+
ELSE EXISTS (SELECT FROM pg_catalog.pg_class AS c JOIN pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace WHERE n.nspname = d.schema AND c.relname = d.name AND pg_catalog.strpos(d.relkinds, c.relkind::text) > 0)
|
|
24
|
+
END`;
|
|
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 undefinedTable(error) {
|
|
36
|
+
return (typeof error === 'object' &&
|
|
37
|
+
error !== null &&
|
|
38
|
+
'code' in error &&
|
|
39
|
+
error.code === '42P01');
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The tables, indexes, views, sequences, functions, procedures and schemas
|
|
43
|
+
* that a package owns in a Postgres 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 under the
|
|
49
|
+
* lock of the package (ADR 0014).
|
|
50
|
+
*/
|
|
51
|
+
export class PostgresDeclaration {
|
|
52
|
+
#statements;
|
|
53
|
+
#ledger;
|
|
54
|
+
/** ledgerSchema is the schema of the ledger table, as the catalog names it. Default: 'public'. */
|
|
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 = `${quote(options?.ledgerSchema ?? 'public')}.${quote(LEDGER)}`;
|
|
66
|
+
}
|
|
67
|
+
/** The drift of the declaration, and each declared object that is missing or stale, in the order of the declaration. */
|
|
68
|
+
async drift(session) {
|
|
69
|
+
let rows;
|
|
70
|
+
try {
|
|
71
|
+
rows = await this.#read(session, true);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (!undefinedTable(error))
|
|
75
|
+
throw error;
|
|
76
|
+
rows = await this.#read(session, false);
|
|
77
|
+
}
|
|
78
|
+
return this.#report(this.#drifts(rows));
|
|
79
|
+
}
|
|
80
|
+
/** Throws SchemaDriftError when the drift is not 'fits'. A package calls it when it opens (ADR 0007). */
|
|
81
|
+
async check(session) {
|
|
82
|
+
const { drift, objects } = await this.drift(session);
|
|
83
|
+
if (drift !== 'fits')
|
|
84
|
+
throw new SchemaDriftError(objects);
|
|
85
|
+
}
|
|
86
|
+
/** The host chooses rows when it applies. It has no default. */
|
|
87
|
+
async apply(session, options) {
|
|
88
|
+
const { rows } = options;
|
|
89
|
+
if (rows !== 'replace' && rows !== 'keep')
|
|
90
|
+
throw new TypeError(`apply needs rows: 'replace' or 'keep'. It has no default. It got ${String(rows)}.`);
|
|
91
|
+
await session.transaction(async (transaction) => {
|
|
92
|
+
await transaction.query(`SELECT pg_catalog.pg_advisory_xact_lock(${LOCK})`, []);
|
|
93
|
+
// The read inside the lock: a failed query would end the transaction,
|
|
94
|
+
// so the try of the ledger runs in a savepoint.
|
|
95
|
+
await transaction.query('SAVEPOINT zukhruf_schema_drift', []);
|
|
96
|
+
let read;
|
|
97
|
+
let ledger = true;
|
|
98
|
+
try {
|
|
99
|
+
read = await this.#read(transaction, true);
|
|
100
|
+
await transaction.query('RELEASE SAVEPOINT zukhruf_schema_drift', []);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
if (!undefinedTable(error))
|
|
104
|
+
throw error;
|
|
105
|
+
await transaction.query('ROLLBACK TO SAVEPOINT zukhruf_schema_drift', []);
|
|
106
|
+
read = await this.#read(transaction, false);
|
|
107
|
+
ledger = false;
|
|
108
|
+
}
|
|
109
|
+
const drifts = this.#drifts(read);
|
|
110
|
+
if (drifts.size === 0)
|
|
111
|
+
return;
|
|
112
|
+
const made = await new Application(transaction, this.#statements, drifts, rows).run();
|
|
113
|
+
if (!ledger)
|
|
114
|
+
await transaction.query(`CREATE TABLE ${this.#ledger} (name text NOT NULL, kind text NOT NULL, checksum text NOT NULL, applied_at timestamptz NOT NULL DEFAULT pg_catalog.now(), PRIMARY KEY (kind, name))`, []);
|
|
115
|
+
const written = this.#statements.filter((statement) => made.has(statement));
|
|
116
|
+
const rowPlaceholders = written.map((_, index) => `($${index * 3 + 1}, $${index * 3 + 2}, $${index * 3 + 3})`);
|
|
117
|
+
await transaction.query(`INSERT INTO ${this.#ledger} (name, kind, checksum) VALUES ${rowPlaceholders.join(', ')} ON CONFLICT (kind, name) DO UPDATE SET checksum = EXCLUDED.checksum, applied_at = EXCLUDED.applied_at`, written.flatMap(({ qualified, kind, checksum }) => [
|
|
118
|
+
qualified,
|
|
119
|
+
kind,
|
|
120
|
+
checksum,
|
|
121
|
+
]));
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
// One query: the declared objects, whether the catalog lists each one, and
|
|
125
|
+
// the checksum of its ledger row when the ledger is read.
|
|
126
|
+
async #read(session, ledger) {
|
|
127
|
+
if (this.#statements.length === 0)
|
|
128
|
+
return [];
|
|
129
|
+
const values = this.#statements.map((_, index) => `($${index * 6 + 1}::int, $${index * 6 + 2}::text, $${index * 6 + 3}::text, $${index * 6 + 4}::text, $${index * 6 + 5}::text, $${index * 6 + 6}::text)`);
|
|
130
|
+
return session.query(`SELECT d.position, ${PRESENT} AS present, ${ledger ? 'l.checksum' : 'NULL::text'} AS recorded
|
|
131
|
+
FROM (VALUES ${values.join(', ')}) AS d (position, kind, schema, name, qualified, relkinds)
|
|
132
|
+
${ledger ? `LEFT JOIN ${this.#ledger} AS l ON l.kind = d.kind AND l.name = d.qualified` : ''}
|
|
133
|
+
ORDER BY d.position`, this.#statements.flatMap(({ kind, object, qualified }, index) => [
|
|
134
|
+
index,
|
|
135
|
+
kind,
|
|
136
|
+
object.schema,
|
|
137
|
+
object.name,
|
|
138
|
+
qualified,
|
|
139
|
+
RELKINDS[kind],
|
|
140
|
+
]));
|
|
141
|
+
}
|
|
142
|
+
// A declared schema has only its name, so it is missing or it fits. Each
|
|
143
|
+
// other object fits when it exists and its ledger row has its checksum.
|
|
144
|
+
#drifts(rows) {
|
|
145
|
+
const drifts = new Map();
|
|
146
|
+
for (const row of rows) {
|
|
147
|
+
const statement = this.#statements[Number(row.position)];
|
|
148
|
+
if (statement === undefined)
|
|
149
|
+
continue;
|
|
150
|
+
if (row.present !== true)
|
|
151
|
+
drifts.set(statement, 'missing');
|
|
152
|
+
else if (statement.kind !== 'schema' &&
|
|
153
|
+
row.recorded !== statement.checksum)
|
|
154
|
+
drifts.set(statement, 'stale');
|
|
155
|
+
}
|
|
156
|
+
return drifts;
|
|
157
|
+
}
|
|
158
|
+
#report(drifts) {
|
|
159
|
+
const objects = this.#statements.flatMap((statement) => {
|
|
160
|
+
const drift = drifts.get(statement);
|
|
161
|
+
return drift === undefined
|
|
162
|
+
? []
|
|
163
|
+
: [{ name: statement.qualified, kind: statement.kind, drift }];
|
|
164
|
+
});
|
|
165
|
+
if (objects.length === 0)
|
|
166
|
+
return { drift: 'fits', objects };
|
|
167
|
+
const none = objects.length === this.#statements.length &&
|
|
168
|
+
objects.every(({ drift }) => drift === 'missing');
|
|
169
|
+
return { drift: none ? 'missing' : 'stale', objects };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// One apply, inside the transaction and the lock: it works on the stale and
|
|
173
|
+
// the missing objects, in the order of the declaration (ADR 0012), and gives
|
|
174
|
+
// each declared object that it made.
|
|
175
|
+
class Application {
|
|
176
|
+
#session;
|
|
177
|
+
#statements;
|
|
178
|
+
#drifts;
|
|
179
|
+
#rows;
|
|
180
|
+
#made = new Set();
|
|
181
|
+
#temporary = randomBytes(6).toHex();
|
|
182
|
+
#renamed = 0;
|
|
183
|
+
constructor(session, statements, drifts, rows) {
|
|
184
|
+
this.#session = session;
|
|
185
|
+
this.#statements = statements;
|
|
186
|
+
this.#drifts = drifts;
|
|
187
|
+
this.#rows = rows;
|
|
188
|
+
}
|
|
189
|
+
async run() {
|
|
190
|
+
for (const statement of this.#statements) {
|
|
191
|
+
if (this.#made.has(statement))
|
|
192
|
+
continue;
|
|
193
|
+
const drift = this.#drifts.get(statement);
|
|
194
|
+
if (drift === 'missing')
|
|
195
|
+
await this.#make(statement);
|
|
196
|
+
else if (drift === 'stale')
|
|
197
|
+
await this.#replace(statement);
|
|
198
|
+
}
|
|
199
|
+
return this.#made;
|
|
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 ${name}`);
|
|
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 n.nspname AS schema, c.relname AS name
|
|
239
|
+
FROM pg_catalog.pg_constraint AS k
|
|
240
|
+
JOIN pg_catalog.pg_class AS c ON c.oid = k.conrelid
|
|
241
|
+
JOIN pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace
|
|
242
|
+
WHERE k.contype = 'f' AND k.confrelid = $1::pg_catalog.regclass AND k.conrelid <> k.confrelid`, [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 = await this.#catalog(async () => {
|
|
256
|
+
const read = [];
|
|
257
|
+
for (const table of group)
|
|
258
|
+
read.push(await this.#capture(table.object));
|
|
259
|
+
return read;
|
|
260
|
+
});
|
|
261
|
+
const views = merged(captures.flatMap(({ views }) => views));
|
|
262
|
+
const foreignKeys = captures
|
|
263
|
+
.flatMap(({ foreignKeys }) => foreignKeys)
|
|
264
|
+
.filter(({ table }) => !group.some(({ object }) => sameName(table, object)));
|
|
265
|
+
if (views.length > 0)
|
|
266
|
+
await this.#query(`DROP VIEW ${views.map(({ object }) => qualify(object)).join(', ')}`);
|
|
267
|
+
for (const { table, name } of foreignKeys)
|
|
268
|
+
await this.#query(`ALTER TABLE ${qualify(table)} DROP CONSTRAINT ${quote(name)}`);
|
|
269
|
+
const kept = new Map();
|
|
270
|
+
if (this.#rows === 'keep')
|
|
271
|
+
for (const [index, table] of group.entries()) {
|
|
272
|
+
const capture = captures[index];
|
|
273
|
+
if (capture === undefined)
|
|
274
|
+
continue;
|
|
275
|
+
// The old table, its indexes and its sequences go away first, so
|
|
276
|
+
// each name that the statement makes is free (ADR 0012).
|
|
277
|
+
const old = this.#away();
|
|
278
|
+
await this.#query(`ALTER TABLE ${qualify(table.object)} RENAME TO ${quote(old)}`);
|
|
279
|
+
for (const { object } of capture.indexes)
|
|
280
|
+
await this.#query(`ALTER INDEX ${qualify(object)} RENAME TO ${quote(this.#away())}`);
|
|
281
|
+
for (const sequence of capture.sequences)
|
|
282
|
+
await this.#query(`ALTER SEQUENCE ${qualify(sequence)} RENAME TO ${quote(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, { schema: table.object.schema, name: old }, capture);
|
|
296
|
+
await this.#query(`DROP TABLE ${qualify({ schema: table.object.schema, name: 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 (!index.constraint && !this.#declares('index', index.object))
|
|
308
|
+
await this.#query(index.definition);
|
|
309
|
+
for (const trigger of capture.triggers)
|
|
310
|
+
await this.#query(trigger);
|
|
311
|
+
}
|
|
312
|
+
for (const { table, name, definition } of foreignKeys)
|
|
313
|
+
await this.#query(`ALTER TABLE ${qualify(table)} ADD CONSTRAINT ${quote(name)} ${definition}`);
|
|
314
|
+
await this.#views(views);
|
|
315
|
+
}
|
|
316
|
+
// Copies the columns that both tables have, by name, in the order of the
|
|
317
|
+
// old table's primary key, with the stored values of identity columns, and
|
|
318
|
+
// moves each sequence of a copied column past the largest copied value.
|
|
319
|
+
async #copy(table, old, capture) {
|
|
320
|
+
const columns = (await this.#query(`SELECT a.attname AS name, pg_catalog.pg_get_serial_sequence($1, a.attname) AS sequence
|
|
321
|
+
FROM pg_catalog.pg_attribute AS a
|
|
322
|
+
WHERE a.attrelid = $1::pg_catalog.regclass AND a.attnum > 0 AND NOT a.attisdropped AND a.attgenerated = ''
|
|
323
|
+
ORDER BY a.attnum`, [qualify(table)])).filter(({ name }) => capture.columns.includes(String(name)));
|
|
324
|
+
if (columns.length === 0)
|
|
325
|
+
return;
|
|
326
|
+
const names = columns.map(({ name }) => quote(String(name))).join(', ');
|
|
327
|
+
const order = capture.key.length === 0
|
|
328
|
+
? ''
|
|
329
|
+
: ` ORDER BY ${capture.key.map(quote).join(', ')}`;
|
|
330
|
+
await this.#query(`INSERT INTO ${qualify(table)} (${names}) OVERRIDING SYSTEM VALUE SELECT ${names} FROM ${qualify(old)}${order}`);
|
|
331
|
+
for (const { name, sequence } of columns)
|
|
332
|
+
if (typeof sequence === 'string')
|
|
333
|
+
await this.#query(`SELECT pg_catalog.setval($1, m.value) FROM (SELECT max(${quote(String(name))}) AS value FROM ${qualify(table)}) AS m WHERE m.value IS NOT NULL`, [sequence]);
|
|
334
|
+
}
|
|
335
|
+
// A stale view is dropped with the views that read it, made from its
|
|
336
|
+
// statement, and the views that read it are made again.
|
|
337
|
+
async #view(view) {
|
|
338
|
+
const { views, triggers } = await this.#catalog(async () => ({
|
|
339
|
+
views: await this.#dependents(view.object),
|
|
340
|
+
triggers: await this.#triggers(view.object),
|
|
341
|
+
}));
|
|
342
|
+
await this.#query(`DROP VIEW ${[...views.map(({ object }) => object), view.object]
|
|
343
|
+
.map(qualify)
|
|
344
|
+
.join(', ')}`);
|
|
345
|
+
await this.#make(view);
|
|
346
|
+
for (const trigger of triggers)
|
|
347
|
+
await this.#query(trigger);
|
|
348
|
+
await this.#views(views);
|
|
349
|
+
}
|
|
350
|
+
// A stale sequence is made from its statement. With rows: 'keep', it keeps
|
|
351
|
+
// its last value.
|
|
352
|
+
async #sequence(sequence) {
|
|
353
|
+
const name = qualify(sequence.object);
|
|
354
|
+
const [last] = this.#rows === 'keep'
|
|
355
|
+
? await this.#query(`SELECT last_value, is_called FROM ${name}`)
|
|
356
|
+
: [];
|
|
357
|
+
await this.#query(`DROP SEQUENCE ${name}`);
|
|
358
|
+
await this.#make(sequence);
|
|
359
|
+
if (last !== undefined)
|
|
360
|
+
await this.#query(`SELECT pg_catalog.setval($1, $2, $3)`, [
|
|
361
|
+
name,
|
|
362
|
+
last.last_value,
|
|
363
|
+
last.is_called,
|
|
364
|
+
]);
|
|
365
|
+
}
|
|
366
|
+
// Makes each view again, the views that others read first: a declared
|
|
367
|
+
// view from its statement, any other view from its definition.
|
|
368
|
+
async #views(views) {
|
|
369
|
+
for (const view of views) {
|
|
370
|
+
const statement = this.#statements.find((candidate) => candidate.kind === 'view' && sameName(view.object, candidate.object));
|
|
371
|
+
if (statement !== undefined)
|
|
372
|
+
await this.#make(statement);
|
|
373
|
+
else
|
|
374
|
+
await this.#query(`CREATE VIEW ${qualify(view.object)}${view.options ? ` WITH (${view.options})` : ''} AS ${view.definition}`);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
async #capture(table) {
|
|
378
|
+
const name = qualify(table);
|
|
379
|
+
const foreignKeys = await this.#query(`SELECT n.nspname AS schema, c.relname AS name, k.conname AS constraint, pg_catalog.pg_get_constraintdef(k.oid) AS definition
|
|
380
|
+
FROM pg_catalog.pg_constraint AS k
|
|
381
|
+
JOIN pg_catalog.pg_class AS c ON c.oid = k.conrelid
|
|
382
|
+
JOIN pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace
|
|
383
|
+
WHERE k.contype = 'f' AND k.confrelid = $1::pg_catalog.regclass AND k.conrelid <> k.confrelid
|
|
384
|
+
ORDER BY n.nspname, c.relname, k.conname`, [name]);
|
|
385
|
+
const indexes = await this.#query(`SELECT n.nspname AS schema, c.relname AS name, pg_catalog.pg_get_indexdef(i.indexrelid) AS definition,
|
|
386
|
+
EXISTS (SELECT FROM pg_catalog.pg_constraint AS k WHERE k.conindid = i.indexrelid AND k.conrelid = i.indrelid) AS constraint
|
|
387
|
+
FROM pg_catalog.pg_index AS i
|
|
388
|
+
JOIN pg_catalog.pg_class AS c ON c.oid = i.indexrelid
|
|
389
|
+
JOIN pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace
|
|
390
|
+
WHERE i.indrelid = $1::pg_catalog.regclass
|
|
391
|
+
ORDER BY c.relname`, [name]);
|
|
392
|
+
const sequences = await this.#query(`SELECT n.nspname AS schema, c.relname AS name
|
|
393
|
+
FROM pg_catalog.pg_depend AS d
|
|
394
|
+
JOIN pg_catalog.pg_class AS c ON c.oid = d.objid
|
|
395
|
+
JOIN pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace
|
|
396
|
+
WHERE d.classid = 'pg_catalog.pg_class'::pg_catalog.regclass AND d.refclassid = 'pg_catalog.pg_class'::pg_catalog.regclass
|
|
397
|
+
AND d.refobjid = $1::pg_catalog.regclass AND c.relkind = 'S' AND d.deptype IN ('a', 'i')`, [name]);
|
|
398
|
+
const columns = await this.#query(`SELECT a.attname AS name FROM pg_catalog.pg_attribute AS a
|
|
399
|
+
WHERE a.attrelid = $1::pg_catalog.regclass AND a.attnum > 0 AND NOT a.attisdropped`, [name]);
|
|
400
|
+
const key = await this.#query(`SELECT a.attname AS name
|
|
401
|
+
FROM pg_catalog.pg_index AS i
|
|
402
|
+
CROSS JOIN LATERAL pg_catalog.unnest(i.indkey) WITH ORDINALITY AS k (attnum, position)
|
|
403
|
+
JOIN pg_catalog.pg_attribute AS a ON a.attrelid = i.indrelid AND a.attnum = k.attnum
|
|
404
|
+
WHERE i.indrelid = $1::pg_catalog.regclass AND i.indisprimary
|
|
405
|
+
ORDER BY k.position`, [name]);
|
|
406
|
+
return {
|
|
407
|
+
views: await this.#dependents(table),
|
|
408
|
+
foreignKeys: foreignKeys.map((row) => ({
|
|
409
|
+
table: catalogName(row),
|
|
410
|
+
name: String(row.constraint),
|
|
411
|
+
definition: String(row.definition),
|
|
412
|
+
})),
|
|
413
|
+
indexes: indexes.map((row) => ({
|
|
414
|
+
object: catalogName(row),
|
|
415
|
+
definition: String(row.definition),
|
|
416
|
+
constraint: row.constraint === true,
|
|
417
|
+
})),
|
|
418
|
+
sequences: sequences.map(catalogName),
|
|
419
|
+
triggers: await this.#triggers(table),
|
|
420
|
+
columns: columns.map(({ name }) => String(name)),
|
|
421
|
+
key: key.map(({ name }) => String(name)),
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
// The views that read the relation, and the views that read those, the
|
|
425
|
+
// views that others read first.
|
|
426
|
+
async #dependents(relation) {
|
|
427
|
+
const rows = await this.#query(`WITH RECURSIVE dependents (oid, depth) AS (
|
|
428
|
+
SELECT r.ev_class, 1
|
|
429
|
+
FROM pg_catalog.pg_depend AS d
|
|
430
|
+
JOIN pg_catalog.pg_rewrite AS r ON r.oid = d.objid
|
|
431
|
+
WHERE d.classid = 'pg_catalog.pg_rewrite'::pg_catalog.regclass AND d.refclassid = 'pg_catalog.pg_class'::pg_catalog.regclass
|
|
432
|
+
AND d.refobjid = $1::pg_catalog.regclass AND r.ev_class <> d.refobjid
|
|
433
|
+
UNION ALL
|
|
434
|
+
SELECT r.ev_class, dependents.depth + 1
|
|
435
|
+
FROM dependents
|
|
436
|
+
JOIN pg_catalog.pg_depend AS d ON d.refobjid = dependents.oid
|
|
437
|
+
JOIN pg_catalog.pg_rewrite AS r ON r.oid = d.objid
|
|
438
|
+
WHERE d.classid = 'pg_catalog.pg_rewrite'::pg_catalog.regclass AND d.refclassid = 'pg_catalog.pg_class'::pg_catalog.regclass
|
|
439
|
+
AND r.ev_class <> dependents.oid
|
|
440
|
+
)
|
|
441
|
+
SELECT n.nspname AS schema, c.relname AS name, max(dependents.depth) AS depth,
|
|
442
|
+
pg_catalog.pg_get_viewdef(c.oid) AS definition, pg_catalog.array_to_string(c.reloptions, ', ') AS options
|
|
443
|
+
FROM dependents
|
|
444
|
+
JOIN pg_catalog.pg_class AS c ON c.oid = dependents.oid
|
|
445
|
+
JOIN pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace
|
|
446
|
+
WHERE c.relkind = 'v'
|
|
447
|
+
GROUP BY c.oid, n.nspname, c.relname
|
|
448
|
+
ORDER BY max(dependents.depth), n.nspname, c.relname`, [qualify(relation)]);
|
|
449
|
+
return rows.map((row) => ({
|
|
450
|
+
object: catalogName(row),
|
|
451
|
+
depth: Number(row.depth),
|
|
452
|
+
definition: String(row.definition),
|
|
453
|
+
options: typeof row.options === 'string' && row.options !== ''
|
|
454
|
+
? row.options
|
|
455
|
+
: null,
|
|
456
|
+
}));
|
|
457
|
+
}
|
|
458
|
+
async #triggers(relation) {
|
|
459
|
+
const rows = await this.#query(`SELECT pg_catalog.pg_get_triggerdef(t.oid) AS definition FROM pg_catalog.pg_trigger AS t
|
|
460
|
+
WHERE t.tgrelid = $1::pg_catalog.regclass AND NOT t.tgisinternal ORDER BY t.tgname`, [qualify(relation)]);
|
|
461
|
+
return rows.map(({ definition }) => String(definition));
|
|
462
|
+
}
|
|
463
|
+
// Reads definitions with only pg_catalog on the search path, so each name
|
|
464
|
+
// in them carries its schema; the statements of the declaration then run
|
|
465
|
+
// on the host's search path again.
|
|
466
|
+
async #catalog(read) {
|
|
467
|
+
const [path] = await this.#query(`SELECT pg_catalog.current_setting('search_path') AS path`);
|
|
468
|
+
await this.#query(`SELECT pg_catalog.set_config('search_path', 'pg_catalog', true)`);
|
|
469
|
+
const result = await read();
|
|
470
|
+
await this.#query(`SELECT pg_catalog.set_config('search_path', $1, true)`, [
|
|
471
|
+
String(path?.path),
|
|
472
|
+
]);
|
|
473
|
+
return result;
|
|
474
|
+
}
|
|
475
|
+
#declares(kind, object) {
|
|
476
|
+
return this.#statements.some((statement) => statement.kind === kind && sameName(statement.object, object));
|
|
477
|
+
}
|
|
478
|
+
#away() {
|
|
479
|
+
this.#renamed += 1;
|
|
480
|
+
return `zukhruf_schema_drift_${this.#temporary}_${this.#renamed}`;
|
|
481
|
+
}
|
|
482
|
+
async #make(statement) {
|
|
483
|
+
await this.#query(statement.statement);
|
|
484
|
+
this.#made.add(statement);
|
|
485
|
+
}
|
|
486
|
+
#query(sql, parameters = []) {
|
|
487
|
+
return this.#session.query(sql, parameters);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
function catalogName(row) {
|
|
491
|
+
return { schema: String(row.schema), name: String(row.name) };
|
|
492
|
+
}
|
|
493
|
+
// The views of several tables, each once, at its deepest place.
|
|
494
|
+
function merged(views) {
|
|
495
|
+
const deepest = new Map();
|
|
496
|
+
for (const view of views) {
|
|
497
|
+
const key = qualify(view.object);
|
|
498
|
+
const known = deepest.get(key);
|
|
499
|
+
if (known === undefined || known.depth < view.depth)
|
|
500
|
+
deepest.set(key, view);
|
|
501
|
+
}
|
|
502
|
+
return [...deepest.values()].toSorted((a, b) => a.depth - b.depth);
|
|
503
|
+
}
|
|
504
|
+
//# sourceMappingURL=postgres-declaration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-declaration.js","sourceRoot":"","sources":["../../src/postgres/postgres-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,yBAAyB,CAAC;AAsBjC,0EAA0E;AAC1E,6EAA6E;AAC7E,MAAM,IAAI,GAAG,qBAAqB,CAAC;AACnC,MAAM,MAAM,GAAG,sBAAsB,CAAC;AAEtC,0DAA0D;AAC1D,MAAM,QAAQ,GAAwD;IACpE,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,IAAI,EAAE,GAAG;IACT,QAAQ,EAAE,GAAG;IACb,QAAQ,EAAE,EAAE;IACZ,SAAS,EAAE,EAAE;IACb,MAAM,EAAE,EAAE;CACX,CAAC;AAEF,yDAAyD;AACzD,MAAM,OAAO,GAAG;;;;;IAKZ,CAAC;AAEL,SAAS,KAAK,CAAC,UAAkB;IAC/B,OAAO,IAAI,UAAU,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;AACjD,CAAC;AAED,SAA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GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ObjectKind } from '../drift.ts';
|
|
2
|
+
/** A name of the catalog: its schema and its own name, as Postgres keeps them. */
|
|
3
|
+
export type CatalogName = {
|
|
4
|
+
readonly schema: string;
|
|
5
|
+
readonly name: string;
|
|
6
|
+
};
|
|
7
|
+
/** One element of a declaration, read: what it makes, and the checksum of its tokens. */
|
|
8
|
+
export type DeclaredStatement = {
|
|
9
|
+
readonly statement: string;
|
|
10
|
+
readonly kind: Exclude<ObjectKind, 'virtual table' | 'trigger'>;
|
|
11
|
+
readonly object: CatalogName;
|
|
12
|
+
/** The qualified name of the report and the ledger: '_warehouse.extraction_coverage'. */
|
|
13
|
+
readonly qualified: string;
|
|
14
|
+
/** The table of an index, from the head after ON. */
|
|
15
|
+
readonly table?: CatalogName;
|
|
16
|
+
readonly checksum: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function declared(statement: string): DeclaredStatement;
|
|
19
|
+
//# sourceMappingURL=postgres-statement.d.ts.map
|