@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.
Files changed (138) hide show
  1. package/dist/clickhouse/plan/statements.d.ts +29 -0
  2. package/dist/clickhouse/plan/statements.d.ts.map +1 -0
  3. package/dist/clickhouse/plan/statements.js +334 -0
  4. package/dist/codegen/classifier-page.d.ts.map +1 -1
  5. package/dist/codegen/classifier-page.js +23 -0
  6. package/dist/codegen/postgres-classifier-page.js +2 -2
  7. package/dist/codegen/registry.d.ts.map +1 -1
  8. package/dist/codegen/registry.js +5 -0
  9. package/dist/core/statement-class.d.ts +55 -0
  10. package/dist/core/statement-class.d.ts.map +1 -0
  11. package/dist/core/statement-class.js +43 -0
  12. package/dist/coverage/postgres.json +6 -6
  13. package/dist/drizzle.d.ts.map +1 -1
  14. package/dist/drizzle.js +5 -0
  15. package/dist/files/postgres.d.ts.map +1 -1
  16. package/dist/files/postgres.js +23 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +1 -1
  20. package/dist/integrity.json +5 -5
  21. package/dist/lint/post-synth/postgres-names.d.ts.map +1 -1
  22. package/dist/lint/post-synth/postgres-names.js +3 -0
  23. package/dist/lint/rules/postgres-templates.js +2 -2
  24. package/dist/lsp/postgres-template.d.ts.map +1 -1
  25. package/dist/lsp/postgres-template.js +10 -0
  26. package/dist/manifest.json +1 -1
  27. package/dist/mcp/postgres.js +1 -1
  28. package/dist/meta.json +25 -0
  29. package/dist/migration-classify.d.ts +23 -0
  30. package/dist/migration-classify.d.ts.map +1 -0
  31. package/dist/migration-classify.js +44 -0
  32. package/dist/okf/index.md +5 -0
  33. package/dist/okf/types/PostgresForeignTable.md +9 -0
  34. package/dist/okf/types/PostgresOperatorClass.md +9 -0
  35. package/dist/okf/types/PostgresOperatorFamily.md +9 -0
  36. package/dist/okf/types/PostgresTextSearchConfiguration.md +9 -0
  37. package/dist/okf/types/PostgresTextSearchDictionary.md +9 -0
  38. package/dist/plugin.d.ts.map +1 -1
  39. package/dist/plugin.js +13 -0
  40. package/dist/postgres/access/acl.js +1 -1
  41. package/dist/postgres/access/import.js +1 -1
  42. package/dist/postgres/apply/apply.js +5 -0
  43. package/dist/postgres/apply/statements.d.ts.map +1 -1
  44. package/dist/postgres/apply/statements.js +156 -2
  45. package/dist/postgres/entities.d.ts +120 -2
  46. package/dist/postgres/entities.d.ts.map +1 -1
  47. package/dist/postgres/entities.js +180 -5
  48. package/dist/postgres/entity-types.d.ts +5 -0
  49. package/dist/postgres/entity-types.d.ts.map +1 -1
  50. package/dist/postgres/entity-types.js +5 -0
  51. package/dist/postgres/import/generator.d.ts.map +1 -1
  52. package/dist/postgres/import/generator.js +16 -1
  53. package/dist/postgres/live/catalog-kinds.d.ts +6 -0
  54. package/dist/postgres/live/catalog-kinds.d.ts.map +1 -1
  55. package/dist/postgres/live/catalog-kinds.js +251 -3
  56. package/dist/postgres/live/describe-resources.d.ts.map +1 -1
  57. package/dist/postgres/live/describe-resources.js +2 -0
  58. package/dist/postgres/migrate/observe.d.ts.map +1 -1
  59. package/dist/postgres/migrate/observe.js +4 -1
  60. package/dist/postgres/migrate/replication.d.ts +42 -0
  61. package/dist/postgres/migrate/replication.d.ts.map +1 -1
  62. package/dist/postgres/migrate/replication.js +53 -0
  63. package/dist/postgres/parser.d.ts +73 -1
  64. package/dist/postgres/parser.d.ts.map +1 -1
  65. package/dist/postgres/parser.js +181 -7
  66. package/dist/postgres/plan/deep.d.ts.map +1 -1
  67. package/dist/postgres/plan/deep.js +15 -4
  68. package/dist/postgres/plan/diff.d.ts.map +1 -1
  69. package/dist/postgres/plan/diff.js +120 -5
  70. package/dist/postgres/plan/normalize.d.ts +12 -1
  71. package/dist/postgres/plan/normalize.d.ts.map +1 -1
  72. package/dist/postgres/plan/normalize.js +151 -0
  73. package/dist/postgres/plan/rules.d.ts +3 -0
  74. package/dist/postgres/plan/rules.d.ts.map +1 -1
  75. package/dist/postgres/plan/rules.js +5 -2
  76. package/dist/postgres/plan/schema.js +1 -1
  77. package/dist/postgres/plan/statements.d.ts +26 -0
  78. package/dist/postgres/plan/statements.d.ts.map +1 -0
  79. package/dist/postgres/plan/statements.js +364 -0
  80. package/dist/postgres/testing/roundtrip-schema.d.ts +3 -2
  81. package/dist/postgres/testing/roundtrip-schema.d.ts.map +1 -1
  82. package/dist/postgres/testing/roundtrip-schema.js +12 -1
  83. package/dist/postgres.d.ts +1 -1
  84. package/dist/postgres.d.ts.map +1 -1
  85. package/dist/postgres.js +1 -1
  86. package/dist/rules/postgres-names.ts +2 -0
  87. package/dist/rules/postgres-templates.ts +2 -2
  88. package/dist/validate.d.ts.map +1 -1
  89. package/dist/validate.js +5 -0
  90. package/package.json +2 -2
  91. package/src/clickhouse/plan/statements.test.ts +61 -0
  92. package/src/clickhouse/plan/statements.ts +306 -0
  93. package/src/codegen/classifier-page.ts +23 -0
  94. package/src/codegen/postgres-classifier-page.ts +2 -2
  95. package/src/codegen/registry.ts +5 -0
  96. package/src/core/statement-class.ts +88 -0
  97. package/src/coverage/postgres.json +6 -6
  98. package/src/drizzle.ts +5 -0
  99. package/src/files/postgres.ts +22 -1
  100. package/src/generated/lexicon-sql.json +25 -0
  101. package/src/index.ts +1 -1
  102. package/src/lint/post-synth/postgres-checks.test.ts +8 -1
  103. package/src/lint/post-synth/postgres-names.ts +2 -0
  104. package/src/lint/rules/postgres-templates.ts +2 -2
  105. package/src/lsp/postgres-template.ts +9 -0
  106. package/src/mcp/postgres.ts +1 -1
  107. package/src/migration-classify.test.ts +150 -0
  108. package/src/migration-classify.ts +45 -0
  109. package/src/op/watch-pipeline.test.ts +8 -1
  110. package/src/plugin.ts +14 -0
  111. package/src/postgres/access/acl.ts +1 -1
  112. package/src/postgres/access/import.ts +1 -1
  113. package/src/postgres/apply/apply.ts +5 -0
  114. package/src/postgres/apply/statements.ts +151 -3
  115. package/src/postgres/database-kinds.test.ts +498 -17
  116. package/src/postgres/entities.ts +276 -5
  117. package/src/postgres/entity-types.ts +5 -0
  118. package/src/postgres/import/generator.ts +13 -1
  119. package/src/postgres/live/catalog-kinds.ts +275 -3
  120. package/src/postgres/live/describe-resources.ts +2 -0
  121. package/src/postgres/migrate/observe.ts +3 -1
  122. package/src/postgres/migrate/replication.ts +66 -0
  123. package/src/postgres/migrate/subscriber.e2e.test.ts +141 -0
  124. package/src/postgres/migrate/subscriber.test.ts +59 -0
  125. package/src/postgres/parser.ts +225 -6
  126. package/src/postgres/plan/deep.ts +15 -4
  127. package/src/postgres/plan/diff.ts +107 -6
  128. package/src/postgres/plan/normalize.ts +155 -0
  129. package/src/postgres/plan/rules.ts +25 -4
  130. package/src/postgres/plan/schema.ts +1 -1
  131. package/src/postgres/plan/statements.test.ts +78 -0
  132. package/src/postgres/plan/statements.ts +299 -0
  133. package/src/postgres/testing/roundtrip-schema.ts +12 -1
  134. package/src/postgres.ts +17 -0
  135. package/src/skills/chant-sql-postgres-migration.md +1 -0
  136. package/src/skills/chant-sql-postgres.md +5 -0
  137. package/src/sql-files.test.ts +33 -0
  138. package/src/validate.ts +5 -0
