@intentius/chant-lexicon-sql 0.112.1 → 0.114.0
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/dist/clickhouse/apply/apply.d.ts +6 -1
- package/dist/clickhouse/apply/apply.d.ts.map +1 -1
- package/dist/clickhouse/apply/statements.d.ts +85 -1
- package/dist/clickhouse/apply/statements.d.ts.map +1 -1
- package/dist/clickhouse/live/bind.d.ts +11 -1
- package/dist/clickhouse/live/bind.d.ts.map +1 -1
- package/dist/clickhouse/plan/commands.d.ts +12 -1
- package/dist/clickhouse/plan/commands.d.ts.map +1 -1
- package/dist/clickhouse/plan/deep.d.ts.map +1 -1
- package/dist/clickhouse/plan/diff.d.ts.map +1 -1
- package/dist/clickhouse/plan/normalize.d.ts.map +1 -1
- package/dist/clickhouse/plan/schema.d.ts +4 -3
- package/dist/clickhouse/plan/schema.d.ts.map +1 -1
- package/dist/clickhouse/rebuild/backfill.d.ts.map +1 -1
- package/dist/clickhouse/rebuild/receipts.d.ts +5 -0
- package/dist/clickhouse/rebuild/receipts.d.ts.map +1 -1
- package/dist/clickhouse/rebuild/steps.d.ts.map +1 -1
- package/dist/clickhouse/topology.d.ts +112 -0
- package/dist/clickhouse/topology.d.ts.map +1 -0
- package/dist/clickhouse.d.ts +1 -0
- package/dist/clickhouse.d.ts.map +1 -1
- package/dist/codegen/classifier-page.d.ts.map +1 -1
- package/dist/codegen/postgres-classifier-page.d.ts.map +1 -1
- package/dist/config.d.ts +46 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/core/statements.d.ts +106 -0
- package/dist/core/statements.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/integrity.json +2 -2
- package/dist/manifest.json +1 -1
- package/dist/migration-statements.d.ts +63 -0
- package/dist/migration-statements.d.ts.map +1 -0
- package/dist/postgres/apply/apply.d.ts.map +1 -1
- package/dist/postgres/apply/statements.d.ts +91 -1
- package/dist/postgres/apply/statements.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/clickhouse/apply/apply.ts +35 -56
- package/src/clickhouse/apply/statements.ts +168 -31
- package/src/clickhouse/live/bind.ts +13 -1
- package/src/clickhouse/live/live.test.ts +10 -0
- package/src/clickhouse/plan/commands.ts +63 -9
- package/src/clickhouse/plan/deep.ts +2 -1
- package/src/clickhouse/plan/diff.ts +3 -1
- package/src/clickhouse/plan/normalize.ts +11 -2
- package/src/clickhouse/plan/schema.ts +6 -5
- package/src/clickhouse/rebuild/backfill.ts +1 -0
- package/src/clickhouse/rebuild/receipts.ts +14 -4
- package/src/clickhouse/rebuild/steps.ts +8 -5
- package/src/clickhouse/topology-replicated.e2e.test.ts +125 -0
- package/src/clickhouse/topology.e2e.test.ts +183 -0
- package/src/clickhouse/topology.test.ts +309 -0
- package/src/clickhouse/topology.ts +477 -0
- package/src/clickhouse.ts +16 -0
- package/src/codegen/classifier-page.ts +19 -0
- package/src/codegen/postgres-classifier-page.ts +17 -0
- package/src/config.ts +33 -0
- package/src/core/statements.ts +129 -0
- package/src/index.ts +15 -0
- package/src/migration-statements.test.ts +384 -0
- package/src/migration-statements.ts +262 -0
- package/src/op/__snapshots__/watch-pipeline.test.ts.snap +93 -0
- package/src/op/activities/clickhouse-apply.ts +1 -1
- package/src/op/activities/clickhouse-rebuild.ts +1 -1
- package/src/op/apply-gate-create.e2e.test.ts +280 -0
- package/src/op/watch-drift.e2e.test.ts +302 -0
- package/src/op/watch-pipeline.test.ts +113 -0
- package/src/plugin.test.ts +9 -0
- package/src/postgres/apply/apply.ts +38 -96
- package/src/postgres/apply/statements.ts +145 -2
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The statements a schema change takes, rendered offline (#3644), the same
|
|
3
|
+
* shape in every dialect: what `diffStatements`
|
|
4
|
+
* (`../migration-statements.ts`) returns and `chant sql diff --statements
|
|
5
|
+
* --json` prints, for a migration file to hold.
|
|
6
|
+
*
|
|
7
|
+
* Every value is plain JSON: strings, booleans, arrays and objects, no
|
|
8
|
+
* `undefined` left in, so the document reads back as it was written. Steps
|
|
9
|
+
* are in the order they run.
|
|
10
|
+
*/
|
|
11
|
+
/** A classified change, as a step names the changes it makes. */
|
|
12
|
+
export interface StatementChange {
|
|
13
|
+
/** The classifier rule, e.g. `SQLCH201`, `SQLPG240`. */
|
|
14
|
+
rule: string;
|
|
15
|
+
/** That rule's class, e.g. `metadata`, `rewrite`, `concurrently`. */
|
|
16
|
+
class: string;
|
|
17
|
+
/** What changed, e.g. `columns.region`, `orderBy`. */
|
|
18
|
+
field: string;
|
|
19
|
+
before?: string;
|
|
20
|
+
after?: string;
|
|
21
|
+
/** Data is removed and not recoverable. */
|
|
22
|
+
destructive?: boolean;
|
|
23
|
+
note?: string;
|
|
24
|
+
}
|
|
25
|
+
/** What every step says about the object it is for. */
|
|
26
|
+
export interface StepObject {
|
|
27
|
+
/** The object's export name: in the newer build, or the older one for an object it drops. */
|
|
28
|
+
object: string;
|
|
29
|
+
/** Its entity type, e.g. `ClickHouse::Table`, `Postgres::Index`. */
|
|
30
|
+
type: string;
|
|
31
|
+
/** Its name on the server: `database.name` or `schema.name`, or a database's, schema's or extension's own name. */
|
|
32
|
+
name: string;
|
|
33
|
+
}
|
|
34
|
+
/** One statement, as the applier would send it. */
|
|
35
|
+
export interface StatementStep extends StepObject {
|
|
36
|
+
kind: "statement";
|
|
37
|
+
sql: string;
|
|
38
|
+
/** The rule of the change it makes. */
|
|
39
|
+
rule: string;
|
|
40
|
+
/** That rule's class. */
|
|
41
|
+
class: string;
|
|
42
|
+
/** False for a statement that may not run inside a transaction block (Postgres `CONCURRENTLY`, `ALTER TYPE ... ADD VALUE`). Always false for ClickHouse, which has none. */
|
|
43
|
+
transactional: boolean;
|
|
44
|
+
/** ClickHouse: the statement starts a mutation; wait for it in `system.mutations` before the next one. */
|
|
45
|
+
waitsForMutation?: boolean;
|
|
46
|
+
/** The statement removes data that is not recoverable (a column or table drop). */
|
|
47
|
+
destructive?: boolean;
|
|
48
|
+
}
|
|
49
|
+
/** A change no statement makes in place, made by a migration Op. */
|
|
50
|
+
export interface OpStep extends StepObject {
|
|
51
|
+
kind: "op";
|
|
52
|
+
/** The Op's export name. */
|
|
53
|
+
op: "ClickHouseRebuildOp" | "PostgresMigrationOp";
|
|
54
|
+
/** The module the Op is imported from. */
|
|
55
|
+
importPath: string;
|
|
56
|
+
/** The Op's options as the hand-off suggests them: `name`, `env`, `table`, and `dualWrite` (ClickHouse) or `column` (Postgres). */
|
|
57
|
+
options: Record<string, unknown>;
|
|
58
|
+
/** The Op's declaration, ready for an `*.op.ts` file. */
|
|
59
|
+
declaration: string;
|
|
60
|
+
/** The changes the Op makes. */
|
|
61
|
+
changes: StatementChange[];
|
|
62
|
+
/** The refusal as the applier reports it: each rule, its restriction, and the Op. */
|
|
63
|
+
detail: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A change neither a statement nor an Op makes: a rebuild of a view or a
|
|
67
|
+
* database, an expand-and-contract change no Op covers, a change with no
|
|
68
|
+
* in-place statement, or the object's other changes that the applier holds
|
|
69
|
+
* back while one of its changes is refused.
|
|
70
|
+
*/
|
|
71
|
+
export interface ManualStep extends StepObject {
|
|
72
|
+
kind: "manual";
|
|
73
|
+
changes: StatementChange[];
|
|
74
|
+
detail: string;
|
|
75
|
+
}
|
|
76
|
+
export type MigrationStep = StatementStep | OpStep | ManualStep;
|
|
77
|
+
export interface SchemaStatements {
|
|
78
|
+
dialect: "clickhouse" | "postgres";
|
|
79
|
+
/** ClickHouse: the database a bare name means. */
|
|
80
|
+
defaultDatabase?: string;
|
|
81
|
+
/** ClickHouse: the topology the statements are rendered for, in its string form (`single`, `cluster:<name>`, `replicated`, `cloud`). */
|
|
82
|
+
topology?: string;
|
|
83
|
+
/** Postgres: the schema a bare name means; the applier sets `search_path` to it. */
|
|
84
|
+
defaultSchema?: string;
|
|
85
|
+
/** Postgres: the major the changes were classified for. */
|
|
86
|
+
major?: number;
|
|
87
|
+
/** In the order they run: each object's in the newer build's creation order, then the drops. */
|
|
88
|
+
steps: MigrationStep[];
|
|
89
|
+
/** True when a step is an Op or manual: the schema change is more than statements. */
|
|
90
|
+
refused: boolean;
|
|
91
|
+
/** What the diff points out besides the changes (a likely rename written as a drop and an add). */
|
|
92
|
+
hints: string[];
|
|
93
|
+
}
|
|
94
|
+
/** A classified change as a step names it, with no `undefined` fields. */
|
|
95
|
+
export declare function statementChange(c: {
|
|
96
|
+
rule: string;
|
|
97
|
+
class: string;
|
|
98
|
+
field: string;
|
|
99
|
+
before?: string;
|
|
100
|
+
after?: string;
|
|
101
|
+
destructive?: boolean;
|
|
102
|
+
note?: string;
|
|
103
|
+
}): StatementChange;
|
|
104
|
+
/** The steps as a migration file's SQL: each statement after a comment naming its object, rule and class; an Op or manual step as a comment. */
|
|
105
|
+
export declare function renderStatements(doc: SchemaStatements): string;
|
|
106
|
+
//# sourceMappingURL=statements.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statements.d.ts","sourceRoot":"","sources":["../../src/core/statements.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,iEAAiE;AACjE,MAAM,WAAW,eAAe;IAC9B,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,uDAAuD;AACvD,MAAM,WAAW,UAAU;IACzB,6FAA6F;IAC7F,MAAM,EAAE,MAAM,CAAC;IACf,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,mHAAmH;IACnH,IAAI,EAAE,MAAM,CAAC;CACd;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KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gGAAgG;IAChG,KAAK,EAAE,aAAa,EAAE,CAAC;IACvB,sFAAsF;IACtF,OAAO,EAAE,OAAO,CAAC;IACjB,mGAAmG;IACnG,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,0EAA0E;AAC1E,wBAAgB,eAAe,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,eAAe,CAUzK;AAED,gJAAgJ;AAChJ,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,gBAAgB,GAAG,MAAM,CAa9D"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export { SQL_DIALECTS, type SqlDialect } from "./dialects.js";
|
|
|
4
4
|
export { sqlConfigSchema, type SqlConfig } from "./config.js";
|
|
5
5
|
export { database, table, view, literal } from "./clickhouse/entities.js";
|
|
6
6
|
export { schema, index, sequence, type, domain, extension } from "./postgres/entities.js";
|
|
7
|
+
export { diffStatements, renderStatements, type DiffStatementsOptions, type ManualStep, type MigrationStep, type OpStep, type SchemaStatements, type StatementChange, type StatementStep, type StepObject, } from "./migration-statements.js";
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAM3D,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAMvE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAM3D,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAMvE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAIvF,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,UAAU,GAChB,MAAM,wBAAwB,CAAC"}
|
package/dist/integrity.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"algorithm": "sha256",
|
|
3
3
|
"artifacts": {
|
|
4
|
-
"manifest.json": "
|
|
4
|
+
"manifest.json": "4d4b3853d5595af4a169a82b6c45f87a103adace1fdff4e61181bcf34aa0a0e2",
|
|
5
5
|
"meta.json": "5b7a5d171aa8bd21c0d55cfbe421143d67da02b7ef924a9b66166790c3fc7b22",
|
|
6
6
|
"types/index.d.ts": "0286ebb367773e84c76818b0f69cb14cff8328fd2f8c65ed87563c8d5815458c",
|
|
7
7
|
"rules/postgres-templates.ts": "f7244417426c441180ccb5c52da32cd812960d6d4eaba1fbdb17f47fcae707b2",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"rules/sqlpg117.ts": "3d5c2d57ccdee3cf91c3ba3cb6363750787a850df8ebd75e9cc3f33113303827",
|
|
58
58
|
"rules/sqlpg118.ts": "e2a40a88a9374c4d99d02118ca4c60877ba0c6eb1ce603a93b24f5fd23d81dde"
|
|
59
59
|
},
|
|
60
|
-
"composite": "
|
|
60
|
+
"composite": "8d565dbc9a455095b5d5e81aac886a7af1b2cb1f3a6e21d0a4ed513b08e1b52a"
|
|
61
61
|
}
|
package/dist/manifest.json
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A schema change's statements, rendered offline (#3644): for two `chant
|
|
3
|
+
* build` outputs, the ordered statements that take the first to the second,
|
|
4
|
+
* each with its change's class and rule, for a migration file. No server is
|
|
5
|
+
* read.
|
|
6
|
+
*
|
|
7
|
+
* The statements are the applier's: each dialect's `planStatements` /
|
|
8
|
+
* `planPgStatements` (`./clickhouse/apply/statements.ts`,
|
|
9
|
+
* `./postgres/apply/statements.ts`) turns classified changes into steps, and
|
|
10
|
+
* both the applier and this renderer call it. What differs is only where the
|
|
11
|
+
* current schema comes from: here the older build, keyed by export name as
|
|
12
|
+
* `chant sql diff` keys it; in the applier the server's catalog.
|
|
13
|
+
*
|
|
14
|
+
* A change the applier refuses in place is a step naming the Op that makes
|
|
15
|
+
* it, never DDL: a ClickHouse rebuild is `ClickHouseRebuildOp`, a Postgres
|
|
16
|
+
* column rename or type change across kinds is `PostgresMigrationOp`. One no
|
|
17
|
+
* Op makes is a manual step. Column and object drops are statements, marked
|
|
18
|
+
* destructive.
|
|
19
|
+
*
|
|
20
|
+
* Where the applier asks the server something, the renderer cannot:
|
|
21
|
+
*
|
|
22
|
+
* - ClickHouse: the applier also asks the server's formatter whether a
|
|
23
|
+
* difference the rules leave is only formatting; the offline diff is the
|
|
24
|
+
* rules' alone, as `chant sql diff` is. Before dropping a database it
|
|
25
|
+
* checks the database is empty.
|
|
26
|
+
* - Postgres: the applier asks the server to normalize expressions the rules
|
|
27
|
+
* leave different, and keeps an extension's own comment (from its control
|
|
28
|
+
* file) under the trailer when the declaration sets none.
|
|
29
|
+
* - Both: the applier restamps an object whose comment lost chant's marker;
|
|
30
|
+
* offline, the older build's objects carry it.
|
|
31
|
+
*/
|
|
32
|
+
import type { OwnershipMarker } from "@intentius/chant/ownership";
|
|
33
|
+
import { type SchemaStatements } from "./core/statements.js";
|
|
34
|
+
import { type Topology } from "./clickhouse/topology.js";
|
|
35
|
+
export type { ManualStep, MigrationStep, OpStep, SchemaStatements, StatementChange, StatementStep, StepObject } from "./core/statements.js";
|
|
36
|
+
export { renderStatements } from "./core/statements.js";
|
|
37
|
+
export interface DiffStatementsOptions {
|
|
38
|
+
/** The ownership marker every `CREATE` and restamped comment carries, as the applier stamps it. Default: `managed-by=chant` alone. */
|
|
39
|
+
marker?: OwnershipMarker;
|
|
40
|
+
/** The environment an Op step's suggested declaration names. Default: `<env>`. */
|
|
41
|
+
env?: string;
|
|
42
|
+
/** ClickHouse: the database a bare name means. Default: `default`. */
|
|
43
|
+
defaultDatabase?: string;
|
|
44
|
+
/**
|
|
45
|
+
* ClickHouse: the topology to render the statements for
|
|
46
|
+
* (`./clickhouse/topology.ts`): `ON CLUSTER` and the engine, on both
|
|
47
|
+
* builds' declarations before they are compared, so the steps are the ones
|
|
48
|
+
* the applier sends to an environment with that topology. Default: `single`.
|
|
49
|
+
*/
|
|
50
|
+
topology?: Topology;
|
|
51
|
+
/** Postgres: the schema a bare name means. Default: `public`. */
|
|
52
|
+
defaultSchema?: string;
|
|
53
|
+
/** Postgres: the major to classify for. Default: the newer build's `postgresMajor`, else the older's, else the newest pinned. */
|
|
54
|
+
major?: number;
|
|
55
|
+
}
|
|
56
|
+
type BuildInput = string | object;
|
|
57
|
+
/**
|
|
58
|
+
* The statements that take the schema `before` builds to the one `after`
|
|
59
|
+
* builds. Each is a `chant build` output of the sql lexicon, as JSON text or
|
|
60
|
+
* parsed. Both must be the same dialect.
|
|
61
|
+
*/
|
|
62
|
+
export declare function diffStatements(before: BuildInput, after: BuildInput, options?: DiffStatementsOptions): SchemaStatements;
|
|
63
|
+
//# sourceMappingURL=migration-statements.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-statements.d.ts","sourceRoot":"","sources":["../src/migration-statements.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAwD,KAAK,gBAAgB,EAAmB,MAAM,mBAAmB,CAAC;AAGjI,OAAO,EAAiB,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAWrE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,gBAAgB,EAAE,eAAe,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACzI,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,MAAM,WAAW,qBAAqB;IACpC,sIAAsI;IACtI,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,kFAAkF;IAClF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,sEAAsE;IACtE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,iEAAiE;IACjE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iIAAiI;IACjI,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,KAAK,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;AAWlC;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,GAAE,qBAA0B,GAAG,gBAAgB,CAQ3H"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../../src/postgres/apply/apply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../../src/postgres/apply/apply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAiE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEtI,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAgB,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAMpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAA+B,KAAK,gBAAgB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;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,SAAW,GAAG,gBAAgB,EAAE,CAc1F;AAED,0FAA0F;AAC1F,eAAO,MAAM,QAAQ,GAAI,UAAU,SAAS,gBAAgB,EAAE,KAAG,QAAQ,EAA2D,CAAC;AAErI,MAAM,WAAW,oBAAoB;IACnC,8FAA8F;IAC9F,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,6FAA6F;IAC7F,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,gGAAgG;IAChG,QAAQ,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC1C,oFAAoF;IACpF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,wDAAwD;IACxD,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,gFAAgF;IAChF,QAAQ,CAAC,EAAE,OAAO,cAAc,CAAC;IACjC,kEAAkE;IAClE,eAAe,CAAC,EAAE,OAAO,gBAAgB,CAAC;CAC3C;AAkCD;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,cAAc,EACtB,QAAQ,EAAE,SAAS,gBAAgB,EAAE,EACrC,IAAI,GAAE,oBAAyB,GAC9B,OAAO,CAAC,oBAAoB,CAAC,CA4M/B"}
|
|
@@ -25,7 +25,7 @@ import { type PostgresEntityType } from "../entity-types.js";
|
|
|
25
25
|
import type { PgChange } from "../plan/diff.js";
|
|
26
26
|
import { type PgChangeClass, type PgClassifierRuleId } from "../plan/rules.js";
|
|
27
27
|
import { type CanonicalConstraint, type CanonicalKind } from "../plan/normalize.js";
|
|
28
|
-
import type { PgDiffObject } from "../plan/schema.js";
|
|
28
|
+
import type { PgDiffObject, PgSchemaObject } from "../plan/schema.js";
|
|
29
29
|
import type { CheckDef, ColumnDef, ExclusionDef, ForeignKeyDef, KeyDef, SequenceProps } from "../entities.js";
|
|
30
30
|
/** One object as a build declares it, in the shape the applier works with. */
|
|
31
31
|
export interface DeclaredPgObject {
|
|
@@ -134,5 +134,95 @@ export declare const scansRows: (cls: PgChangeClass) => boolean;
|
|
|
134
134
|
* `PostgresMigrationOp` for (`../migrate/handoff.ts`).
|
|
135
135
|
*/
|
|
136
136
|
export declare function refusalDetail(changes: readonly PgChange[], name: string, declared?: Pick<PgDiffObject, "kind" | "schema" | "name">): string;
|
|
137
|
+
/**
|
|
138
|
+
* What one declared object takes, as the applier and the offline renderer
|
|
139
|
+
* (`../../migration-statements.ts`) both see it:
|
|
140
|
+
*
|
|
141
|
+
* - `create` or `alter`: the statements, in the order they run. An `alter`
|
|
142
|
+
* with none is an object already as declared.
|
|
143
|
+
* - `foreign`: another tool keeps the object; it is not chant's to change.
|
|
144
|
+
* - `refused`: a change only expand and contract makes; nothing is sent for
|
|
145
|
+
* the object, and `detail` names the migration Op where one makes it.
|
|
146
|
+
* - `unsupported`: a change with no in-place statement; nothing is sent.
|
|
147
|
+
* - `withheld`: a column drop, which destroys data, in a plan not allowed to
|
|
148
|
+
* delete.
|
|
149
|
+
*/
|
|
150
|
+
export type PgObjectStatements = {
|
|
151
|
+
verdict: "create" | "alter";
|
|
152
|
+
obj: DeclaredPgObject;
|
|
153
|
+
changes: PgChange[];
|
|
154
|
+
steps: PgStep[];
|
|
155
|
+
live?: PgDiffObject;
|
|
156
|
+
} | {
|
|
157
|
+
verdict: "foreign";
|
|
158
|
+
obj: DeclaredPgObject;
|
|
159
|
+
changes: PgChange[];
|
|
160
|
+
live: PgDiffObject;
|
|
161
|
+
detail: string;
|
|
162
|
+
} | {
|
|
163
|
+
verdict: "refused";
|
|
164
|
+
obj: DeclaredPgObject;
|
|
165
|
+
changes: PgChange[];
|
|
166
|
+
refused: PgChange[];
|
|
167
|
+
live?: PgDiffObject;
|
|
168
|
+
detail: string;
|
|
169
|
+
} | {
|
|
170
|
+
verdict: "unsupported";
|
|
171
|
+
obj: DeclaredPgObject;
|
|
172
|
+
changes: PgChange[];
|
|
173
|
+
unsupported: UnsupportedChange[];
|
|
174
|
+
live: PgDiffObject;
|
|
175
|
+
detail: string;
|
|
176
|
+
} | {
|
|
177
|
+
verdict: "withheld";
|
|
178
|
+
obj: DeclaredPgObject;
|
|
179
|
+
changes: PgChange[];
|
|
180
|
+
withheld: PgChange[];
|
|
181
|
+
live?: PgDiffObject;
|
|
182
|
+
detail: string;
|
|
183
|
+
};
|
|
184
|
+
/** An object the declarations no longer hold, and the `DROP` for it. */
|
|
185
|
+
export interface PgDropStatement {
|
|
186
|
+
/** The key the changes name it by. */
|
|
187
|
+
key: string;
|
|
188
|
+
kind: CanonicalKind;
|
|
189
|
+
schema?: string;
|
|
190
|
+
name: string;
|
|
191
|
+
step: PgStep;
|
|
192
|
+
}
|
|
193
|
+
export interface PgStatementPlanInput {
|
|
194
|
+
/** The declared objects in creation order, in the canonical form the changes were found for. */
|
|
195
|
+
declared: readonly DeclaredPgObject[];
|
|
196
|
+
/** The classified changes from the current schema to the declared one. */
|
|
197
|
+
changes: readonly PgChange[];
|
|
198
|
+
/** The current schema, keyed as the changes key objects. */
|
|
199
|
+
current: readonly PgSchemaObject[];
|
|
200
|
+
/** How the changes key a declared object: its qualified key against a server (the default), its export name between two builds. */
|
|
201
|
+
keyOf?: (obj: DeclaredPgObject) => string;
|
|
202
|
+
/** The major the statements are for. */
|
|
203
|
+
major: number;
|
|
204
|
+
/** The marker every created object and restamped comment carries. */
|
|
205
|
+
marker?: OwnershipMarker;
|
|
206
|
+
/** Column drops are planned, not withheld. Default: off. */
|
|
207
|
+
allowDestructive?: boolean;
|
|
208
|
+
/** Whether the current object carries the marker already; one that does not is restamped. Default: it does. */
|
|
209
|
+
carriesMarker?: (live: PgDiffObject, currentKey: string) => boolean;
|
|
210
|
+
/** The comment an extension's control file sets, kept under the trailer when the declaration sets none. */
|
|
211
|
+
extensionComment?: (name: string) => string | undefined;
|
|
212
|
+
}
|
|
213
|
+
export interface PgStatementPlan {
|
|
214
|
+
/** One entry per declared object, in creation order. */
|
|
215
|
+
objects: PgObjectStatements[];
|
|
216
|
+
/** The objects the declarations no longer hold, in drop order: views first, a schema last. */
|
|
217
|
+
drops: PgDropStatement[];
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* The statements that take the current schema to the declared one, from the
|
|
221
|
+
* classified changes between them. Pure: nothing is read or sent. The applier
|
|
222
|
+
* (`./apply.ts`) groups the steps into transactions and runs them;
|
|
223
|
+
* `diffStatements` (`../../migration-statements.ts`) renders the same steps
|
|
224
|
+
* for a migration file.
|
|
225
|
+
*/
|
|
226
|
+
export declare function planPgStatements(input: PgStatementPlanInput): PgStatementPlan;
|
|
137
227
|
export {};
|
|
138
228
|
//# sourceMappingURL=statements.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statements.d.ts","sourceRoot":"","sources":["../../../src/postgres/apply/statements.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,EAA0B,KAAK,KAAK,EAAE,MAAM,WAAW,CAAC;AAG/D,OAAO,EAAyB,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAEjF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAuB,KAAK,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACjG,OAAO,EAAoC,KAAK,mBAAmB,EAAE,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACnH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"statements.d.ts","sourceRoot":"","sources":["../../../src/postgres/apply/statements.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAA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"0.
|
|
3
|
+
"version": "0.114.0",
|
|
4
4
|
"description": "SQL lexicon for chant — database schema as typed declarations, one dialect at a time; ClickHouse first, with types read from a pinned server's catalog",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://intentius.io/chant",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"typescript": "^5.9.3"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
|
-
"@intentius/chant": "^0.
|
|
73
|
+
"@intentius/chant": "^0.114.0",
|
|
74
74
|
"typescript": "^5.9.3"
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -36,7 +36,6 @@ import type { OwnershipMarker } from "@intentius/chant/ownership";
|
|
|
36
36
|
import type { ApplyRef } from "@intentius/chant/apply";
|
|
37
37
|
import {
|
|
38
38
|
SqlApplyError,
|
|
39
|
-
changesByObject,
|
|
40
39
|
dependencyFailedDetail,
|
|
41
40
|
missingDependencies,
|
|
42
41
|
readBuildObjects,
|
|
@@ -50,20 +49,9 @@ import { diffSchemas, type Change } from "../plan/diff";
|
|
|
50
49
|
import { dropFormattingOnly } from "../plan/server-format";
|
|
51
50
|
import { CLICKHOUSE_ENTITY_TYPES, type ClickHouseEntityType } from "../entities";
|
|
52
51
|
import { carriesMarker, isChantManaged } from "../ownership";
|
|
53
|
-
import {
|
|
54
|
-
alterSteps,
|
|
55
|
-
commentStatement,
|
|
56
|
-
createStatement,
|
|
57
|
-
dropStatement,
|
|
58
|
-
isDestructiveAlter,
|
|
59
|
-
isRebuild,
|
|
60
|
-
refusalDetail,
|
|
61
|
-
sqlString,
|
|
62
|
-
stepsSetComment,
|
|
63
|
-
type DeclaredObject,
|
|
64
|
-
type Step,
|
|
65
|
-
} from "./statements";
|
|
52
|
+
import { planStatements, sqlString, type DeclaredObject, type DropStatement, type Step } from "./statements";
|
|
66
53
|
import { waitForMutations } from "./mutations";
|
|
54
|
+
import { renderFor, type Topology } from "../topology";
|
|
67
55
|
|
|
68
56
|
export type { FailedObject } from "../../core/apply";
|
|
69
57
|
|
|
@@ -71,15 +59,20 @@ export type { FailedObject } from "../../core/apply";
|
|
|
71
59
|
* The objects a `chant build` output declares, in creation order. Takes the
|
|
72
60
|
* sql lexicon's primary output, or a multi-lexicon output holding it under
|
|
73
61
|
* `sql` (the shared core's reader).
|
|
62
|
+
*
|
|
63
|
+
* With a `topology`, each declaration is rendered for it first
|
|
64
|
+
* (`../topology.ts`): the engine and `ON CLUSTER` it runs with there, which
|
|
65
|
+
* is what the changes compare and every `CREATE` sends.
|
|
74
66
|
*/
|
|
75
|
-
export function declaredObjects(json: string, defaultDatabase = "default"): DeclaredObject[] {
|
|
67
|
+
export function declaredObjects(json: string, defaultDatabase = "default", topology?: Topology): DeclaredObject[] {
|
|
76
68
|
return readBuildObjects(json, "clickhouse", (o) => {
|
|
77
|
-
const
|
|
69
|
+
const ddl = renderFor(o.ddl, topology);
|
|
70
|
+
const canonical = canonicalObject(ddl, defaultDatabase);
|
|
78
71
|
return {
|
|
79
72
|
exportName: o.export,
|
|
80
73
|
type: o.type as ClickHouseEntityType,
|
|
81
74
|
key: canonical.database !== undefined ? `${canonical.database}.${canonical.name}` : canonical.name,
|
|
82
|
-
ddl
|
|
75
|
+
ddl,
|
|
83
76
|
canonical,
|
|
84
77
|
dependsOn: o.dependsOn,
|
|
85
78
|
};
|
|
@@ -117,14 +110,6 @@ export class ClickHouseApplyError extends SqlApplyError<ClickHouseApplyOutcome>
|
|
|
117
110
|
|
|
118
111
|
const liveKey = (o: LiveObject) => (o.database !== undefined ? `${o.database}.${o.name}` : o.name);
|
|
119
112
|
|
|
120
|
-
/** Drop order: what reads from a table before the table, a database last. */
|
|
121
|
-
const DROP_ORDER: Record<string, number> = {
|
|
122
|
-
[CLICKHOUSE_ENTITY_TYPES.materializedView]: 0,
|
|
123
|
-
[CLICKHOUSE_ENTITY_TYPES.view]: 1,
|
|
124
|
-
[CLICKHOUSE_ENTITY_TYPES.table]: 2,
|
|
125
|
-
[CLICKHOUSE_ENTITY_TYPES.database]: 3,
|
|
126
|
-
};
|
|
127
|
-
|
|
128
113
|
/**
|
|
129
114
|
* The server's objects in the databases the declarations use, as the diff
|
|
130
115
|
* compares them. The `default` database itself is never part of a schema.
|
|
@@ -160,7 +145,6 @@ export async function applyClickHouse(target: ClickHouseTarget, declared: readon
|
|
|
160
145
|
const { objects: liveObjects, canonical: live } = await liveSchema(target, declared);
|
|
161
146
|
const liveByKey = new Map(liveObjects.map((o) => [liveKey(o), o]));
|
|
162
147
|
const changes = await plannedChanges(target, declared, live);
|
|
163
|
-
const byObject = changesByObject(changes);
|
|
164
148
|
|
|
165
149
|
const outcome: ClickHouseApplyOutcome = { target: target.endpoint.url, source: target.source, applied: [], pruned: [], notAttempted: [], failed: [] };
|
|
166
150
|
/** Export names whose object is on the server. */
|
|
@@ -181,35 +165,34 @@ export async function applyClickHouse(target: ClickHouseTarget, declared: readon
|
|
|
181
165
|
}
|
|
182
166
|
};
|
|
183
167
|
|
|
184
|
-
|
|
168
|
+
const plan = planStatements({
|
|
169
|
+
declared,
|
|
170
|
+
changes,
|
|
171
|
+
current: live,
|
|
172
|
+
allowDestructive: opts.prune === true,
|
|
173
|
+
carriesMarker: (key) => carriesMarker(liveByKey.get(key)?.comment, opts.marker),
|
|
174
|
+
...(target.topology ? { topology: target.topology } : {}),
|
|
175
|
+
...(opts.marker ? { marker: opts.marker } : {}),
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
for (const entry of plan.objects) {
|
|
179
|
+
const obj = entry.obj;
|
|
185
180
|
const ref = { kind: obj.type, name: obj.key };
|
|
186
|
-
const
|
|
187
|
-
const created = mine.some((c) => c.rule === "SQLCH200");
|
|
188
|
-
const renamedFrom = mine.find((c) => c.rule === "SQLCH230" || c.rule === "SQLCH231")?.before;
|
|
181
|
+
const renamedFrom = entry.changes.find((c) => c.rule === "SQLCH230" || c.rule === "SQLCH231")?.before;
|
|
189
182
|
const liveObject = liveByKey.get(renamedFrom ?? obj.key);
|
|
190
|
-
const liveCanonical = live.get(renamedFrom ?? obj.key);
|
|
191
183
|
|
|
192
|
-
|
|
193
|
-
if (refused.length > 0) {
|
|
184
|
+
if (entry.verdict === "rebuild") {
|
|
194
185
|
if (liveObject) onServer.add(obj.exportName);
|
|
195
|
-
outcome.notAttempted.push({ ...ref, reason: "unsupported-kind", detail:
|
|
186
|
+
outcome.notAttempted.push({ ...ref, reason: "unsupported-kind", detail: entry.detail });
|
|
196
187
|
continue;
|
|
197
188
|
}
|
|
198
|
-
|
|
199
|
-
if (destructive.length > 0 && !opts.prune) {
|
|
189
|
+
if (entry.verdict === "withheld") {
|
|
200
190
|
onServer.add(obj.exportName);
|
|
201
|
-
outcome.notAttempted.push({
|
|
202
|
-
...ref,
|
|
203
|
-
reason: "filtered",
|
|
204
|
-
detail: `drops ${destructive.map((c) => c.field).join(", ")}, which destroys the data in it; an apply that may delete (prune, ApplyOp delete "owned-only" or "gated") makes it`,
|
|
205
|
-
});
|
|
191
|
+
outcome.notAttempted.push({ ...ref, reason: "filtered", detail: entry.detail });
|
|
206
192
|
continue;
|
|
207
193
|
}
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
const steps: Step[] = created
|
|
211
|
-
? [{ sql: createStatement(obj, opts.marker), rewrite: false }]
|
|
212
|
-
: [...alterSteps(obj, mine, { ...(liveCanonical ? { live: liveCanonical } : {}), ...(opts.marker ? { marker: opts.marker } : {}) }), ...(restamp ? [{ sql: commentStatement(obj, opts.marker), rewrite: false }] : [])];
|
|
194
|
+
const created = entry.verdict === "create";
|
|
195
|
+
const steps = entry.steps;
|
|
213
196
|
|
|
214
197
|
if (steps.length === 0) {
|
|
215
198
|
onServer.add(obj.exportName);
|
|
@@ -235,26 +218,22 @@ export async function applyClickHouse(target: ClickHouseTarget, declared: readon
|
|
|
235
218
|
}
|
|
236
219
|
}
|
|
237
220
|
|
|
238
|
-
if (opts.prune) await prune(target,
|
|
221
|
+
if (opts.prune) await prune(target, plan.drops, liveByKey, opts, outcome, log);
|
|
239
222
|
if (outcome.failed.length > 0) throw new ClickHouseApplyError(outcome);
|
|
240
223
|
return outcome;
|
|
241
224
|
}
|
|
242
225
|
|
|
243
226
|
async function prune(
|
|
244
227
|
target: ClickHouseTarget,
|
|
245
|
-
|
|
228
|
+
drops: readonly DropStatement[],
|
|
246
229
|
liveByKey: Map<string, LiveObject>,
|
|
247
230
|
opts: ClickHouseApplyOptions,
|
|
248
231
|
outcome: ClickHouseApplyOutcome,
|
|
249
232
|
log: (line: string) => void,
|
|
250
233
|
): Promise<void> {
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
.filter((o): o is LiveObject => o !== undefined)
|
|
255
|
-
.sort((a, b) => (DROP_ORDER[a.type] ?? 9) - (DROP_ORDER[b.type] ?? 9));
|
|
256
|
-
|
|
257
|
-
for (const o of orphans) {
|
|
234
|
+
for (const drop of drops) {
|
|
235
|
+
const o = liveByKey.get(drop.key);
|
|
236
|
+
if (!o) continue;
|
|
258
237
|
const ref = { kind: o.type, name: liveKey(o) };
|
|
259
238
|
if (!isChantManaged(o.comment)) continue; // not chant's: never touched, never reported
|
|
260
239
|
if (!opts.marker?.stack) {
|
|
@@ -275,7 +254,7 @@ async function prune(
|
|
|
275
254
|
continue;
|
|
276
255
|
}
|
|
277
256
|
}
|
|
278
|
-
const sql =
|
|
257
|
+
const sql = drop.step.sql;
|
|
279
258
|
opts.signal?.throwIfAborted();
|
|
280
259
|
log(sql);
|
|
281
260
|
await clickhouseQuery(target.endpoint, sql);
|