@intentius/chant-lexicon-sql 0.124.48 → 0.124.50
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/plan/statements.d.ts +29 -0
- package/dist/clickhouse/plan/statements.d.ts.map +1 -0
- package/dist/clickhouse/plan/statements.js +334 -0
- package/dist/codegen/classifier-page.d.ts.map +1 -1
- package/dist/codegen/classifier-page.js +23 -0
- package/dist/codegen/postgres-classifier-page.js +2 -2
- package/dist/codegen/registry.d.ts.map +1 -1
- package/dist/codegen/registry.js +5 -0
- package/dist/core/statement-class.d.ts +55 -0
- package/dist/core/statement-class.d.ts.map +1 -0
- package/dist/core/statement-class.js +43 -0
- package/dist/coverage/postgres.json +6 -6
- package/dist/drizzle.d.ts.map +1 -1
- package/dist/drizzle.js +5 -0
- package/dist/files/postgres.d.ts.map +1 -1
- package/dist/files/postgres.js +23 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/integrity.json +5 -5
- package/dist/lint/post-synth/postgres-names.d.ts.map +1 -1
- package/dist/lint/post-synth/postgres-names.js +3 -0
- package/dist/lint/rules/postgres-templates.js +2 -2
- package/dist/lsp/postgres-template.d.ts.map +1 -1
- package/dist/lsp/postgres-template.js +10 -0
- package/dist/manifest.json +1 -1
- package/dist/mcp/postgres.js +1 -1
- package/dist/meta.json +25 -0
- package/dist/migration-classify.d.ts +23 -0
- package/dist/migration-classify.d.ts.map +1 -0
- package/dist/migration-classify.js +44 -0
- package/dist/okf/index.md +5 -0
- package/dist/okf/types/PostgresForeignTable.md +9 -0
- package/dist/okf/types/PostgresOperatorClass.md +9 -0
- package/dist/okf/types/PostgresOperatorFamily.md +9 -0
- package/dist/okf/types/PostgresTextSearchConfiguration.md +9 -0
- package/dist/okf/types/PostgresTextSearchDictionary.md +9 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +13 -0
- package/dist/postgres/access/acl.js +1 -1
- package/dist/postgres/access/import.js +1 -1
- package/dist/postgres/apply/apply.js +5 -0
- package/dist/postgres/apply/statements.d.ts.map +1 -1
- package/dist/postgres/apply/statements.js +156 -2
- package/dist/postgres/entities.d.ts +120 -2
- package/dist/postgres/entities.d.ts.map +1 -1
- package/dist/postgres/entities.js +180 -5
- package/dist/postgres/entity-types.d.ts +5 -0
- package/dist/postgres/entity-types.d.ts.map +1 -1
- package/dist/postgres/entity-types.js +5 -0
- package/dist/postgres/import/generator.d.ts.map +1 -1
- package/dist/postgres/import/generator.js +16 -1
- package/dist/postgres/live/catalog-kinds.d.ts +6 -0
- package/dist/postgres/live/catalog-kinds.d.ts.map +1 -1
- package/dist/postgres/live/catalog-kinds.js +251 -3
- package/dist/postgres/live/describe-resources.d.ts.map +1 -1
- package/dist/postgres/live/describe-resources.js +2 -0
- package/dist/postgres/migrate/observe.d.ts.map +1 -1
- package/dist/postgres/migrate/observe.js +4 -1
- package/dist/postgres/migrate/replication.d.ts +42 -0
- package/dist/postgres/migrate/replication.d.ts.map +1 -1
- package/dist/postgres/migrate/replication.js +53 -0
- package/dist/postgres/parser.d.ts +73 -1
- package/dist/postgres/parser.d.ts.map +1 -1
- package/dist/postgres/parser.js +181 -7
- package/dist/postgres/plan/deep.d.ts.map +1 -1
- package/dist/postgres/plan/deep.js +15 -4
- package/dist/postgres/plan/diff.d.ts.map +1 -1
- package/dist/postgres/plan/diff.js +120 -5
- package/dist/postgres/plan/normalize.d.ts +12 -1
- package/dist/postgres/plan/normalize.d.ts.map +1 -1
- package/dist/postgres/plan/normalize.js +151 -0
- package/dist/postgres/plan/rules.d.ts +3 -0
- package/dist/postgres/plan/rules.d.ts.map +1 -1
- package/dist/postgres/plan/rules.js +5 -2
- package/dist/postgres/plan/schema.js +1 -1
- package/dist/postgres/plan/statements.d.ts +26 -0
- package/dist/postgres/plan/statements.d.ts.map +1 -0
- package/dist/postgres/plan/statements.js +364 -0
- package/dist/postgres/testing/roundtrip-schema.d.ts +3 -2
- package/dist/postgres/testing/roundtrip-schema.d.ts.map +1 -1
- package/dist/postgres/testing/roundtrip-schema.js +12 -1
- package/dist/postgres.d.ts +1 -1
- package/dist/postgres.d.ts.map +1 -1
- package/dist/postgres.js +1 -1
- package/dist/rules/postgres-names.ts +2 -0
- package/dist/rules/postgres-templates.ts +2 -2
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +5 -0
- package/package.json +2 -2
- package/src/clickhouse/plan/statements.test.ts +61 -0
- package/src/clickhouse/plan/statements.ts +306 -0
- package/src/codegen/classifier-page.ts +23 -0
- package/src/codegen/postgres-classifier-page.ts +2 -2
- package/src/codegen/registry.ts +5 -0
- package/src/core/statement-class.ts +88 -0
- package/src/coverage/postgres.json +6 -6
- package/src/drizzle.ts +5 -0
- package/src/files/postgres.ts +22 -1
- package/src/generated/lexicon-sql.json +25 -0
- package/src/index.ts +1 -1
- package/src/lint/post-synth/postgres-checks.test.ts +8 -1
- package/src/lint/post-synth/postgres-names.ts +2 -0
- package/src/lint/rules/postgres-templates.ts +2 -2
- package/src/lsp/postgres-template.ts +9 -0
- package/src/mcp/postgres.ts +1 -1
- package/src/migration-classify.test.ts +150 -0
- package/src/migration-classify.ts +45 -0
- package/src/op/watch-pipeline.test.ts +8 -1
- package/src/plugin.ts +14 -0
- package/src/postgres/access/acl.ts +1 -1
- package/src/postgres/access/import.ts +1 -1
- package/src/postgres/apply/apply.ts +5 -0
- package/src/postgres/apply/statements.ts +151 -3
- package/src/postgres/database-kinds.test.ts +498 -17
- package/src/postgres/entities.ts +276 -5
- package/src/postgres/entity-types.ts +5 -0
- package/src/postgres/import/generator.ts +13 -1
- package/src/postgres/live/catalog-kinds.ts +275 -3
- package/src/postgres/live/describe-resources.ts +2 -0
- package/src/postgres/migrate/observe.ts +3 -1
- package/src/postgres/migrate/replication.ts +66 -0
- package/src/postgres/migrate/subscriber.e2e.test.ts +141 -0
- package/src/postgres/migrate/subscriber.test.ts +59 -0
- package/src/postgres/parser.ts +225 -6
- package/src/postgres/plan/deep.ts +15 -4
- package/src/postgres/plan/diff.ts +107 -6
- package/src/postgres/plan/normalize.ts +155 -0
- package/src/postgres/plan/rules.ts +25 -4
- package/src/postgres/plan/schema.ts +1 -1
- package/src/postgres/plan/statements.test.ts +78 -0
- package/src/postgres/plan/statements.ts +299 -0
- package/src/postgres/testing/roundtrip-schema.ts +12 -1
- package/src/postgres.ts +17 -0
- package/src/skills/chant-sql-postgres-migration.md +1 -0
- package/src/skills/chant-sql-postgres.md +5 -0
- package/src/sql-files.test.ts +33 -0
- package/src/validate.ts +5 -0
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Postgres statement classifier (#4407): a migration file's statements,
|
|
3
|
+
* each given the class and rule the schema-diff classifier (`./rules.ts`)
|
|
4
|
+
* gives the same change, with the lock the rule's restriction names. It reads
|
|
5
|
+
* text and contacts no server.
|
|
6
|
+
*
|
|
7
|
+
* `CREATE`, `GRANT`, `REVOKE`, `COMMENT ON` and `ALTER TABLE ... ROW LEVEL
|
|
8
|
+
* SECURITY` go through the declaration parser (`../parser.ts`). The parser
|
|
9
|
+
* has no `ALTER` grammar, so the other `ALTER` and `DROP` statements are read
|
|
10
|
+
* word by word from the same tokens.
|
|
11
|
+
*
|
|
12
|
+
* A statement alone cannot decide some changes. `ALTER COLUMN ... TYPE` is a
|
|
13
|
+
* catalog change or a table rewrite by the column's old type, which the file
|
|
14
|
+
* does not state: it is `undecided`, naming SQLPG206 and SQLPG207 (and
|
|
15
|
+
* SQLPG208 with a `USING` expression). `CREATE OR REPLACE VIEW` is SQLPG250
|
|
16
|
+
* or SQLPG251 by whether the columns stay. A statement no rule covers is
|
|
17
|
+
* `unclassified` with a note.
|
|
18
|
+
*/
|
|
19
|
+
import { isTrivia, tokenizeText } from "../tokens.js";
|
|
20
|
+
import { parseStatements } from "../parser.js";
|
|
21
|
+
import { classifiedOf, lockOf, splitTopLevel, sqlHead } from "../../core/statement-class.js";
|
|
22
|
+
import { PG_CHANGE_CLASSES, PG_CLASSIFIER_RULES } from "./rules.js";
|
|
23
|
+
const classified = (id, extra = {}) => {
|
|
24
|
+
const lock = lockOf(PG_CLASSIFIER_RULES[id].restriction);
|
|
25
|
+
return classifiedOf(PG_CLASSIFIER_RULES, PG_CHANGE_CLASSES.label, id, { ...(lock ? { lock } : {}), ...extra });
|
|
26
|
+
};
|
|
27
|
+
const rule = (id, extra) => ({ rules: [{ id, ...(extra ? { extra } : {}) }] });
|
|
28
|
+
const VOLATILE = /\b(?:clock_timestamp|random|gen_random_uuid|uuid_generate_v\d\w*|nextval|timeofday|txid_current|setseed)\s*\(/i;
|
|
29
|
+
/** The words from `i` that are one possibly qualified name, and the index after it. */
|
|
30
|
+
function nameAt(words, i) {
|
|
31
|
+
let name = words[i] ?? "";
|
|
32
|
+
let j = i + 1;
|
|
33
|
+
while (words[j] === "." && words[j + 1] !== undefined) {
|
|
34
|
+
name += `.${words[j + 1]}`;
|
|
35
|
+
j += 2;
|
|
36
|
+
}
|
|
37
|
+
return { name, next: j };
|
|
38
|
+
}
|
|
39
|
+
const bare = (name) => (name.split(".").pop() ?? name).replace(/^"|"$/g, "").toLowerCase();
|
|
40
|
+
const has = (u, ...seq) => u.some((_, i) => seq.every((w, k) => u[i + k] === w));
|
|
41
|
+
/** One `ALTER TABLE` action (the words between top-level commas). */
|
|
42
|
+
function tableAction(a) {
|
|
43
|
+
const u = a.map((w) => w.toUpperCase());
|
|
44
|
+
const first = u[0];
|
|
45
|
+
if (first === "ADD") {
|
|
46
|
+
let i = 1;
|
|
47
|
+
if (u[i] === "COLUMN")
|
|
48
|
+
i++;
|
|
49
|
+
if (u[i] === "CONSTRAINT" || ["PRIMARY", "UNIQUE", "CHECK", "FOREIGN", "EXCLUDE"].includes(u[i] ?? "")) {
|
|
50
|
+
let k = i;
|
|
51
|
+
if (u[k] === "CONSTRAINT")
|
|
52
|
+
k += 2;
|
|
53
|
+
const kind = u[k];
|
|
54
|
+
const notValid = has(u, "NOT", "VALID");
|
|
55
|
+
if (kind === "NOT" && u[k + 1] === "NULL")
|
|
56
|
+
return rule("SQLPG210");
|
|
57
|
+
if (notValid)
|
|
58
|
+
return rule("SQLPG217", { note: `${kind ?? "constraint"} added NOT VALID; VALIDATE CONSTRAINT is SQLPG220` });
|
|
59
|
+
if (kind === "PRIMARY" || kind === "UNIQUE")
|
|
60
|
+
return rule("SQLPG221", has(u, "USING", "INDEX") ? { note: "from an existing unique index, so no build under this lock" } : {});
|
|
61
|
+
if (kind === "CHECK")
|
|
62
|
+
return rule("SQLPG218");
|
|
63
|
+
if (kind === "FOREIGN")
|
|
64
|
+
return rule("SQLPG219");
|
|
65
|
+
if (kind === "EXCLUDE")
|
|
66
|
+
return rule("SQLPG222");
|
|
67
|
+
return { none: "an ADD CONSTRAINT of a kind no rule names" };
|
|
68
|
+
}
|
|
69
|
+
if (u[i] === "IF" && u[i + 1] === "NOT" && u[i + 2] === "EXISTS")
|
|
70
|
+
i += 3;
|
|
71
|
+
const hasDefault = u.includes("DEFAULT");
|
|
72
|
+
const defaultText = hasDefault ? a.slice(u.indexOf("DEFAULT") + 1).join(" ") : "";
|
|
73
|
+
const generated = has(u, "GENERATED");
|
|
74
|
+
const stored = u.includes("STORED") && generated;
|
|
75
|
+
const identity = u.includes("IDENTITY");
|
|
76
|
+
const notNull = has(u, "NOT", "NULL");
|
|
77
|
+
if (stored || identity)
|
|
78
|
+
return rule("SQLPG202", { note: stored ? "a STORED generated column" : "an identity column" });
|
|
79
|
+
if (VOLATILE.test(defaultText))
|
|
80
|
+
return rule("SQLPG202", { note: "a volatile default" });
|
|
81
|
+
if (notNull && !hasDefault && !generated)
|
|
82
|
+
return rule("SQLPG203");
|
|
83
|
+
return rule("SQLPG201");
|
|
84
|
+
}
|
|
85
|
+
if (first === "DROP") {
|
|
86
|
+
if (u[1] === "CONSTRAINT")
|
|
87
|
+
return rule("SQLPG223");
|
|
88
|
+
return rule("SQLPG204", { destructive: true });
|
|
89
|
+
}
|
|
90
|
+
if (first === "RENAME") {
|
|
91
|
+
if (u[1] === "COLUMN" || (u[1] !== "CONSTRAINT" && u[1] !== "TO"))
|
|
92
|
+
return rule("SQLPG205");
|
|
93
|
+
return rule("SQLPG228");
|
|
94
|
+
}
|
|
95
|
+
if (first === "ALTER") {
|
|
96
|
+
let i = 1;
|
|
97
|
+
if (u[i] === "COLUMN")
|
|
98
|
+
i++;
|
|
99
|
+
if (u[i] === "CONSTRAINT")
|
|
100
|
+
return { none: "ALTER CONSTRAINT (deferrability)" };
|
|
101
|
+
const rest = u.slice(i + 1);
|
|
102
|
+
const col = a[i] ?? "column";
|
|
103
|
+
if (rest[0] === "TYPE" || (rest[0] === "SET" && rest[1] === "DATA" && rest[2] === "TYPE")) {
|
|
104
|
+
const using = rest.includes("USING");
|
|
105
|
+
return {
|
|
106
|
+
undecided: using ? ["SQLPG206", "SQLPG207", "SQLPG208"] : ["SQLPG206", "SQLPG207"],
|
|
107
|
+
note: `the new type of ${col} is a catalog change or a table rewrite by its old type${using ? ", or a change across kinds with this USING expression," : ""}, which the file does not state`,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
if (rest[0] === "SET" && rest[1] === "DEFAULT")
|
|
111
|
+
return rule("SQLPG209");
|
|
112
|
+
if (rest[0] === "DROP" && rest[1] === "DEFAULT")
|
|
113
|
+
return rule("SQLPG209");
|
|
114
|
+
if (rest[0] === "SET" && rest[1] === "NOT" && rest[2] === "NULL")
|
|
115
|
+
return rule("SQLPG210");
|
|
116
|
+
if (rest[0] === "DROP" && rest[1] === "NOT" && rest[2] === "NULL")
|
|
117
|
+
return rule("SQLPG211");
|
|
118
|
+
if (rest[0] === "SET" && rest[1] === "EXPRESSION")
|
|
119
|
+
return rule("SQLPG212");
|
|
120
|
+
if ((rest[0] === "ADD" && rest[1] === "GENERATED") || (rest[0] === "SET" && (rest[1] === "GENERATED" || rest[1] === "INCREMENT" || rest[1] === "START" || rest[1] === "RESTART")) || rest[0] === "RESTART" || (rest[0] === "DROP" && rest[1] === "IDENTITY")) {
|
|
121
|
+
return rule("SQLPG213");
|
|
122
|
+
}
|
|
123
|
+
if (rest[0] === "SET" && (rest[1] === "STORAGE" || rest[1] === "COMPRESSION"))
|
|
124
|
+
return rule("SQLPG215");
|
|
125
|
+
return { none: `ALTER COLUMN ${rest.slice(0, 2).join(" ")}` };
|
|
126
|
+
}
|
|
127
|
+
if (first === "VALIDATE" && u[1] === "CONSTRAINT")
|
|
128
|
+
return rule("SQLPG220");
|
|
129
|
+
if (first === "SET" || first === "RESET") {
|
|
130
|
+
if (u[1] === "LOGGED" || u[1] === "UNLOGGED")
|
|
131
|
+
return rule("SQLPG225");
|
|
132
|
+
if (u[1] === "ACCESS" || u[1] === "TABLESPACE")
|
|
133
|
+
return rule("SQLPG226");
|
|
134
|
+
if (u[1] === "SCHEMA")
|
|
135
|
+
return rule("SQLPG228");
|
|
136
|
+
if (u[1] === "(" || first === "RESET")
|
|
137
|
+
return rule("SQLPG224");
|
|
138
|
+
return { none: `ALTER TABLE ${u.slice(0, 2).join(" ")}` };
|
|
139
|
+
}
|
|
140
|
+
if (first === "ATTACH" || first === "DETACH" || first === "INHERIT" || (first === "NO" && u[1] === "INHERIT") || first === "OF" || (first === "NOT" && u[1] === "OF"))
|
|
141
|
+
return rule("SQLPG227");
|
|
142
|
+
if ((first === "ENABLE" || first === "DISABLE" || first === "FORCE" || (first === "NO" && u[1] === "FORCE")) && has(u, "ROW", "LEVEL", "SECURITY"))
|
|
143
|
+
return rule("SQLPG293");
|
|
144
|
+
if ((first === "ENABLE" || first === "DISABLE") && (u[1] === "TRIGGER" || u[1] === "REPLICA" || u[1] === "ALWAYS"))
|
|
145
|
+
return rule("SQLPG284");
|
|
146
|
+
return { none: `ALTER TABLE ${u.slice(0, 2).join(" ")}` };
|
|
147
|
+
}
|
|
148
|
+
/** `ALTER <object> ...` other than `TABLE`, by its second word. */
|
|
149
|
+
function alterOther(u, a) {
|
|
150
|
+
const obj = u[1];
|
|
151
|
+
const rename = u.includes("RENAME");
|
|
152
|
+
if (obj === "INDEX")
|
|
153
|
+
return rename ? rule("SQLPG229") : rule("SQLPG243");
|
|
154
|
+
if (obj === "TYPE") {
|
|
155
|
+
if (has(u, "ADD", "VALUE"))
|
|
156
|
+
return rule("SQLPG260");
|
|
157
|
+
if (has(u, "RENAME", "TO"))
|
|
158
|
+
return rule("SQLPG228");
|
|
159
|
+
return { none: "ALTER TYPE other than ADD VALUE and RENAME TO" };
|
|
160
|
+
}
|
|
161
|
+
if (obj === "SEQUENCE")
|
|
162
|
+
return rename || has(u, "SET", "SCHEMA") ? rule("SQLPG228") : has(u, "OWNER", "TO") ? { none: "ALTER SEQUENCE OWNER TO" } : rule("SQLPG265");
|
|
163
|
+
if (obj === "VIEW")
|
|
164
|
+
return rename || has(u, "SET", "SCHEMA") ? rule("SQLPG228") : has(u, "OWNER", "TO") ? { none: "ALTER VIEW OWNER TO" } : rule("SQLPG253");
|
|
165
|
+
if (obj === "MATERIALIZED")
|
|
166
|
+
return rename || has(u, "SET", "SCHEMA") ? rule("SQLPG228") : { none: "ALTER MATERIALIZED VIEW other than RENAME" };
|
|
167
|
+
if (obj === "SCHEMA")
|
|
168
|
+
return rename ? rule("SQLPG228") : has(u, "OWNER", "TO") ? rule("SQLPG267") : { none: "ALTER SCHEMA" };
|
|
169
|
+
if (obj === "EXTENSION")
|
|
170
|
+
return has(u, "UPDATE") || has(u, "SET", "SCHEMA") ? rule("SQLPG266") : { none: "ALTER EXTENSION ADD or DROP member" };
|
|
171
|
+
if (obj === "FUNCTION" || obj === "PROCEDURE" || obj === "ROUTINE")
|
|
172
|
+
return rename || has(u, "SET", "SCHEMA") ? rule("SQLPG228") : { none: `ALTER ${obj} other than RENAME` };
|
|
173
|
+
if (obj === "TRIGGER")
|
|
174
|
+
return rule("SQLPG284");
|
|
175
|
+
if (obj === "POLICY")
|
|
176
|
+
return rename ? rule("SQLPG228") : rule("SQLPG291");
|
|
177
|
+
if (obj === "ROLE" || obj === "USER" || obj === "GROUP")
|
|
178
|
+
return rule("SQLPG294");
|
|
179
|
+
if (obj === "DOMAIN") {
|
|
180
|
+
if (rename || has(u, "SET", "SCHEMA"))
|
|
181
|
+
return rule("SQLPG228");
|
|
182
|
+
if (has(u, "ADD", "CONSTRAINT") || (u[3] === "ADD" && ["CHECK", "NOT"].includes(u[4] ?? "")))
|
|
183
|
+
return rule("SQLPG262");
|
|
184
|
+
if (has(u, "OWNER", "TO"))
|
|
185
|
+
return { none: "ALTER DOMAIN OWNER TO" };
|
|
186
|
+
return rule("SQLPG263");
|
|
187
|
+
}
|
|
188
|
+
if (obj === "SERVER" || obj === "PUBLICATION" || (obj === "FOREIGN" && u[2] === "DATA"))
|
|
189
|
+
return rename ? rule("SQLPG228") : rule("SQLPG303");
|
|
190
|
+
void a;
|
|
191
|
+
return { none: `ALTER ${obj ?? ""}`.trim() };
|
|
192
|
+
}
|
|
193
|
+
function dropStatement(u) {
|
|
194
|
+
const obj = u[1] === "MATERIALIZED" || u[1] === "FOREIGN" || u[1] === "EVENT" ? `${u[1]} ${u[2]}` : u[1];
|
|
195
|
+
if (obj === "INDEX")
|
|
196
|
+
return rule("SQLPG242", u[2] === "CONCURRENTLY" ? { note: "DROP INDEX CONCURRENTLY waits for running queries instead of blocking them" } : {});
|
|
197
|
+
if (obj === "TRIGGER")
|
|
198
|
+
return rule("SQLPG285", { destructive: false });
|
|
199
|
+
if (obj === "POLICY")
|
|
200
|
+
return rule("SQLPG292", { destructive: false });
|
|
201
|
+
return rule("SQLPG270", { destructive: true });
|
|
202
|
+
}
|
|
203
|
+
/** How a `CREATE` that the parser could not read starts: its kind by key words. */
|
|
204
|
+
function createByWords(u) {
|
|
205
|
+
let i = 1;
|
|
206
|
+
const orReplace = u[i] === "OR" && u[i + 1] === "REPLACE";
|
|
207
|
+
if (orReplace)
|
|
208
|
+
i += 2;
|
|
209
|
+
while (["GLOBAL", "LOCAL", "TEMPORARY", "TEMP", "UNLOGGED", "RECURSIVE", "UNIQUE", "CONSTRAINT"].includes(u[i] ?? "") && u[i + 1] !== "INDEX" && u[i] !== "UNIQUE")
|
|
210
|
+
i++;
|
|
211
|
+
if (u[i] === "UNIQUE")
|
|
212
|
+
i++;
|
|
213
|
+
if (u[i] === "INDEX") {
|
|
214
|
+
const concurrently = u[i + 1] === "CONCURRENTLY";
|
|
215
|
+
return concurrently ? rule("SQLPG240") : rule("SQLPG241");
|
|
216
|
+
}
|
|
217
|
+
if (orReplace && (u[i] === "FUNCTION" || u[i] === "PROCEDURE"))
|
|
218
|
+
return rule("SQLPG280");
|
|
219
|
+
if (orReplace && u[i] === "VIEW")
|
|
220
|
+
return { undecided: ["SQLPG250", "SQLPG251"], note: "whether the view keeps its columns depends on the view it replaces" };
|
|
221
|
+
if (orReplace && u[i] === "AGGREGATE")
|
|
222
|
+
return rule("SQLPG302");
|
|
223
|
+
if (u[i] === "TRIGGER")
|
|
224
|
+
return rule("SQLPG283");
|
|
225
|
+
if (u[i] === "POLICY")
|
|
226
|
+
return rule("SQLPG290");
|
|
227
|
+
return rule("SQLPG200");
|
|
228
|
+
}
|
|
229
|
+
/** A statement the parser read: its rule, given the tables this file created earlier. */
|
|
230
|
+
function fromNode(n, created) {
|
|
231
|
+
switch (n.statement) {
|
|
232
|
+
case "table":
|
|
233
|
+
created.add(bare(n.name.pieces.join(".")));
|
|
234
|
+
return rule("SQLPG200");
|
|
235
|
+
case "index":
|
|
236
|
+
if (n.concurrently)
|
|
237
|
+
return rule("SQLPG240");
|
|
238
|
+
if (created.has(bare(n.table.pieces.join("."))))
|
|
239
|
+
return rule("SQLPG200", { note: "an index on a table this file creates, which has no rows to block" });
|
|
240
|
+
return rule("SQLPG241");
|
|
241
|
+
case "view":
|
|
242
|
+
if (n.orReplace && !n.materialized)
|
|
243
|
+
return { undecided: ["SQLPG250", "SQLPG251"], note: "whether the view keeps its columns depends on the view it replaces" };
|
|
244
|
+
return rule("SQLPG200");
|
|
245
|
+
case "function":
|
|
246
|
+
case "procedure":
|
|
247
|
+
return n.orReplace ? rule("SQLPG280") : rule("SQLPG200");
|
|
248
|
+
case "aggregate":
|
|
249
|
+
return n.orReplace ? rule("SQLPG302") : rule("SQLPG200");
|
|
250
|
+
case "trigger":
|
|
251
|
+
return created.has(bare(n.table.pieces.join("."))) ? rule("SQLPG200", { note: "a trigger on a table this file creates" }) : rule("SQLPG283");
|
|
252
|
+
case "policy":
|
|
253
|
+
return created.has(bare(n.table.pieces.join("."))) ? rule("SQLPG200", { note: "a policy on a table this file creates" }) : rule("SQLPG290");
|
|
254
|
+
case "grant":
|
|
255
|
+
return n.defaults ? rule("SQLPG298") : n.revoke ? rule("SQLPG297") : rule("SQLPG296");
|
|
256
|
+
case "rowSecurity":
|
|
257
|
+
return rule("SQLPG293");
|
|
258
|
+
case "comment":
|
|
259
|
+
return rule("SQLPG216");
|
|
260
|
+
case "role":
|
|
261
|
+
return rule("SQLPG200");
|
|
262
|
+
default:
|
|
263
|
+
return rule("SQLPG200");
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const DATA_WORDS = new Set(["INSERT", "UPDATE", "DELETE", "SELECT", "WITH", "COPY", "CALL", "DO", "SET", "BEGIN", "START", "COMMIT", "END", "ROLLBACK", "SAVEPOINT", "RELEASE", "ANALYZE", "ANALYSE", "VACUUM", "REINDEX", "LOCK", "NOTIFY", "LISTEN", "RESET", "SHOW", "EXPLAIN", "VALUES", "MERGE", "REFRESH", "CLUSTER", "CHECKPOINT", "DISCARD", "PREPARE", "EXECUTE", "DEALLOCATE"]);
|
|
267
|
+
/** Classify one statement. `created` is the tables the file's earlier statements created. */
|
|
268
|
+
function read(sql, created) {
|
|
269
|
+
let tokens;
|
|
270
|
+
try {
|
|
271
|
+
tokens = tokenizeText(sql, 0);
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
return [{ none: "text the tokenizer could not read" }];
|
|
275
|
+
}
|
|
276
|
+
const words = tokens.filter((t) => !isTrivia(t) && t.text !== ";").map((t) => t.text);
|
|
277
|
+
const u = words.map((w) => w.toUpperCase());
|
|
278
|
+
const head = u[0];
|
|
279
|
+
if (head === undefined)
|
|
280
|
+
return [{ data: "an empty statement" }];
|
|
281
|
+
if (head === "CREATE" || head === "GRANT" || head === "REVOKE" || head === "COMMENT" || (head === "ALTER" && (u[1] === "DEFAULT" || (u[1] === "TABLE" && has(u, "ROW", "LEVEL", "SECURITY"))))) {
|
|
282
|
+
try {
|
|
283
|
+
const nodes = parseStatements(tokens);
|
|
284
|
+
return nodes.map((n) => fromNode(n, created));
|
|
285
|
+
}
|
|
286
|
+
catch {
|
|
287
|
+
if (head === "CREATE")
|
|
288
|
+
return [createByWords(u)];
|
|
289
|
+
if (head === "GRANT")
|
|
290
|
+
return [rule("SQLPG296")];
|
|
291
|
+
if (head === "REVOKE")
|
|
292
|
+
return [rule("SQLPG297")];
|
|
293
|
+
if (head === "COMMENT")
|
|
294
|
+
return [rule("SQLPG216")];
|
|
295
|
+
if (head === "ALTER" && u[1] === "DEFAULT")
|
|
296
|
+
return [rule("SQLPG298")];
|
|
297
|
+
return [rule("SQLPG293")];
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (head === "ALTER" && u[1] === "TABLE") {
|
|
301
|
+
let i = 2;
|
|
302
|
+
if (u[i] === "IF" && u[i + 1] === "EXISTS")
|
|
303
|
+
i += 2;
|
|
304
|
+
if (u[i] === "ONLY")
|
|
305
|
+
i++;
|
|
306
|
+
const { name, next } = nameAt(words, i);
|
|
307
|
+
if (u[next] === "*")
|
|
308
|
+
i = next + 1;
|
|
309
|
+
else
|
|
310
|
+
i = next;
|
|
311
|
+
const actions = splitTopLevel(words.slice(i));
|
|
312
|
+
if (actions.length === 0)
|
|
313
|
+
return [{ none: `ALTER TABLE ${name} with no action` }];
|
|
314
|
+
void name;
|
|
315
|
+
return actions.map(tableAction);
|
|
316
|
+
}
|
|
317
|
+
if (head === "ALTER")
|
|
318
|
+
return [alterOther(u, words)];
|
|
319
|
+
if (head === "DROP")
|
|
320
|
+
return [dropStatement(u)];
|
|
321
|
+
if (head === "TRUNCATE")
|
|
322
|
+
return [{ data: "TRUNCATE removes every row of the table" }];
|
|
323
|
+
if (DATA_WORDS.has(head))
|
|
324
|
+
return [{ data: `${head} reads or writes rows or the session, not the schema` }];
|
|
325
|
+
return [{ none: `${head} is not a statement the classifier reads` }];
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Classify a migration's up statements, in order. The statements are the
|
|
329
|
+
* file's own text, one per entry (a Flyway file after placeholder
|
|
330
|
+
* substitution).
|
|
331
|
+
*/
|
|
332
|
+
export function classifyPgStatements(statements) {
|
|
333
|
+
const created = new Set();
|
|
334
|
+
return statements.map((sql, k) => {
|
|
335
|
+
const readings = read(sql, created);
|
|
336
|
+
const out = { index: k + 1, sql: sqlHead(sql), outcome: "classified", changes: [] };
|
|
337
|
+
const none = [];
|
|
338
|
+
for (const r of readings) {
|
|
339
|
+
if ("rules" in r)
|
|
340
|
+
out.changes.push(...r.rules.map((x) => classified(x.id, x.extra)));
|
|
341
|
+
else if ("undecided" in r) {
|
|
342
|
+
out.candidates = r.undecided.map((id) => classified(id));
|
|
343
|
+
out.note = r.note;
|
|
344
|
+
}
|
|
345
|
+
else if ("none" in r)
|
|
346
|
+
none.push(r.none);
|
|
347
|
+
else
|
|
348
|
+
out.note = r.data;
|
|
349
|
+
}
|
|
350
|
+
if (out.candidates && out.changes.length === 0)
|
|
351
|
+
out.outcome = "undecided";
|
|
352
|
+
else if (out.candidates) {
|
|
353
|
+
// A statement with some decided clauses and one undecided: report undecided, and keep the decided ones.
|
|
354
|
+
out.outcome = "undecided";
|
|
355
|
+
}
|
|
356
|
+
else if (out.changes.length === 0 && none.length === 0)
|
|
357
|
+
out.outcome = "data";
|
|
358
|
+
else if (none.length > 0) {
|
|
359
|
+
out.outcome = out.changes.length > 0 ? "classified" : "unclassified";
|
|
360
|
+
out.note = [out.note, `no rule covers ${none.join("; ")}`].filter(Boolean).join("; ");
|
|
361
|
+
}
|
|
362
|
+
return out;
|
|
363
|
+
});
|
|
364
|
+
}
|
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
* domain over its type, a collation, composite and range types (and a
|
|
7
7
|
* multirange column), plain and ordered-set aggregates, a cast and an event
|
|
8
8
|
* trigger, an operator, extended statistics, a foreign data wrapper and server, and a
|
|
9
|
-
* publication (#3911), a
|
|
9
|
+
* publication (#3911), a foreign table, an operator class and family, a text
|
|
10
|
+
* search dictionary and configuration (#4406), a partitioned table and a partition, an ORM's
|
|
10
11
|
* revision table that import leaves out, and an object carrying chant's
|
|
11
12
|
* ownership trailer.
|
|
12
13
|
*/
|
|
13
|
-
export declare const ROUNDTRIP_SCHEMA = "\nCREATE SCHEMA app;\nCOMMENT ON SCHEMA app IS 'The shop';\nCREATE EXTENSION citext WITH SCHEMA app;\nCREATE TYPE app.order_status AS ENUM ('placed', 'paid', 'shipped');\nCREATE DOMAIN app.email AS app.citext CONSTRAINT email_shape CHECK (VALUE LIKE '%@%');\nCOMMENT ON CONSTRAINT email_shape ON DOMAIN app.email IS 'needs an @';\nCREATE SEQUENCE app.invoice_seq AS integer START WITH 1000 CACHE 10;\nCREATE TABLE app.users (\n id bigint GENERATED ALWAYS AS IDENTITY (START WITH 10) PRIMARY KEY,\n email app.email NOT NULL UNIQUE,\n plan text NOT NULL DEFAULT 'free' CHECK (plan IN ('free', 'pro')),\n created_at timestamptz NOT NULL DEFAULT now()\n) WITH (fillfactor = 90);\nCOMMENT ON TABLE app.users IS 'Accounts [chant managed-by=chant stack=shop env=e2e]';\nCOMMENT ON COLUMN app.users.email IS 'Login name';\nCREATE TABLE app.orders (\n id serial PRIMARY KEY,\n user_id bigint NOT NULL REFERENCES app.users (id) ON DELETE CASCADE,\n invoice_no integer NOT NULL DEFAULT nextval('app.invoice_seq'),\n status app.order_status NOT NULL DEFAULT 'placed',\n amount numeric(12, 2) NOT NULL CONSTRAINT amount_positive CHECK (amount >= 0),\n discount int DEFAULT -1,\n total numeric GENERATED ALWAYS AS (amount * 2) STORED,\n placed_at timestamp(3) without time zone\n);\nCREATE INDEX orders_user_idx ON app.orders (user_id, placed_at DESC) WHERE status <> 'shipped';\nCREATE UNIQUE INDEX orders_invoice_idx ON app.orders USING btree (invoice_no) INCLUDE (amount);\nCREATE TABLE app.measures (ts date NOT NULL, v double precision) PARTITION BY RANGE (ts);\nCREATE TABLE app.measures_2026 PARTITION OF app.measures FOR VALUES FROM ('2026-01-01') TO ('2027-01-01');\nCREATE VIEW app.order_totals AS\n SELECT u.id AS user_id, u.email, count(o.id) AS n, coalesce(sum(o.amount), 0) AS total\n FROM app.users u LEFT JOIN app.orders o ON o.user_id = u.id\n GROUP BY u.id, u.email;\nCREATE MATERIALIZED VIEW app.daily AS SELECT placed_at::date AS day, count(*) AS n FROM app.orders GROUP BY 1 WITH NO DATA;\nCREATE COLLATION app.ci (provider = icu, locale = 'und-u-ks-level2', deterministic = false);\nCOMMENT ON COLLATION app.ci IS 'Case-insensitive';\nCREATE TYPE app.pair AS (a integer, b text COLLATE \"C\");\nCOMMENT ON TYPE app.pair IS 'Two values';\nCREATE TYPE app.floatrange AS RANGE (SUBTYPE = float8, SUBTYPE_DIFF = float8mi);\nCREATE TABLE app.people (id integer PRIMARY KEY, nick text COLLATE app.ci, span app.floatrange, tags app.floatmultirange);\nCREATE FUNCTION app.add2(a integer, b integer) RETURNS integer LANGUAGE sql IMMUTABLE AS $$ SELECT a + b $$;\nCREATE AGGREGATE app.total(integer) (SFUNC = app.add2, STYPE = integer, INITCOND = '0', PARALLEL = SAFE);\nCOMMENT ON AGGREGATE app.total(integer) IS 'A sum';\nCREATE FUNCTION app.middle(v double precision[]) RETURNS double precision LANGUAGE sql IMMUTABLE AS $$ SELECT v[(array_length(v, 1) + 1) / 2] $$;\nCREATE AGGREGATE app.median_of(ORDER BY double precision) (SFUNC = pg_catalog.array_append, STYPE = double precision[], FINALFUNC = app.middle);\nCREATE FUNCTION app.pair_text(p app.pair) RETURNS text LANGUAGE sql IMMUTABLE AS $$ SELECT p.a || ':' || p.b $$;\nCREATE CAST (app.pair AS text) WITH FUNCTION app.pair_text(app.pair) AS ASSIGNMENT;\nCOMMENT ON CAST (app.pair AS text) IS 'a:b';\nCREATE FUNCTION app.audit() RETURNS event_trigger LANGUAGE plpgsql AS $$ BEGIN END $$;\nCREATE EVENT TRIGGER app_audit ON ddl_command_end WHEN TAG IN ('CREATE TABLE') EXECUTE FUNCTION app.audit();\nCREATE FUNCTION app.int_same(a integer, b integer) RETURNS boolean LANGUAGE sql IMMUTABLE AS $$ SELECT a = b $$;\nCREATE OPERATOR app.=== (FUNCTION = app.int_same, LEFTARG = integer, RIGHTARG = integer, COMMUTATOR = OPERATOR(app.===), RESTRICT = eqsel, JOIN = eqjoinsel, HASHES, MERGES);\nCOMMENT ON OPERATOR app.===(integer, integer) IS 'Same value';\nCREATE STATISTICS app.orders_stats (dependencies) ON user_id, status FROM app.orders;\nCOMMENT ON STATISTICS app.orders_stats IS 'Users and their order states';\nCREATE FOREIGN DATA WRAPPER app_fdw OPTIONS (debug 'true');\nCOMMENT ON FOREIGN DATA WRAPPER app_fdw IS 'Remote tables';\nCREATE SERVER app_replica TYPE 'pg' VERSION '16' FOREIGN DATA WRAPPER app_fdw OPTIONS (host 'db.internal', port '5432');\nCOMMENT ON SERVER app_replica IS 'The read replica';\nCREATE PUBLICATION app_pub FOR TABLE app.orders, app.users WITH (publish = 'insert, update');\nCOMMENT ON PUBLICATION app_pub IS 'Order changes';\nCREATE TABLE public._prisma_migrations (id varchar(36) PRIMARY KEY, checksum varchar(64) NOT NULL);\n";
|
|
14
|
+
export declare const ROUNDTRIP_SCHEMA = "\nCREATE SCHEMA app;\nCOMMENT ON SCHEMA app IS 'The shop';\nCREATE EXTENSION citext WITH SCHEMA app;\nCREATE TYPE app.order_status AS ENUM ('placed', 'paid', 'shipped');\nCREATE DOMAIN app.email AS app.citext CONSTRAINT email_shape CHECK (VALUE LIKE '%@%');\nCOMMENT ON CONSTRAINT email_shape ON DOMAIN app.email IS 'needs an @';\nCREATE SEQUENCE app.invoice_seq AS integer START WITH 1000 CACHE 10;\nCREATE TABLE app.users (\n id bigint GENERATED ALWAYS AS IDENTITY (START WITH 10) PRIMARY KEY,\n email app.email NOT NULL UNIQUE,\n plan text NOT NULL DEFAULT 'free' CHECK (plan IN ('free', 'pro')),\n created_at timestamptz NOT NULL DEFAULT now()\n) WITH (fillfactor = 90);\nCOMMENT ON TABLE app.users IS 'Accounts [chant managed-by=chant stack=shop env=e2e]';\nCOMMENT ON COLUMN app.users.email IS 'Login name';\nCREATE TABLE app.orders (\n id serial PRIMARY KEY,\n user_id bigint NOT NULL REFERENCES app.users (id) ON DELETE CASCADE,\n invoice_no integer NOT NULL DEFAULT nextval('app.invoice_seq'),\n status app.order_status NOT NULL DEFAULT 'placed',\n amount numeric(12, 2) NOT NULL CONSTRAINT amount_positive CHECK (amount >= 0),\n discount int DEFAULT -1,\n total numeric GENERATED ALWAYS AS (amount * 2) STORED,\n placed_at timestamp(3) without time zone\n);\nCREATE INDEX orders_user_idx ON app.orders (user_id, placed_at DESC) WHERE status <> 'shipped';\nCREATE UNIQUE INDEX orders_invoice_idx ON app.orders USING btree (invoice_no) INCLUDE (amount);\nCREATE TABLE app.measures (ts date NOT NULL, v double precision) PARTITION BY RANGE (ts);\nCREATE TABLE app.measures_2026 PARTITION OF app.measures FOR VALUES FROM ('2026-01-01') TO ('2027-01-01');\nCREATE VIEW app.order_totals AS\n SELECT u.id AS user_id, u.email, count(o.id) AS n, coalesce(sum(o.amount), 0) AS total\n FROM app.users u LEFT JOIN app.orders o ON o.user_id = u.id\n GROUP BY u.id, u.email;\nCREATE MATERIALIZED VIEW app.daily AS SELECT placed_at::date AS day, count(*) AS n FROM app.orders GROUP BY 1 WITH NO DATA;\nCREATE COLLATION app.ci (provider = icu, locale = 'und-u-ks-level2', deterministic = false);\nCOMMENT ON COLLATION app.ci IS 'Case-insensitive';\nCREATE TYPE app.pair AS (a integer, b text COLLATE \"C\");\nCOMMENT ON TYPE app.pair IS 'Two values';\nCREATE TYPE app.floatrange AS RANGE (SUBTYPE = float8, SUBTYPE_DIFF = float8mi);\nCREATE TABLE app.people (id integer PRIMARY KEY, nick text COLLATE app.ci, span app.floatrange, tags app.floatmultirange);\nCREATE FUNCTION app.add2(a integer, b integer) RETURNS integer LANGUAGE sql IMMUTABLE AS $$ SELECT a + b $$;\nCREATE AGGREGATE app.total(integer) (SFUNC = app.add2, STYPE = integer, INITCOND = '0', PARALLEL = SAFE);\nCOMMENT ON AGGREGATE app.total(integer) IS 'A sum';\nCREATE FUNCTION app.middle(v double precision[]) RETURNS double precision LANGUAGE sql IMMUTABLE AS $$ SELECT v[(array_length(v, 1) + 1) / 2] $$;\nCREATE AGGREGATE app.median_of(ORDER BY double precision) (SFUNC = pg_catalog.array_append, STYPE = double precision[], FINALFUNC = app.middle);\nCREATE FUNCTION app.pair_text(p app.pair) RETURNS text LANGUAGE sql IMMUTABLE AS $$ SELECT p.a || ':' || p.b $$;\nCREATE CAST (app.pair AS text) WITH FUNCTION app.pair_text(app.pair) AS ASSIGNMENT;\nCOMMENT ON CAST (app.pair AS text) IS 'a:b';\nCREATE FUNCTION app.audit() RETURNS event_trigger LANGUAGE plpgsql AS $$ BEGIN END $$;\nCREATE EVENT TRIGGER app_audit ON ddl_command_end WHEN TAG IN ('CREATE TABLE') EXECUTE FUNCTION app.audit();\nCREATE FUNCTION app.int_same(a integer, b integer) RETURNS boolean LANGUAGE sql IMMUTABLE AS $$ SELECT a = b $$;\nCREATE OPERATOR app.=== (FUNCTION = app.int_same, LEFTARG = integer, RIGHTARG = integer, COMMUTATOR = OPERATOR(app.===), RESTRICT = eqsel, JOIN = eqjoinsel, HASHES, MERGES);\nCOMMENT ON OPERATOR app.===(integer, integer) IS 'Same value';\nCREATE STATISTICS app.orders_stats (dependencies) ON user_id, status FROM app.orders;\nCOMMENT ON STATISTICS app.orders_stats IS 'Users and their order states';\nCREATE FOREIGN DATA WRAPPER app_fdw OPTIONS (debug 'true');\nCOMMENT ON FOREIGN DATA WRAPPER app_fdw IS 'Remote tables';\nCREATE SERVER app_replica TYPE 'pg' VERSION '16' FOREIGN DATA WRAPPER app_fdw OPTIONS (host 'db.internal', port '5432');\nCOMMENT ON SERVER app_replica IS 'The read replica';\nCREATE PUBLICATION app_pub FOR TABLE app.orders, app.users WITH (publish = 'insert, update');\nCOMMENT ON PUBLICATION app_pub IS 'Order changes';\nCREATE FOREIGN TABLE app.remote_orders (id integer OPTIONS (column_name 'order_id') NOT NULL, status text DEFAULT 'placed', CONSTRAINT status_known CHECK (status IS NOT NULL)) SERVER app_replica OPTIONS (table_name 'orders');\nCOMMENT ON FOREIGN TABLE app.remote_orders IS 'Orders on the replica';\nCREATE OPERATOR CLASS app.int_hash_ops FOR TYPE integer USING hash AS OPERATOR 1 =, FUNCTION 1 hashint4(integer);\nCOMMENT ON OPERATOR CLASS app.int_hash_ops USING hash IS 'Hash by value';\nCREATE OPERATOR FAMILY app.spare_ops USING btree;\nCREATE TEXT SEARCH DICTIONARY app.shop_stop (TEMPLATE = simple, StopWords = english);\nCREATE TEXT SEARCH CONFIGURATION app.shop (PARSER = pg_catalog.\"default\");\nALTER TEXT SEARCH CONFIGURATION app.shop ADD MAPPING FOR asciiword, word WITH app.shop_stop, english_stem;\nALTER TEXT SEARCH CONFIGURATION app.shop ADD MAPPING FOR int, uint WITH simple;\nCOMMENT ON TEXT SEARCH CONFIGURATION app.shop IS 'Shop search';\nCREATE TABLE public._prisma_migrations (id varchar(36) PRIMARY KEY, checksum varchar(64) NOT NULL);\n";
|
|
14
15
|
//# sourceMappingURL=roundtrip-schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"roundtrip-schema.d.ts","sourceRoot":"","sources":["../../../src/postgres/testing/roundtrip-schema.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"roundtrip-schema.d.ts","sourceRoot":"","sources":["../../../src/postgres/testing/roundtrip-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB,03KAyE5B,CAAC"}
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* domain over its type, a collation, composite and range types (and a
|
|
7
7
|
* multirange column), plain and ordered-set aggregates, a cast and an event
|
|
8
8
|
* trigger, an operator, extended statistics, a foreign data wrapper and server, and a
|
|
9
|
-
* publication (#3911), a
|
|
9
|
+
* publication (#3911), a foreign table, an operator class and family, a text
|
|
10
|
+
* search dictionary and configuration (#4406), a partitioned table and a partition, an ORM's
|
|
10
11
|
* revision table that import leaves out, and an object carrying chant's
|
|
11
12
|
* ownership trailer.
|
|
12
13
|
*/
|
|
@@ -72,5 +73,15 @@ CREATE SERVER app_replica TYPE 'pg' VERSION '16' FOREIGN DATA WRAPPER app_fdw OP
|
|
|
72
73
|
COMMENT ON SERVER app_replica IS 'The read replica';
|
|
73
74
|
CREATE PUBLICATION app_pub FOR TABLE app.orders, app.users WITH (publish = 'insert, update');
|
|
74
75
|
COMMENT ON PUBLICATION app_pub IS 'Order changes';
|
|
76
|
+
CREATE FOREIGN TABLE app.remote_orders (id integer OPTIONS (column_name 'order_id') NOT NULL, status text DEFAULT 'placed', CONSTRAINT status_known CHECK (status IS NOT NULL)) SERVER app_replica OPTIONS (table_name 'orders');
|
|
77
|
+
COMMENT ON FOREIGN TABLE app.remote_orders IS 'Orders on the replica';
|
|
78
|
+
CREATE OPERATOR CLASS app.int_hash_ops FOR TYPE integer USING hash AS OPERATOR 1 =, FUNCTION 1 hashint4(integer);
|
|
79
|
+
COMMENT ON OPERATOR CLASS app.int_hash_ops USING hash IS 'Hash by value';
|
|
80
|
+
CREATE OPERATOR FAMILY app.spare_ops USING btree;
|
|
81
|
+
CREATE TEXT SEARCH DICTIONARY app.shop_stop (TEMPLATE = simple, StopWords = english);
|
|
82
|
+
CREATE TEXT SEARCH CONFIGURATION app.shop (PARSER = pg_catalog."default");
|
|
83
|
+
ALTER TEXT SEARCH CONFIGURATION app.shop ADD MAPPING FOR asciiword, word WITH app.shop_stop, english_stem;
|
|
84
|
+
ALTER TEXT SEARCH CONFIGURATION app.shop ADD MAPPING FOR int, uint WITH simple;
|
|
85
|
+
COMMENT ON TEXT SEARCH CONFIGURATION app.shop IS 'Shop search';
|
|
75
86
|
CREATE TABLE public._prisma_migrations (id varchar(36) PRIMARY KEY, checksum varchar(64) NOT NULL);
|
|
76
87
|
`;
|
package/dist/postgres.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* the statements are Postgres's own DDL, parsed at build time into entities,
|
|
6
6
|
* and the names fold and quote as Postgres folds and quotes them.
|
|
7
7
|
*/
|
|
8
|
-
export { schema, table, index, view, sequence, type, domain, extension, func, procedure, aggregate, trigger, eventTrigger, operator, statistics, foreignDataWrapper, foreignServer, publication, collation, cast, policy, role, grant, literal, SqlLiteral, SqlTemplateError, PostgresObject, POSTGRES_ENTITY_TYPES, isPostgresObject, isColumnRef, quoteIdent, type PostgresEntityType, type PostgresSchema, type PostgresRelation, type PostgresTable, type PostgresView, type PostgresIndex, type PostgresSequence, type PostgresEnum, type PostgresCompositeType, type PostgresRangeType, type PostgresType, type PostgresDomain, type PostgresAggregate, type PostgresCollation, type PostgresCast, type PostgresEventTrigger, type PostgresOperator, type PostgresStatistics, type PostgresForeignDataWrapper, type PostgresForeignServer, type PostgresPublication, type PostgresExtension, type PostgresFunction, type PostgresProcedure, type PostgresTrigger, type PostgresPolicy, type PostgresRole, type PostgresGrant, type ColumnDef, type KeyDef, type CheckDef, type ForeignKeyDef, type ExclusionDef, type SchemaProps, type TableProps, type IndexProps, type ViewProps, type SequenceProps, type EnumProps, type CompositeTypeProps, type CompositeAttributeDef, type RangeTypeProps, type AggregateProps, type AggregateArgDef, type CollationProps, type CastProps, type EventTriggerProps, type OperatorProps, type StatisticsProps, type ForeignDataWrapperProps, type ForeignServerProps, type PublicationProps, type PublicationTableDef, type DomainProps, type ExtensionProps, type RoutineProps, type RoutineArgDef, type FunctionProps, type ProcedureProps, type TriggerProps, type PolicyProps, type RoleProps, type GrantProps, type DefaultPrivilegesProps, type PrivilegeDef, type LineageEdge, type SqlSchema, type RowOf, type Column, type ColumnTraits, type AnyColumn, type UncheckedColumn, type KeyColumn, type NotNullColumn, type Named, type Unnamed, } from "./postgres/entities.js";
|
|
8
|
+
export { schema, table, index, view, sequence, type, domain, extension, func, procedure, aggregate, trigger, eventTrigger, operator, operatorClass, operatorFamily, foreignTable, textSearchConfiguration, textSearchDictionary, statistics, foreignDataWrapper, foreignServer, publication, collation, cast, policy, role, grant, literal, SqlLiteral, SqlTemplateError, PostgresObject, POSTGRES_ENTITY_TYPES, isPostgresObject, isColumnRef, quoteIdent, type PostgresEntityType, type PostgresSchema, type PostgresRelation, type PostgresTable, type PostgresView, type PostgresIndex, type PostgresSequence, type PostgresEnum, type PostgresCompositeType, type PostgresRangeType, type PostgresType, type PostgresDomain, type PostgresAggregate, type PostgresCollation, type PostgresCast, type PostgresEventTrigger, type PostgresOperator, type PostgresOperatorClass, type PostgresOperatorFamily, type PostgresForeignTable, type PostgresTextSearchConfiguration, type PostgresTextSearchDictionary, type PostgresStatistics, type PostgresForeignDataWrapper, type PostgresForeignServer, type PostgresPublication, type PostgresExtension, type PostgresFunction, type PostgresProcedure, type PostgresTrigger, type PostgresPolicy, type PostgresRole, type PostgresGrant, type ColumnDef, type KeyDef, type CheckDef, type ForeignKeyDef, type ExclusionDef, type SchemaProps, type TableProps, type IndexProps, type ViewProps, type SequenceProps, type EnumProps, type CompositeTypeProps, type CompositeAttributeDef, type RangeTypeProps, type AggregateProps, type AggregateArgDef, type CollationProps, type CastProps, type EventTriggerProps, type OperatorProps, type OperatorClassProps, type OperatorClassItemDef, type OperatorFamilyProps, type ForeignTableProps, type TextSearchConfigurationProps, type TextSearchDictionaryProps, type TextSearchMappingDef, type StatisticsProps, type ForeignDataWrapperProps, type ForeignServerProps, type PublicationProps, type PublicationTableDef, type DomainProps, type ExtensionProps, type RoutineProps, type RoutineArgDef, type FunctionProps, type ProcedureProps, type TriggerProps, type PolicyProps, type RoleProps, type GrantProps, type DefaultPrivilegesProps, type PrivilegeDef, type LineageEdge, type SqlSchema, type RowOf, type Column, type ColumnTraits, type AnyColumn, type UncheckedColumn, type KeyColumn, type NotNullColumn, type Named, type Unnamed, } from "./postgres/entities.js";
|
|
9
9
|
export { POSTGRES_PROVIDERS, COMMON_REFUSED, providerData, isPostgresProvider, providerAllowsExtension, isProviderOwned, refusedStatement, normalizeStatement, type PostgresProvider, type ProviderData, type ProviderSource, type RefusedStatement, type LiveObjectRef, } from "./postgres/providers/index.js";
|
|
10
10
|
export { PostgresMigrationOp, type PostgresMigrationOpConfig, type PostgresMigrationOpResources, type PostgresMigrationArgs, } from "./postgres/migrate/op.js";
|
|
11
11
|
export { POSTGRES_RECEIPTS_TABLE } from "./postgres/migrate/receipts.js";
|
package/dist/postgres.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,MAAM,EACN,KAAK,EACL,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,SAAS,EACT,IAAI,EACJ,SAAS,EACT,SAAS,EACT,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,kBAAkB,EAClB,aAAa,EACb,WAAW,EACX,SAAS,EACT,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,KAAK,EACL,OAAO,EACP,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,0BAA0B,EAC/B,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,KAAK,EACV,KAAK,OAAO,GACb,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,uBAAuB,EACvB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,aAAa,GACnB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,mBAAmB,EACnB,KAAK,yBAAyB,EAC9B,KAAK,4BAA4B,EACjC,KAAK,qBAAqB,GAC3B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,cAAc,uBAAuB,CAAC;AAItC,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,GACtB,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"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"}
|
package/dist/postgres.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* the statements are Postgres's own DDL, parsed at build time into entities,
|
|
6
6
|
* and the names fold and quote as Postgres folds and quotes them.
|
|
7
7
|
*/
|
|
8
|
-
export { schema, table, index, view, sequence, type, domain, extension, func, procedure, aggregate, trigger, eventTrigger, operator, statistics, foreignDataWrapper, foreignServer, publication, collation, cast, policy, role, grant, literal, SqlLiteral, SqlTemplateError, PostgresObject, POSTGRES_ENTITY_TYPES, isPostgresObject, isColumnRef, quoteIdent, } from "./postgres/entities.js";
|
|
8
|
+
export { schema, table, index, view, sequence, type, domain, extension, func, procedure, aggregate, trigger, eventTrigger, operator, operatorClass, operatorFamily, foreignTable, textSearchConfiguration, textSearchDictionary, statistics, foreignDataWrapper, foreignServer, publication, collation, cast, policy, role, grant, literal, SqlLiteral, SqlTemplateError, PostgresObject, POSTGRES_ENTITY_TYPES, isPostgresObject, isColumnRef, quoteIdent, } from "./postgres/entities.js";
|
|
9
9
|
export { POSTGRES_PROVIDERS, COMMON_REFUSED, providerData, isPostgresProvider, providerAllowsExtension, isProviderOwned, refusedStatement, normalizeStatement, } from "./postgres/providers/index.js";
|
|
10
10
|
export { PostgresMigrationOp, } from "./postgres/migrate/op.js";
|
|
11
11
|
export { POSTGRES_RECEIPTS_TABLE } from "./postgres/migrate/receipts.js";
|
|
@@ -474,6 +474,8 @@ export type OpClassResolution = { ok: true } | { ok: false; miss: Miss; otherMet
|
|
|
474
474
|
/** An operator class for `method` at the target major. */
|
|
475
475
|
export function resolveOpClass(p: PgProject, method: string, opclass: { schema?: string; name: string }): OpClassResolution {
|
|
476
476
|
if (opclass.schema !== undefined && outsideProject(p, opclass.schema)) return { ok: true };
|
|
477
|
+
// A class the project declares (an `operatorClass` tag), for this method.
|
|
478
|
+
if (p.objects.some((o) => o.type === "Postgres::OperatorClass" && o.name === opclass.name && o.method === method && (opclass.schema === undefined || o.schema === opclass.schema))) return { ok: true };
|
|
477
479
|
const classes = OPERATOR_CLASSES as Readonly<Record<string, Readonly<Record<string, Presence>>>>;
|
|
478
480
|
if (presentAt(classes[method]?.[opclass.name], p.major)) return { ok: true };
|
|
479
481
|
const ext = extensionFor(p, (e) => e.opclasses?.[method]?.includes(opclass.name) ?? false);
|
|
@@ -17,12 +17,12 @@ export const POSTGRES_TEMPLATE_SOURCES: readonly TemplateSource<PostgresTag>[] =
|
|
|
17
17
|
{
|
|
18
18
|
dialect: "postgres",
|
|
19
19
|
modules: ["@intentius/chant-lexicon-sql/postgres"],
|
|
20
|
-
tags: ["schema", "table", "index", "view", "sequence", "type", "domain", "extension", "func", "procedure", "aggregate", "trigger", "eventTrigger", "operator", "statistics", "foreignDataWrapper", "foreignServer", "publication", "collation", "cast", "policy", "role", "grant"],
|
|
20
|
+
tags: ["schema", "table", "index", "view", "sequence", "type", "domain", "extension", "func", "procedure", "aggregate", "trigger", "eventTrigger", "operator", "operatorClass", "operatorFamily", "foreignTable", "textSearchConfiguration", "textSearchDictionary", "statistics", "foreignDataWrapper", "foreignServer", "publication", "collation", "cast", "policy", "role", "grant"],
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
23
|
dialect: "postgres",
|
|
24
24
|
modules: ["@intentius/chant-lexicon-sql"],
|
|
25
|
-
tags: ["schema", "index", "sequence", "type", "domain", "extension", "func", "procedure", "aggregate", "trigger", "eventTrigger", "operator", "statistics", "foreignDataWrapper", "foreignServer", "publication", "collation", "cast", "policy", "role", "grant"],
|
|
25
|
+
tags: ["schema", "index", "sequence", "type", "domain", "extension", "func", "procedure", "aggregate", "trigger", "eventTrigger", "operator", "operatorClass", "operatorFamily", "foreignTable", "textSearchConfiguration", "textSearchDictionary", "statistics", "foreignDataWrapper", "foreignServer", "publication", "collation", "cast", "policy", "role", "grant"],
|
|
26
26
|
},
|
|
27
27
|
];
|
|
28
28
|
|
package/dist/validate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,EAAgD,KAAK,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAMtH,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,EAAgD,KAAK,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAMtH,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AA4FvF,wBAAsB,QAAQ,CAAC,IAAI,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAoEpF"}
|
package/dist/validate.js
CHANGED
|
@@ -44,6 +44,11 @@ const REQUIRED_ENTITIES = [
|
|
|
44
44
|
"PostgresCast",
|
|
45
45
|
"PostgresEventTrigger",
|
|
46
46
|
"PostgresOperator",
|
|
47
|
+
"PostgresOperatorClass",
|
|
48
|
+
"PostgresOperatorFamily",
|
|
49
|
+
"PostgresForeignTable",
|
|
50
|
+
"PostgresTextSearchConfiguration",
|
|
51
|
+
"PostgresTextSearchDictionary",
|
|
47
52
|
"PostgresStatistics",
|
|
48
53
|
"PostgresForeignDataWrapper",
|
|
49
54
|
"PostgresForeignServer",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intentius/chant-lexicon-sql",
|
|
3
|
-
"version": "0.124.
|
|
3
|
+
"version": "0.124.50",
|
|
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",
|
|
@@ -72,6 +72,6 @@
|
|
|
72
72
|
"typescript": "^5.9.3"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
|
-
"@intentius/chant": "^0.124.
|
|
75
|
+
"@intentius/chant": "^0.124.50"
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { classifyClickHouseStatements } from "./statements";
|
|
3
|
+
|
|
4
|
+
const one = (sql: string) => classifyClickHouseStatements([sql])[0]!;
|
|
5
|
+
const rules = (sql: string) => one(sql).changes.map((c) => c.rule);
|
|
6
|
+
|
|
7
|
+
describe("ClickHouse statements", () => {
|
|
8
|
+
test("a sort-key change is SQLCH220, a rebuild", () => {
|
|
9
|
+
const v = one("ALTER TABLE events MODIFY ORDER BY (user_id, ts)");
|
|
10
|
+
expect(v.outcome).toBe("classified");
|
|
11
|
+
expect(v.changes).toMatchObject([{ rule: "SQLCH220", class: "rebuild", label: "REBUILD" }]);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("appending the column the same ALTER adds is undecided between SQLCH216 and SQLCH220", () => {
|
|
15
|
+
const v = one("ALTER TABLE events ADD COLUMN region String, MODIFY ORDER BY (user_id, region)");
|
|
16
|
+
expect(v.outcome).toBe("undecided");
|
|
17
|
+
expect(v.candidates!.map((c) => c.rule)).toEqual(["SQLCH216", "SQLCH220"]);
|
|
18
|
+
expect(v.changes.map((c) => c.rule)).toEqual(["SQLCH201"]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("a table created in the same file decides the key questions", () => {
|
|
22
|
+
const create = "CREATE TABLE events (user_id UInt64, ts DateTime, region String) ENGINE = MergeTree ORDER BY (user_id, ts)";
|
|
23
|
+
const [, appended] = classifyClickHouseStatements([create, "ALTER TABLE events ADD COLUMN extra String, MODIFY ORDER BY (user_id, ts, extra)"]);
|
|
24
|
+
expect(appended!.outcome).toBe("classified");
|
|
25
|
+
expect(appended!.changes.map((c) => c.rule)).toEqual(["SQLCH201", "SQLCH216"]);
|
|
26
|
+
expect(classifyClickHouseStatements([create, "ALTER TABLE events MODIFY COLUMN user_id UInt32"])[1]!.changes[0]!.rule).toBe("SQLCH211");
|
|
27
|
+
expect(classifyClickHouseStatements([create, "ALTER TABLE events MODIFY COLUMN region LowCardinality(String)"])[1]!.changes[0]!.rule).toBe("SQLCH210");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("a column type change on a table the file does not create is undecided", () => {
|
|
31
|
+
const v = one("ALTER TABLE events MODIFY COLUMN user_id UInt32");
|
|
32
|
+
expect(v.outcome).toBe("undecided");
|
|
33
|
+
expect(v.candidates!.map((c) => c.rule)).toEqual(["SQLCH210", "SQLCH211"]);
|
|
34
|
+
expect(one("ALTER TABLE events DROP COLUMN a").candidates!.map((c) => c.rule)).toEqual(["SQLCH202", "SQLCH213"]);
|
|
35
|
+
expect(one("ALTER TABLE events RENAME COLUMN a TO b").candidates!.map((c) => c.rule)).toEqual(["SQLCH212", "SQLCH213"]);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("metadata and rewrite changes", () => {
|
|
39
|
+
expect(rules("ALTER TABLE events ADD COLUMN IF NOT EXISTS a String DEFAULT ''")).toEqual(["SQLCH201"]);
|
|
40
|
+
expect(rules("ALTER TABLE events ON CLUSTER c MODIFY COLUMN a DEFAULT 'x'")).toEqual(["SQLCH207"]);
|
|
41
|
+
expect(rules("ALTER TABLE events MODIFY TTL ts + INTERVAL 30 DAY")).toEqual(["SQLCH205"]);
|
|
42
|
+
expect(rules("ALTER TABLE events ADD INDEX i a TYPE minmax GRANULARITY 1")).toEqual(["SQLCH204"]);
|
|
43
|
+
expect(rules("ALTER TABLE events MODIFY SETTING ttl_only_drop_parts = 1")).toEqual(["SQLCH206"]);
|
|
44
|
+
expect(rules("ALTER TABLE events MODIFY COMMENT 'x'")).toEqual(["SQLCH203"]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("create, drop, rename", () => {
|
|
48
|
+
expect(rules("CREATE TABLE t (a UInt8) ENGINE = MergeTree ORDER BY a")).toEqual(["SQLCH200"]);
|
|
49
|
+
expect(rules("CREATE MATERIALIZED VIEW mv TO t AS SELECT a FROM s")).toEqual(["SQLCH200"]);
|
|
50
|
+
expect(rules("CREATE USER u IDENTIFIED WITH no_password")).toEqual(["SQLCH200"]);
|
|
51
|
+
expect(one("DROP TABLE t").changes[0]).toMatchObject({ rule: "SQLCH250", destructive: true });
|
|
52
|
+
expect(rules("RENAME TABLE a TO b")).toEqual(["SQLCH230"]);
|
|
53
|
+
expect(rules("GRANT SELECT ON db.* TO r")).toEqual(["SQLCH273"]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("mutations are data; partition operations have no rule", () => {
|
|
57
|
+
expect(one("ALTER TABLE t UPDATE a = 1 WHERE b = 2").outcome).toBe("data");
|
|
58
|
+
expect(one("ALTER TABLE t DROP PARTITION 2024").outcome).toBe("unclassified");
|
|
59
|
+
expect(one("INSERT INTO t VALUES (1)").outcome).toBe("data");
|
|
60
|
+
});
|
|
61
|
+
});
|