@@ -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 partitioned table and a partition, an ORM's
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/src/postgres.ts CHANGED
@@ -21,6 +21,11 @@ export {
21
21
  trigger,
22
22
  eventTrigger,
23
23
  operator,
24
+ operatorClass,
25
+ operatorFamily,
26
+ foreignTable,
27
+ textSearchConfiguration,
28
+ textSearchDictionary,
24
29
  statistics,
25
30
  foreignDataWrapper,
26
31
  foreignServer,
@@ -55,6 +60,11 @@ export {
55
60
  type PostgresCast,
56
61
  type PostgresEventTrigger,
57
62
  type PostgresOperator,
63
+ type PostgresOperatorClass,
64
+ type PostgresOperatorFamily,
65
+ type PostgresForeignTable,
66
+ type PostgresTextSearchConfiguration,
67
+ type PostgresTextSearchDictionary,
58
68
  type PostgresStatistics,
59
69
  type PostgresForeignDataWrapper,
60
70
  type PostgresForeignServer,
@@ -86,6 +96,13 @@ export {
86
96
  type CastProps,
87
97
  type EventTriggerProps,
88
98
  type OperatorProps,
99
+ type OperatorClassProps,
100
+ type OperatorClassItemDef,
101
+ type OperatorFamilyProps,
102
+ type ForeignTableProps,
103
+ type TextSearchConfigurationProps,
104
+ type TextSearchDictionaryProps,
105
+ type TextSearchMappingDef,
89
106
  type StatisticsProps,
90
107
  type ForeignDataWrapperProps,
91
108
  type ForeignServerProps,
@@ -121,6 +121,7 @@ The Plan phase refuses, naming each object and what to do, a table or column wit
121
121
  - a rename combined with a type change, unless the Op gives `reverse` (the old column's value from the new one); with a default, a serial or an identity as well, run the Op twice, the rename first;
122
122
  - a rename of a column with a default, an identity or a serial sequence, unless the Op gives `defaultAtContract: true` (the default lands on the new column at the contract; an explicit NULL into the new name gets the default until then);
123
123
  - a column a logical replication publication sends; a column list that leaves it out does not stop the Op (chant #3332);
124
+ - a table that is the target of a logical replication subscription, named in the refusal (chant #4405);
124
125
  - a column that needs no migration, where the message says to use the applier.
125
126
 
126
127
  ## Checking it is done
@@ -43,6 +43,11 @@ The export name (`users`) is the object's identity in chant. The name in the SQL
43
43
  | `trigger` | `CREATE TRIGGER` | `Postgres::Trigger` |
44
44
  | `eventTrigger` | `CREATE EVENT TRIGGER` | `Postgres::EventTrigger` |
45
45
  | `operator` | `CREATE OPERATOR` | `Postgres::Operator` |
46
+ | `operatorClass` | `CREATE OPERATOR CLASS` | `Postgres::OperatorClass` |
47
+ | `operatorFamily` | `CREATE OPERATOR FAMILY` | `Postgres::OperatorFamily` |
48
+ | `foreignTable` | `CREATE FOREIGN TABLE` | `Postgres::ForeignTable` |
49
+ | `textSearchConfiguration` | `CREATE TEXT SEARCH CONFIGURATION`, then `ALTER TEXT SEARCH CONFIGURATION ... ADD MAPPING` | `Postgres::TextSearchConfiguration` |
50
+ | `textSearchDictionary` | `CREATE TEXT SEARCH DICTIONARY` | `Postgres::TextSearchDictionary` |
46
51
  | `statistics` | `CREATE STATISTICS` | `Postgres::Statistics` |
47
52
  | `foreignDataWrapper` | `CREATE FOREIGN DATA WRAPPER` | `Postgres::ForeignDataWrapper` |
48
53
  | `foreignServer` | `CREATE SERVER` | `Postgres::ForeignServer` |
@@ -42,6 +42,39 @@ describe("reading a file of Postgres DDL", () => {
42
42
  );
43
43
  });
44
44
 
45
+ test("a foreign table, an operator class and a text search configuration with its mappings and comments are each one object (#4406)", () => {
46
+ const ddl = [
47
+ "CREATE FOREIGN TABLE app.remote_orders (id int NOT NULL) SERVER replica OPTIONS (table_name 'orders');",
48
+ "COMMENT ON FOREIGN TABLE app.remote_orders IS 'Orders';",
49
+ "CREATE OPERATOR CLASS app.int_hash_ops FOR TYPE int USING hash AS OPERATOR 1 =, FUNCTION 1 hashint4(int);",
50
+ "CREATE OPERATOR FAMILY app.int_hash_ops USING btree;",
51
+ "COMMENT ON OPERATOR CLASS app.int_hash_ops USING hash IS 'Hash';",
52
+ "CREATE TEXT SEARCH DICTIONARY app.shop_stop (TEMPLATE = simple, StopWords = english);",
53
+ "CREATE TEXT SEARCH CONFIGURATION app.shop (PARSER = pg_catalog.default);",
54
+ "CREATE TEXT SEARCH CONFIGURATION app.shop2 (PARSER = pg_catalog.default);",
55
+ "ALTER TEXT SEARCH CONFIGURATION app.shop ADD MAPPING FOR word WITH app.shop_stop;",
56
+ "COMMENT ON TEXT SEARCH CONFIGURATION app.shop2 IS 'Second';",
57
+ ].join("\n");
58
+ const objects = readSqlFile("postgres", ddl, { origin: "schema.sql" });
59
+ expect(objects.map((o) => [o.export, o.type, o.name])).toEqual([
60
+ ["remoteOrders", "Postgres::ForeignTable", "app.remote_orders"],
61
+ ["appIntHashOps", "Postgres::OperatorClass", "app.int_hash_ops"],
62
+ ["appIntHashOps2", "Postgres::OperatorFamily", "app.int_hash_ops"],
63
+ ["shopStop", "Postgres::TextSearchDictionary", "app.shop_stop"],
64
+ ["shop", "Postgres::TextSearchConfiguration", "app.shop"],
65
+ ["shop2", "Postgres::TextSearchConfiguration", "app.shop2"],
66
+ ]);
67
+ expect(objects[0]!.ddl).toContain("COMMENT ON FOREIGN TABLE app.remote_orders IS 'Orders'");
68
+ // A class and a family of one name and two methods are two objects, and each takes only its own comment.
69
+ expect(objects[1]!.ddl).toContain("COMMENT ON OPERATOR CLASS app.int_hash_ops USING hash IS 'Hash'");
70
+ expect(objects[2]!.ddl).not.toContain("COMMENT");
71
+ expect(objects[4]!.ddl).toContain("ADD MAPPING FOR word WITH app.shop_stop");
72
+ expect(objects[5]!.ddl).toContain("COMMENT ON TEXT SEARCH CONFIGURATION app.shop2 IS 'Second'");
73
+ expect(objects[5]!.ddl).not.toContain("ADD MAPPING");
74
+ // A mapping for a configuration the file does not create is named.
75
+ expect(() => readSqlFile("postgres", "ALTER TEXT SEARCH CONFIGURATION app.x ADD MAPPING FOR word WITH simple;", { origin: "x.sql" })).toThrow(/ALTER TEXT SEARCH CONFIGURATION \.\.\. ADD MAPPING for an object the file does not create/);
76
+ });
77
+
45
78
  test("a statement that declares nothing or does not parse is an error naming it, and every one is named", () => {
46
79
  const read = () => readSqlFile("postgres", "CREATE TABLE a (id int);\nINSERT INTO a VALUES (1);\nCREATE TABLE b (id int,);\nCOMMENT ON TABLE c IS 'x';", { origin: "db/schema.sql" });
47
80
  expect(read).toThrow(SqlFileError);
package/src/validate.ts CHANGED
@@ -48,6 +48,11 @@ const REQUIRED_ENTITIES = [
48
48
  "PostgresCast",
49
49
  "PostgresEventTrigger",
50
50
  "PostgresOperator",
51
+ "PostgresOperatorClass",
52
+ "PostgresOperatorFamily",
53
+ "PostgresForeignTable",
54
+ "PostgresTextSearchConfiguration",
55
+ "PostgresTextSearchDictionary",
51
56
  "PostgresStatistics",
52
57
  "PostgresForeignDataWrapper",
53
58
  "PostgresForeignServer",