@zukhruf/schema-drift 0.8.282 → 0.8.284
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 +108 -4
- 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/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 and `./
|
|
3
|
+
> **Design accepted 2026-12-01.** The root entry point, `./sqlite` and `./postgres` are built. `./sqlserver` is the API on paper, which the maintainer approved, and is not built yet (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
|
|
|
@@ -70,7 +70,9 @@ A warehouse that an older elt made with `CREATE TABLE IF NOT EXISTS` has the tab
|
|
|
70
70
|
```ts
|
|
71
71
|
const report = await warehouse.drift(session);
|
|
72
72
|
// { drift: 'stale',
|
|
73
|
-
// objects: [
|
|
73
|
+
// objects: [
|
|
74
|
+
// { name: '_warehouse.extraction_coverage', kind: 'table', drift: 'stale' },
|
|
75
|
+
// { name: '_warehouse.extraction_coverage_target', kind: 'index', drift: 'missing' } ] }
|
|
74
76
|
```
|
|
75
77
|
|
|
76
78
|
- `drift` is `missing` when the database stores none of the objects, `fits` when it stores each one as declared, and `stale` for all other cases.
|
|
@@ -89,6 +91,7 @@ const report = await warehouse.drift(session);
|
|
|
89
91
|
| Any, or none | Does not exist | `missing` |
|
|
90
92
|
|
|
91
93
|
- The checksum is the SHA-256 of the tokens of the statement. A comment, and a change of the spaces and line breaks between two tokens, is not drift. A change of a string, of a quoted name, of a dollar-quoted body (Postgres), of a `[bracketed]` name or of an `N'…'` string (SQL Server) is drift. A change of case of a word is drift too ([ADR 0010](./docs/adr/0010-a-checksum-covers-the-tokens-of-a-statement-and-comments-and-the-spaces-between-tokens-are-not-drift.md)).
|
|
94
|
+
- A declared schema fits when it exists, with or without a ledger row: its statement holds only its name.
|
|
92
95
|
- An object with no ledger row is stale, also when its shape is the declared one. The package cannot know who made it, or from which text. Thus `apply` repairs a database that older code made with `IF NOT EXISTS`.
|
|
93
96
|
- A change that a person makes by hand after `apply` is not seen. The ledger row still has the checksum of the declared statement. Liquibase (`MD5SUM`) and Flyway (`validate`) have the same limit. A dropped object is seen: it is missing.
|
|
94
97
|
|
|
@@ -99,6 +102,7 @@ const report = await warehouse.drift(session);
|
|
|
99
102
|
```
|
|
100
103
|
SchemaDriftError: The database does not store the declaration as declared:
|
|
101
104
|
_warehouse.extraction_coverage (table) is stale.
|
|
105
|
+
_warehouse.extraction_coverage_target (index) is missing.
|
|
102
106
|
Apply the declaration.
|
|
103
107
|
```
|
|
104
108
|
|
|
@@ -128,6 +132,7 @@ With `rows: 'replace'`, `apply` drops a stale table and makes it from its statem
|
|
|
128
132
|
|
|
129
133
|
- A declared table that refers to the replaced table is replaced too, so no kept row refers to a row that is gone.
|
|
130
134
|
- A view that depends on the table is dropped first, and made again after it: a declared view from its statement, any other view from its definition that `apply` read before the drop.
|
|
135
|
+
- A declared index on the table is made from its statement. An index and a trigger that the declaration does not name are made again from their catalog definitions, as with `rows: 'keep'`.
|
|
131
136
|
- A foreign key of a table that the declaration does not name is made again after the table. When that table has a row that refers to a row that is gone, `apply` fails with the error of the database, and the transaction rolls back.
|
|
132
137
|
- A stale sequence is dropped and made from its statement. It starts again.
|
|
133
138
|
|
|
@@ -140,7 +145,7 @@ With `rows: 'keep'`, `apply` rebuilds each stale table and keeps its rows. This
|
|
|
140
145
|
3. It renames the stored table to a temporary name, and renames its constraints, its indexes and its owned sequences away too. The declared names are then free.
|
|
141
146
|
4. It makes the table from its statement, under its declared name. Each name that the database gives (`<table>_pkey`, `<table>_<column>_seq`) is the name that a new database gives.
|
|
142
147
|
5. It copies the columns that both tables have, read from the catalog of the target, by name, in the order of the primary key. It writes the stored values of an identity column: `OVERRIDING SYSTEM VALUE` on Postgres, `SET IDENTITY_INSERT … ON` on SQL Server. It does not copy a column that the database computes (generated, computed, `rowversion`).
|
|
143
|
-
6. On Postgres, it sets the sequence of each identity column to the largest copied value (`setval`). SQL Server moves the identity on its own when it inserts a larger value.
|
|
148
|
+
6. On Postgres, it sets the sequence of each identity or `serial` column to the largest copied value (`setval`). SQL Server moves the identity on its own when it inserts a larger value.
|
|
144
149
|
7. It drops the old table, and makes again the indexes and triggers of step 1 from their catalog definitions.
|
|
145
150
|
8. It makes again the foreign keys and the views of step 1: a declared view from its statement, any other view from its definition. On SQL Server, it runs `sp_refreshview` on each view that is not schema-bound and that refers to the table.
|
|
146
151
|
|
|
@@ -152,6 +157,100 @@ A stale sequence keeps its last value: `apply` reads it, makes the sequence from
|
|
|
152
157
|
- When a stored row does not fit the declared table (`NOT NULL`, `CHECK`, a foreign key, a type), `apply` fails with the error of the database, and the transaction rolls back.
|
|
153
158
|
- The grants, the comments and the row-level security policies of a rebuilt table or a made-again view are gone. The host grants them again after `apply`.
|
|
154
159
|
|
|
160
|
+
## Work on Postgres
|
|
161
|
+
|
|
162
|
+
`@zukhruf/schema-drift/postgres` imports no driver. The host gives a `PostgresSession` over its own driver. The example writes one over node-postgres, makes the table as an older elt did, and repairs it.
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
import pg from 'pg';
|
|
166
|
+
|
|
167
|
+
import {
|
|
168
|
+
PostgresDeclaration,
|
|
169
|
+
type PostgresSession,
|
|
170
|
+
} from '@zukhruf/schema-drift/postgres';
|
|
171
|
+
|
|
172
|
+
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
|
|
173
|
+
// The session over node-postgres: queries on the pool, and a transaction on
|
|
174
|
+
// one client of it.
|
|
175
|
+
const session: PostgresSession = {
|
|
176
|
+
query: async (sql, parameters) =>
|
|
177
|
+
(await pool.query(sql, [...parameters])).rows,
|
|
178
|
+
transaction: async (work) => {
|
|
179
|
+
const client = await pool.connect();
|
|
180
|
+
try {
|
|
181
|
+
await client.query('BEGIN');
|
|
182
|
+
const inner: PostgresSession = {
|
|
183
|
+
query: async (sql, parameters) =>
|
|
184
|
+
(await client.query(sql, [...parameters])).rows,
|
|
185
|
+
transaction: async (nested) => nested(inner),
|
|
186
|
+
};
|
|
187
|
+
await work(inner);
|
|
188
|
+
await client.query('COMMIT');
|
|
189
|
+
} catch (error) {
|
|
190
|
+
await client.query('ROLLBACK');
|
|
191
|
+
throw error;
|
|
192
|
+
} finally {
|
|
193
|
+
client.release();
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
// An older elt made the table with IF NOT EXISTS, without reloading.
|
|
198
|
+
await pool.query(`CREATE SCHEMA _warehouse;
|
|
199
|
+
CREATE TABLE IF NOT EXISTS _warehouse.extraction_coverage (stream text PRIMARY KEY, target_schema text NOT NULL);
|
|
200
|
+
INSERT INTO _warehouse.extraction_coverage VALUES ('orders', 'raw')`);
|
|
201
|
+
|
|
202
|
+
const warehouse = new PostgresDeclaration(
|
|
203
|
+
[
|
|
204
|
+
'CREATE SCHEMA _warehouse',
|
|
205
|
+
`CREATE TABLE _warehouse.extraction_coverage (
|
|
206
|
+
stream text PRIMARY KEY,
|
|
207
|
+
target_schema text NOT NULL,
|
|
208
|
+
reloading boolean NOT NULL DEFAULT false
|
|
209
|
+
)`,
|
|
210
|
+
'CREATE INDEX extraction_coverage_target ON _warehouse.extraction_coverage (target_schema)',
|
|
211
|
+
],
|
|
212
|
+
{ ledgerSchema: '_warehouse' },
|
|
213
|
+
);
|
|
214
|
+
console.log(await warehouse.drift(session));
|
|
215
|
+
try {
|
|
216
|
+
await warehouse.check(session);
|
|
217
|
+
} catch (error) {
|
|
218
|
+
console.log(String(error));
|
|
219
|
+
}
|
|
220
|
+
await warehouse.apply(session, { rows: 'keep' });
|
|
221
|
+
console.log(await warehouse.drift(session));
|
|
222
|
+
console.log(
|
|
223
|
+
(await pool.query('SELECT * FROM _warehouse.extraction_coverage')).rows,
|
|
224
|
+
);
|
|
225
|
+
await pool.end();
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Output:
|
|
229
|
+
|
|
230
|
+
```
|
|
231
|
+
{
|
|
232
|
+
drift: 'stale',
|
|
233
|
+
objects: [
|
|
234
|
+
{
|
|
235
|
+
name: '_warehouse.extraction_coverage',
|
|
236
|
+
kind: 'table',
|
|
237
|
+
drift: 'stale'
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
name: '_warehouse.extraction_coverage_target',
|
|
241
|
+
kind: 'index',
|
|
242
|
+
drift: 'missing'
|
|
243
|
+
}
|
|
244
|
+
]
|
|
245
|
+
}
|
|
246
|
+
SchemaDriftError: The database does not store the declaration as declared:
|
|
247
|
+
_warehouse.extraction_coverage (table) is stale.
|
|
248
|
+
_warehouse.extraction_coverage_target (index) is missing.
|
|
249
|
+
Apply the declaration.
|
|
250
|
+
{ drift: 'fits', objects: [] }
|
|
251
|
+
[ { stream: 'orders', target_schema: 'raw', reloading: false } ]
|
|
252
|
+
```
|
|
253
|
+
|
|
155
254
|
## Work on SQLite
|
|
156
255
|
|
|
157
256
|
`@zukhruf/schema-drift/sqlite` is `@zukhruf/sqlite-drift`, moved in with its behaviour. It uses only `node:sqlite`.
|
|
@@ -366,12 +465,13 @@ The key is `(kind, name)`. The table lives in the schema that `ledgerSchema` nam
|
|
|
366
465
|
| `A declared object needs a schema in its name: …` | The Postgres or SQL Server constructor found a name with no schema. |
|
|
367
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. …`. |
|
|
368
467
|
| `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. |
|
|
369
469
|
| `A declaration names each object once: …` | Two statements make objects of one kind and one qualified name, also two overloads of one function. |
|
|
370
470
|
| `apply needs rows: 'replace' or 'keep'. …` (`TypeError`) | A JavaScript caller gave `apply` no `rows`. TypeScript refuses the call. Nothing changes. |
|
|
371
471
|
| The error of SQLite | `new SqliteDeclaration` fails when a statement does not run in the dev database. |
|
|
372
472
|
| `The dev database must be empty. …` | `new SqliteDeclaration` fails when the dev database has an object. |
|
|
373
473
|
| `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. |
|
|
374
|
-
| `An element of a declaration holds one statement. …` | `new SqliteDeclaration` fails when one string holds two statements.
|
|
474
|
+
| `An element of a declaration holds one statement. …` | `new SqliteDeclaration` fails when one string holds two statements. The Postgres constructor ends the message with `:` and the element. |
|
|
375
475
|
| `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`. |
|
|
376
476
|
| `The virtual table … cannot keep its rows: …` | SQLite `apply` with `rows: 'keep'`, and a virtual table is stale. Nothing changes. |
|
|
377
477
|
| `database is locked` | SQLite `apply` with no transaction waits for the busy timeout of the connection, then fails. |
|
|
@@ -619,4 +719,8 @@ src/
|
|
|
619
719
|
sqlite.ts the ./sqlite entry point
|
|
620
720
|
sqlite/sqlite-declaration.ts SqliteDeclaration
|
|
621
721
|
sqlite/sqlite-declaration.test.ts the tests, on real SQLite files
|
|
722
|
+
postgres.ts the ./postgres entry point
|
|
723
|
+
postgres/postgres-statement.ts the tokens, the checksum and the head of a statement
|
|
724
|
+
postgres/postgres-declaration.ts PostgresDeclaration, PostgresSession
|
|
725
|
+
postgres/postgres-declaration.test.ts the tests, on a real Postgres of @zukhruf/testing/postgres
|
|
622
726
|
```
|
|
@@ -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,SAAS,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,EAAe;IAC5C,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;AAC3C,CAAC;AAED,SAAS,QAAQ,CAAC,CAA0B,EAAE,CAAc;IAC1D,OAAO,CAAC,EAAE,MAAM,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,CAAC;AACrD,CAAC;AAED,+DAA+D;AAC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,CAAC,CAAC;IAC5B,CAAC;IAED,MAAM,CACJ,GAAW,EACX,UAAU,GAAuB,EAAE;QAEnC,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IAC9C,CAAC;CACF;AAED,SAAS,WAAW,CAAC,GAA4B;IAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;AAChE,CAAC;AAED,gEAAgE;AAChE,SAAS,MAAM,CAAC,KAAsB;IACpC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAgB,CAAC;IACxC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACjC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK;YAAE,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-statement.d.ts","sourceRoot":"","sources":["../../src/postgres/postgres-statement.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAe9C,kFAAkF;AAClF,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7E,yFAAyF;AACzF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CAAC;IAChE,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,yFAAyF;IACzF,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,qDAAqD;IACrD,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B,CAAC;AAwIF,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,iBAAiB,CAkG7D"}
|
|
@@ -0,0 +1,253 @@
|
|
|
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[xXoObB][0-9a-fA-F_]+|(?:\d[\d_]*(?:\.[\d_]*)?|\.\d[\d_]*)(?:[eE][+-]?\d+)?)/y;
|
|
6
|
+
const DOLLAR_TAG = /\$(?:[A-Za-z_\u0080-][A-Za-z0-9_\u0080-]*)?\$/y;
|
|
7
|
+
// The tokens of a statement by the lexical rules of Postgres (ADR 0010): a
|
|
8
|
+
// string, an escape string, a quoted name and a dollar-quoted body are each one
|
|
9
|
+
// token, kept as written; comments (nested /* */ too) and the spaces between
|
|
10
|
+
// tokens are not tokens.
|
|
11
|
+
function tokens(statement) {
|
|
12
|
+
const found = [];
|
|
13
|
+
let at = 0;
|
|
14
|
+
const unclosed = (what) => {
|
|
15
|
+
throw new Error(`A statement of a declaration must close each ${what}: ${statement}`);
|
|
16
|
+
};
|
|
17
|
+
while (at < statement.length) {
|
|
18
|
+
const char = statement[at] ?? '';
|
|
19
|
+
const next = statement[at + 1] ?? '';
|
|
20
|
+
if (/\s/.test(char)) {
|
|
21
|
+
at += 1;
|
|
22
|
+
}
|
|
23
|
+
else if (char === '-' && next === '-') {
|
|
24
|
+
const end = statement.indexOf('\n', at);
|
|
25
|
+
at = end === -1 ? statement.length : end + 1;
|
|
26
|
+
}
|
|
27
|
+
else if (char === '/' && next === '*') {
|
|
28
|
+
let depth = 0;
|
|
29
|
+
do {
|
|
30
|
+
if (at >= statement.length)
|
|
31
|
+
unclosed('comment');
|
|
32
|
+
if (statement.startsWith('/*', at)) {
|
|
33
|
+
depth += 1;
|
|
34
|
+
at += 2;
|
|
35
|
+
}
|
|
36
|
+
else if (statement.startsWith('*/', at)) {
|
|
37
|
+
depth -= 1;
|
|
38
|
+
at += 2;
|
|
39
|
+
}
|
|
40
|
+
else
|
|
41
|
+
at += 1;
|
|
42
|
+
} while (depth > 0);
|
|
43
|
+
}
|
|
44
|
+
else if (char === "'" ||
|
|
45
|
+
((char === 'E' || char === 'e') && next === "'")) {
|
|
46
|
+
const escapes = char !== "'";
|
|
47
|
+
let end = at + (escapes ? 2 : 1);
|
|
48
|
+
for (;;) {
|
|
49
|
+
if (end >= statement.length)
|
|
50
|
+
unclosed('string');
|
|
51
|
+
const inside = statement[end];
|
|
52
|
+
if (escapes && inside === '\\')
|
|
53
|
+
end += 2;
|
|
54
|
+
else if (inside === "'" && statement[end + 1] === "'")
|
|
55
|
+
end += 2;
|
|
56
|
+
else if (inside === "'")
|
|
57
|
+
break;
|
|
58
|
+
else
|
|
59
|
+
end += 1;
|
|
60
|
+
}
|
|
61
|
+
found.push({ type: 'string', text: statement.slice(at, end + 1) });
|
|
62
|
+
at = end + 1;
|
|
63
|
+
}
|
|
64
|
+
else if (char === '"') {
|
|
65
|
+
let end = at + 1;
|
|
66
|
+
for (;;) {
|
|
67
|
+
if (end >= statement.length)
|
|
68
|
+
unclosed('quoted name');
|
|
69
|
+
if (statement[end] === '"' && statement[end + 1] === '"')
|
|
70
|
+
end += 2;
|
|
71
|
+
else if (statement[end] === '"')
|
|
72
|
+
break;
|
|
73
|
+
else
|
|
74
|
+
end += 1;
|
|
75
|
+
}
|
|
76
|
+
found.push({ type: 'quoted', text: statement.slice(at, end + 1) });
|
|
77
|
+
at = end + 1;
|
|
78
|
+
}
|
|
79
|
+
else if (char === '$') {
|
|
80
|
+
DOLLAR_TAG.lastIndex = at;
|
|
81
|
+
const tag = DOLLAR_TAG.exec(statement)?.[0];
|
|
82
|
+
if (tag !== undefined) {
|
|
83
|
+
const close = statement.indexOf(tag, at + tag.length);
|
|
84
|
+
if (close === -1)
|
|
85
|
+
unclosed('dollar-quoted body');
|
|
86
|
+
found.push({
|
|
87
|
+
type: 'dollar',
|
|
88
|
+
text: statement.slice(at, close + tag.length),
|
|
89
|
+
});
|
|
90
|
+
at = close + tag.length;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
let end = at + 1;
|
|
94
|
+
while (/\d/.test(statement[end] ?? ''))
|
|
95
|
+
end += 1;
|
|
96
|
+
found.push({ type: 'parameter', text: statement.slice(at, end) });
|
|
97
|
+
at = end;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if (/\d/.test(char) || (char === '.' && /\d/.test(next))) {
|
|
101
|
+
NUMBER.lastIndex = at;
|
|
102
|
+
const number = NUMBER.exec(statement)?.[0] ?? char;
|
|
103
|
+
found.push({ type: 'number', text: number });
|
|
104
|
+
at += number.length;
|
|
105
|
+
}
|
|
106
|
+
else if (WORD_START.test(char)) {
|
|
107
|
+
let end = at + 1;
|
|
108
|
+
while (WORD.test(statement[end] ?? ''))
|
|
109
|
+
end += 1;
|
|
110
|
+
found.push({ type: 'word', text: statement.slice(at, end) });
|
|
111
|
+
at = end;
|
|
112
|
+
}
|
|
113
|
+
else if (OPERATOR.test(char)) {
|
|
114
|
+
let end = at + 1;
|
|
115
|
+
while (OPERATOR.test(statement[end] ?? '') &&
|
|
116
|
+
!statement.startsWith('--', end) &&
|
|
117
|
+
!statement.startsWith('/*', end))
|
|
118
|
+
end += 1;
|
|
119
|
+
found.push({ type: 'operator', text: statement.slice(at, end) });
|
|
120
|
+
at = end;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
found.push({ type: 'symbol', text: char });
|
|
124
|
+
at += 1;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (found.at(-1)?.text === ';')
|
|
128
|
+
found.pop();
|
|
129
|
+
if (found.some(({ type, text }) => type === 'symbol' && text === ';'))
|
|
130
|
+
throw new Error(`An element of a declaration holds one statement: ${statement}`);
|
|
131
|
+
return found;
|
|
132
|
+
}
|
|
133
|
+
// The SHA-256 of the tokens, each followed by a byte that no token holds (ADR 0010).
|
|
134
|
+
function checksum(found) {
|
|
135
|
+
const hash = createHash('sha256');
|
|
136
|
+
for (const { text } of found)
|
|
137
|
+
hash.update(`${text}\0`);
|
|
138
|
+
return hash.digest('hex');
|
|
139
|
+
}
|
|
140
|
+
const KINDS = new Map([
|
|
141
|
+
['TABLE', 'table'],
|
|
142
|
+
['INDEX', 'index'],
|
|
143
|
+
['VIEW', 'view'],
|
|
144
|
+
['SEQUENCE', 'sequence'],
|
|
145
|
+
['FUNCTION', 'function'],
|
|
146
|
+
['PROCEDURE', 'procedure'],
|
|
147
|
+
['SCHEMA', 'schema'],
|
|
148
|
+
]);
|
|
149
|
+
// Reads the kind and the qualified name from the head of a statement, and
|
|
150
|
+
// refuses a head it cannot read (ADR 0011).
|
|
151
|
+
export function declared(statement) {
|
|
152
|
+
const found = tokens(statement);
|
|
153
|
+
let at = 0;
|
|
154
|
+
const unreadable = () => {
|
|
155
|
+
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}`);
|
|
156
|
+
};
|
|
157
|
+
const word = (offset = 0) => {
|
|
158
|
+
const token = found[at + offset];
|
|
159
|
+
return token?.type === 'word' ? token.text.toUpperCase() : undefined;
|
|
160
|
+
};
|
|
161
|
+
const take = (expected) => {
|
|
162
|
+
if (word() !== expected)
|
|
163
|
+
return false;
|
|
164
|
+
at += 1;
|
|
165
|
+
return true;
|
|
166
|
+
};
|
|
167
|
+
const identifier = () => {
|
|
168
|
+
const token = found[at];
|
|
169
|
+
if (token?.type === 'word') {
|
|
170
|
+
at += 1;
|
|
171
|
+
return token.text.replaceAll(/[A-Z]+/g, (upper) => upper.toLowerCase());
|
|
172
|
+
}
|
|
173
|
+
if (token?.type === 'quoted') {
|
|
174
|
+
at += 1;
|
|
175
|
+
return token.text.slice(1, -1).replaceAll('""', '"');
|
|
176
|
+
}
|
|
177
|
+
return unreadable();
|
|
178
|
+
};
|
|
179
|
+
const dot = () => {
|
|
180
|
+
const token = found[at];
|
|
181
|
+
if (token?.type !== 'symbol' || token.text !== '.')
|
|
182
|
+
return false;
|
|
183
|
+
at += 1;
|
|
184
|
+
return true;
|
|
185
|
+
};
|
|
186
|
+
const qualifiedName = () => {
|
|
187
|
+
const first = identifier();
|
|
188
|
+
if (!dot())
|
|
189
|
+
throw new Error(`A declared object needs a schema in its name: ${statement}`);
|
|
190
|
+
const name = identifier();
|
|
191
|
+
if (dot())
|
|
192
|
+
unreadable();
|
|
193
|
+
return { schema: first, name };
|
|
194
|
+
};
|
|
195
|
+
const ifNotExists = () => {
|
|
196
|
+
if (word() === 'IF' && word(1) === 'NOT' && word(2) === 'EXISTS')
|
|
197
|
+
throw new Error(`A declaration does not use IF NOT EXISTS: ${statement}`);
|
|
198
|
+
};
|
|
199
|
+
if (!take('CREATE'))
|
|
200
|
+
unreadable();
|
|
201
|
+
const orReplace = take('OR') ? take('REPLACE') || unreadable() : false;
|
|
202
|
+
const unique = take('UNIQUE');
|
|
203
|
+
const kind = KINDS.get(word() ?? '');
|
|
204
|
+
if (kind === undefined)
|
|
205
|
+
return unreadable();
|
|
206
|
+
at += 1;
|
|
207
|
+
if (unique && kind !== 'index')
|
|
208
|
+
unreadable();
|
|
209
|
+
if (orReplace && !['view', 'function', 'procedure'].includes(kind))
|
|
210
|
+
unreadable();
|
|
211
|
+
ifNotExists();
|
|
212
|
+
const sum = checksum(found);
|
|
213
|
+
if (kind === 'schema') {
|
|
214
|
+
const name = identifier();
|
|
215
|
+
if (at !== found.length)
|
|
216
|
+
throw new Error(`A declared schema has only its name: ${statement}`);
|
|
217
|
+
return {
|
|
218
|
+
statement,
|
|
219
|
+
kind,
|
|
220
|
+
object: { schema: name, name },
|
|
221
|
+
qualified: name,
|
|
222
|
+
checksum: sum,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
if (kind === 'index') {
|
|
226
|
+
if (word() === 'CONCURRENTLY')
|
|
227
|
+
unreadable();
|
|
228
|
+
const name = identifier();
|
|
229
|
+
if (dot())
|
|
230
|
+
unreadable();
|
|
231
|
+
if (!take('ON'))
|
|
232
|
+
unreadable();
|
|
233
|
+
take('ONLY');
|
|
234
|
+
const table = qualifiedName();
|
|
235
|
+
return {
|
|
236
|
+
statement,
|
|
237
|
+
kind,
|
|
238
|
+
object: { schema: table.schema, name },
|
|
239
|
+
qualified: `${table.schema}.${name}`,
|
|
240
|
+
table,
|
|
241
|
+
checksum: sum,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
const object = qualifiedName();
|
|
245
|
+
return {
|
|
246
|
+
statement,
|
|
247
|
+
kind,
|
|
248
|
+
object,
|
|
249
|
+
qualified: `${object.schema}.${object.name}`,
|
|
250
|
+
checksum: sum,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=postgres-statement.js.map
|
|
@@ -0,0 +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,MAAM,UAAU,GAAG,mBAAmB,CAAC;AACvC,MAAM,IAAI,GAAG,uBAAuB,CAAC;AACrC,MAAM,MAAM,GACV,oFAAoF,CAAC;AACvF,MAAM,UAAU,GAAG,kDAAkD,CAAC;AAEtE,2EAA2E;AAC3E,gFAAgF;AAChF,6EAA6E;AAC7E,yBAAyB;AACzB,SAAS,MAAM,CAAC,SAAiB;IAC/B,MAAM,KAAK,GAAY,EAAE,CAAC;IAC1B,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAS,EAAE;QACvC,MAAM,IAAI,KAAK,CACb,gDAAgD,IAAI,KAAK,SAAS,EAAE,CACrE,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,EAAE,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;QACjC,MAAM,IAAI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,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":"postgres.d.ts","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,KAAK,eAAe,EACpB,KAAK,YAAY,GAClB,MAAM,oCAAoC,CAAC"}
|
package/dist/postgres.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,GAGpB,MAAM,oCAAoC,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.284",
|
|
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": {
|
|
@@ -32,6 +32,12 @@
|
|
|
32
32
|
"import": "./dist/index.js",
|
|
33
33
|
"default": "./dist/index.js"
|
|
34
34
|
},
|
|
35
|
+
"./postgres": {
|
|
36
|
+
"@zukhruf/source": "./src/postgres.ts",
|
|
37
|
+
"types": "./dist/postgres.d.ts",
|
|
38
|
+
"import": "./dist/postgres.js",
|
|
39
|
+
"default": "./dist/postgres.js"
|
|
40
|
+
},
|
|
35
41
|
"./sqlite": {
|
|
36
42
|
"@zukhruf/source": "./src/sqlite.ts",
|
|
37
43
|
"types": "./dist/sqlite.d.ts",
|
|
@@ -49,12 +55,12 @@
|
|
|
49
55
|
"access": "public"
|
|
50
56
|
},
|
|
51
57
|
"dependencies": {
|
|
52
|
-
"@zukhruf/sqlite-open": "^0.8.
|
|
53
|
-
"@zukhruf/sqlite-transaction": "^0.8.
|
|
58
|
+
"@zukhruf/sqlite-open": "^0.8.284",
|
|
59
|
+
"@zukhruf/sqlite-transaction": "^0.8.284"
|
|
54
60
|
},
|
|
55
61
|
"devDependencies": {
|
|
56
|
-
"@zukhruf/fs": "^0.8.
|
|
57
|
-
"@zukhruf/parameterized-test": "^0.8.
|
|
58
|
-
"@zukhruf/testing": "^0.8.
|
|
62
|
+
"@zukhruf/fs": "^0.8.284",
|
|
63
|
+
"@zukhruf/parameterized-test": "^0.8.284",
|
|
64
|
+
"@zukhruf/testing": "^0.8.284"
|
|
59
65
|
}
|
|
60
66
|
}
|