@intentius/chant-lexicon-sql 0.124.46 → 0.124.49
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/change-set.d.ts +1 -1
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +2 -1
- package/dist/clickhouse/apply/statements.d.ts +9 -0
- package/dist/clickhouse/apply/statements.d.ts.map +1 -1
- package/dist/clickhouse/apply/statements.js +24 -0
- package/dist/clickhouse/import/live-export.d.ts +7 -3
- package/dist/clickhouse/import/live-export.d.ts.map +1 -1
- package/dist/clickhouse/import/live-export.js +21 -5
- package/dist/clickhouse/live/named-collections.d.ts +27 -0
- package/dist/clickhouse/live/named-collections.d.ts.map +1 -0
- package/dist/clickhouse/live/named-collections.js +53 -0
- package/dist/clickhouse/live/undeclarable.d.ts +15 -3
- package/dist/clickhouse/live/undeclarable.d.ts.map +1 -1
- package/dist/clickhouse/live/undeclarable.js +18 -4
- package/dist/clickhouse/named-collections.d.ts +83 -0
- package/dist/clickhouse/named-collections.d.ts.map +1 -0
- package/dist/clickhouse/named-collections.js +203 -0
- package/dist/clickhouse/parser.d.ts.map +1 -1
- package/dist/clickhouse/parser.js +1 -1
- package/dist/clickhouse/plan/commands.d.ts +2 -1
- package/dist/clickhouse/plan/commands.d.ts.map +1 -1
- package/dist/clickhouse/plan/commands.js +17 -2
- package/dist/clickhouse/plan/diff.d.ts +15 -0
- package/dist/clickhouse/plan/diff.d.ts.map +1 -1
- package/dist/clickhouse/plan/diff.js +43 -1
- package/dist/clickhouse/plan/disruption.d.ts.map +1 -1
- package/dist/clickhouse/plan/disruption.js +5 -0
- package/dist/clickhouse/plan/rebuild-handoff.d.ts.map +1 -1
- package/dist/clickhouse/plan/rebuild-handoff.js +4 -0
- package/dist/clickhouse/plan/report.d.ts.map +1 -1
- package/dist/clickhouse/plan/report.js +6 -1
- package/dist/clickhouse/plan/rules.d.ts +5 -1
- package/dist/clickhouse/plan/rules.d.ts.map +1 -1
- package/dist/clickhouse/plan/rules.js +7 -3
- 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/clickhouse/plan/stream.d.ts +40 -0
- package/dist/clickhouse/plan/stream.d.ts.map +1 -0
- package/dist/clickhouse/plan/stream.js +107 -0
- package/dist/clickhouse/rebuild/observe.d.ts +3 -1
- package/dist/clickhouse/rebuild/observe.d.ts.map +1 -1
- package/dist/clickhouse/rebuild/observe.js +14 -1
- package/dist/clickhouse/review-catalog.d.ts +213 -0
- package/dist/clickhouse/review-catalog.d.ts.map +1 -0
- package/dist/clickhouse/review-catalog.js +330 -0
- package/dist/codegen/classifier-page.d.ts.map +1 -1
- package/dist/codegen/classifier-page.js +44 -4
- package/dist/codegen/clickhouse-module.d.ts.map +1 -1
- package/dist/codegen/clickhouse-module.js +3 -0
- package/dist/codegen/coverage-page.d.ts.map +1 -1
- package/dist/codegen/coverage-page.js +5 -3
- package/dist/codegen/docs.js +1 -1
- package/dist/codegen/postgres-classifier-page.js +2 -2
- package/dist/codegen/registry.d.ts.map +1 -1
- package/dist/codegen/registry.js +10 -0
- package/dist/composites/catalog.d.ts.map +1 -1
- package/dist/composites/catalog.js +100 -0
- package/dist/composites/clickhouse.d.ts +2 -0
- package/dist/composites/clickhouse.d.ts.map +1 -1
- package/dist/composites/clickhouse.js +2 -0
- package/dist/composites/otel-tables.d.ts +100 -0
- package/dist/composites/otel-tables.d.ts.map +1 -0
- package/dist/composites/otel-tables.js +282 -0
- package/dist/composites/stream-ingest.d.ts +63 -0
- package/dist/composites/stream-ingest.d.ts.map +1 -0
- package/dist/composites/stream-ingest.js +39 -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/clickhouse.json +1 -1
- package/dist/coverage/postgres.json +12 -12
- package/dist/coverage.d.ts +16 -6
- package/dist/coverage.d.ts.map +1 -1
- package/dist/coverage.js +10 -5
- package/dist/drizzle-command.d.ts +17 -0
- package/dist/drizzle-command.d.ts.map +1 -0
- package/dist/drizzle-command.js +91 -0
- package/dist/drizzle.d.ts +70 -0
- package/dist/drizzle.d.ts.map +1 -0
- package/dist/drizzle.js +689 -0
- package/dist/files/clickhouse.d.ts.map +1 -1
- package/dist/files/clickhouse.js +8 -1
- package/dist/files/common.d.ts +13 -0
- package/dist/files/common.d.ts.map +1 -1
- package/dist/files/common.js +5 -0
- package/dist/files/postgres.d.ts.map +1 -1
- package/dist/files/postgres.js +35 -3
- package/dist/generated/clickhouse.d.ts +2 -0
- package/dist/generated/clickhouse.d.ts.map +1 -1
- package/dist/generated/clickhouse.js +2 -0
- package/dist/import-parser.d.ts +21 -1
- package/dist/import-parser.d.ts.map +1 -1
- package/dist/import-parser.js +79 -5
- 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 +7 -6
- package/dist/lint/post-synth/audit-entries.d.ts.map +1 -1
- package/dist/lint/post-synth/audit-entries.js +1 -0
- package/dist/lint/post-synth/index.d.ts.map +1 -1
- package/dist/lint/post-synth/index.js +2 -0
- 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/post-synth/sqlch128.d.ts +18 -0
- package/dist/lint/post-synth/sqlch128.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch128.js +222 -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 +21 -0
- package/dist/manifest.json +1 -1
- package/dist/mcp/postgres.js +1 -1
- package/dist/meta.json +50 -0
- package/dist/migrate/from-postgres/detect.d.ts +4 -0
- package/dist/migrate/from-postgres/detect.d.ts.map +1 -0
- package/dist/migrate/from-postgres/detect.js +7 -0
- package/dist/migrate/from-postgres/emit.d.ts +26 -0
- package/dist/migrate/from-postgres/emit.d.ts.map +1 -0
- package/dist/migrate/from-postgres/emit.js +86 -0
- package/dist/migrate/from-postgres/index.d.ts +51 -0
- package/dist/migrate/from-postgres/index.d.ts.map +1 -0
- package/dist/migrate/from-postgres/index.js +115 -0
- package/dist/migrate/from-postgres/translate.d.ts +73 -0
- package/dist/migrate/from-postgres/translate.d.ts.map +1 -0
- package/dist/migrate/from-postgres/translate.js +261 -0
- package/dist/migrate/from-postgres/types.d.ts +51 -0
- package/dist/migrate/from-postgres/types.d.ts.map +1 -0
- package/dist/migrate/from-postgres/types.js +211 -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/migration-replay.d.ts +73 -0
- package/dist/migration-replay.d.ts.map +1 -0
- package/dist/migration-replay.js +294 -0
- package/dist/okf/index.md +11 -0
- package/dist/okf/rules/SQLCH128.md +11 -0
- package/dist/okf/types/PostgresForeignDataWrapper.md +9 -0
- package/dist/okf/types/PostgresForeignServer.md +9 -0
- package/dist/okf/types/PostgresForeignTable.md +9 -0
- package/dist/okf/types/PostgresOperator.md +9 -0
- package/dist/okf/types/PostgresOperatorClass.md +9 -0
- package/dist/okf/types/PostgresOperatorFamily.md +9 -0
- package/dist/okf/types/PostgresPublication.md +9 -0
- package/dist/okf/types/PostgresStatistics.md +9 -0
- package/dist/okf/types/PostgresTextSearchConfiguration.md +9 -0
- package/dist/okf/types/PostgresTextSearchDictionary.md +9 -0
- package/dist/op/activities/postgres-migration.d.ts.map +1 -1
- package/dist/op/activities/postgres-migration.js +4 -0
- package/dist/op/activity-contracts.d.ts +20 -0
- package/dist/op/activity-contracts.d.ts.map +1 -1
- package/dist/op/activity-contracts.js +2 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +49 -2
- package/dist/postgres/access/acl.js +1 -1
- package/dist/postgres/access/import.js +1 -1
- package/dist/postgres/apply/apply.js +13 -1
- package/dist/postgres/apply/statements.d.ts.map +1 -1
- package/dist/postgres/apply/statements.js +243 -4
- package/dist/postgres/constraint-names.d.ts +30 -0
- package/dist/postgres/constraint-names.d.ts.map +1 -0
- package/dist/postgres/constraint-names.js +72 -0
- package/dist/postgres/entities.d.ts +229 -2
- package/dist/postgres/entities.d.ts.map +1 -1
- package/dist/postgres/entities.js +326 -5
- package/dist/postgres/entity-types.d.ts +10 -0
- package/dist/postgres/entity-types.d.ts.map +1 -1
- package/dist/postgres/entity-types.js +10 -0
- package/dist/postgres/import/generator.d.ts.map +1 -1
- package/dist/postgres/import/generator.js +65 -2
- package/dist/postgres/import/live-export.d.ts.map +1 -1
- package/dist/postgres/import/live-export.js +2 -0
- package/dist/postgres/live/catalog-kinds.d.ts +20 -0
- package/dist/postgres/live/catalog-kinds.d.ts.map +1 -1
- package/dist/postgres/live/catalog-kinds.js +452 -0
- package/dist/postgres/live/catalog.d.ts +2 -0
- package/dist/postgres/live/catalog.d.ts.map +1 -1
- package/dist/postgres/live/catalog.js +3 -1
- package/dist/postgres/live/describe-resources.d.ts.map +1 -1
- package/dist/postgres/live/describe-resources.js +12 -2
- package/dist/postgres/migrate/backfill.d.ts +2 -0
- package/dist/postgres/migrate/backfill.d.ts.map +1 -1
- package/dist/postgres/migrate/backfill.js +7 -1
- package/dist/postgres/migrate/carry.d.ts +45 -1
- package/dist/postgres/migrate/carry.d.ts.map +1 -1
- package/dist/postgres/migrate/carry.js +72 -8
- package/dist/postgres/migrate/observe.d.ts +28 -4
- package/dist/postgres/migrate/observe.d.ts.map +1 -1
- package/dist/postgres/migrate/observe.js +45 -13
- package/dist/postgres/migrate/op.d.ts +26 -1
- package/dist/postgres/migrate/op.d.ts.map +1 -1
- package/dist/postgres/migrate/op.js +3 -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/migrate/steps.d.ts +35 -2
- package/dist/postgres/migrate/steps.d.ts.map +1 -1
- package/dist/postgres/migrate/steps.js +158 -12
- package/dist/postgres/parser.d.ts +144 -1
- package/dist/postgres/parser.d.ts.map +1 -1
- package/dist/postgres/parser.js +370 -4
- package/dist/postgres/plan/deep.d.ts.map +1 -1
- package/dist/postgres/plan/deep.js +43 -4
- package/dist/postgres/plan/diff.d.ts.map +1 -1
- package/dist/postgres/plan/diff.js +154 -1
- package/dist/postgres/plan/normalize.d.ts +28 -2
- package/dist/postgres/plan/normalize.d.ts.map +1 -1
- package/dist/postgres/plan/normalize.js +260 -1
- package/dist/postgres/plan/rules.d.ts +4 -0
- package/dist/postgres/plan/rules.d.ts.map +1 -1
- package/dist/postgres/plan/rules.js +6 -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/secret-options.d.ts +10 -0
- package/dist/postgres/secret-options.d.ts.map +1 -0
- package/dist/postgres/secret-options.js +9 -0
- package/dist/postgres/testing/roundtrip-schema.d.ts +4 -2
- package/dist/postgres/testing/roundtrip-schema.d.ts.map +1 -1
- package/dist/postgres/testing/roundtrip-schema.js +24 -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/audit-entries.ts +1 -0
- package/dist/rules/postgres-names.ts +2 -0
- package/dist/rules/postgres-templates.ts +2 -2
- package/dist/rules/sqlch128.ts +230 -0
- package/dist/serializer.d.ts +5 -0
- package/dist/serializer.d.ts.map +1 -1
- package/dist/serializer.js +13 -2
- package/dist/sql-types-command.d.ts +13 -0
- package/dist/sql-types-command.d.ts.map +1 -1
- package/dist/sql-types-command.js +31 -16
- package/dist/sql-types.d.ts +22 -0
- package/dist/sql-types.d.ts.map +1 -1
- package/dist/sql-types.js +10 -6
- package/dist/sqlserver/lexer.d.ts +37 -0
- package/dist/sqlserver/lexer.d.ts.map +1 -0
- package/dist/sqlserver/lexer.js +254 -0
- package/dist/sqlserver/parse.d.ts +185 -0
- package/dist/sqlserver/parse.d.ts.map +1 -0
- package/dist/sqlserver/parse.js +767 -0
- package/dist/sqlserver/translate.d.ts +34 -0
- package/dist/sqlserver/translate.d.ts.map +1 -0
- package/dist/sqlserver/translate.js +495 -0
- package/dist/sqlserver/types.d.ts +44 -0
- package/dist/sqlserver/types.d.ts.map +1 -0
- package/dist/sqlserver/types.js +133 -0
- package/dist/sqlserver/validate.d.ts +31 -0
- package/dist/sqlserver/validate.d.ts.map +1 -0
- package/dist/sqlserver/validate.js +67 -0
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +10 -0
- package/package.json +2 -2
- package/src/change-set.ts +2 -1
- package/src/clickhouse/apply/statements.ts +25 -0
- package/src/clickhouse/import/live-export.ts +20 -5
- package/src/clickhouse/live/named-collections.e2e.test.ts +88 -0
- package/src/clickhouse/live/named-collections.ts +61 -0
- package/src/clickhouse/live/undeclarable.e2e.test.ts +5 -3
- package/src/clickhouse/live/undeclarable.ts +20 -4
- package/src/clickhouse/named-collections.test.ts +187 -0
- package/src/clickhouse/named-collections.ts +224 -0
- package/src/clickhouse/parser.ts +2 -1
- package/src/clickhouse/plan/commands.ts +17 -2
- package/src/clickhouse/plan/diff.ts +57 -1
- package/src/clickhouse/plan/disruption.ts +5 -0
- package/src/clickhouse/plan/rebuild-handoff.ts +3 -0
- package/src/clickhouse/plan/report.ts +6 -1
- package/src/clickhouse/plan/rules.ts +14 -4
- package/src/clickhouse/plan/statements.test.ts +61 -0
- package/src/clickhouse/plan/statements.ts +306 -0
- package/src/clickhouse/plan/stream-s3queue.e2e.test.ts +148 -0
- package/src/clickhouse/plan/stream.test.ts +237 -0
- package/src/clickhouse/plan/stream.ts +111 -0
- package/src/clickhouse/rebuild/observe.ts +15 -1
- package/src/clickhouse/review-catalog.test.ts +181 -0
- package/src/clickhouse/review-catalog.ts +489 -0
- package/src/codegen/classifier-page.ts +44 -4
- package/src/codegen/clickhouse-module.ts +3 -0
- package/src/codegen/coverage-page.ts +5 -3
- package/src/codegen/docs.ts +1 -1
- package/src/codegen/postgres-classifier-page.ts +2 -2
- package/src/codegen/registry.ts +10 -0
- package/src/composites/catalog.test.ts +6 -1
- package/src/composites/catalog.ts +100 -0
- package/src/composites/clickhouse.ts +2 -0
- package/src/composites/composites.test.ts +1 -1
- package/src/composites/otel-tables.test.ts +118 -0
- package/src/composites/otel-tables.ts +339 -0
- package/src/composites/stream-ingest.test.ts +114 -0
- package/src/composites/stream-ingest.ts +82 -0
- package/src/core/statement-class.ts +88 -0
- package/src/core/undeclarable.test.ts +6 -5
- package/src/coverage/clickhouse.json +1 -1
- package/src/coverage/postgres.json +12 -12
- package/src/coverage.test.ts +27 -2
- package/src/coverage.ts +18 -7
- package/src/drizzle-command.ts +94 -0
- package/src/drizzle-kit.e2e.test.ts +89 -0
- package/src/drizzle-types.e2e.test.ts +67 -0
- package/src/drizzle.test.ts +358 -0
- package/src/drizzle.ts +742 -0
- package/src/files/clickhouse.ts +8 -1
- package/src/files/common.ts +14 -1
- package/src/files/postgres.ts +34 -3
- package/src/generated/clickhouse.ts +3 -0
- package/src/generated/lexicon-sql.json +50 -0
- package/src/import-parser.sqlserver.test.ts +92 -0
- package/src/import-parser.ts +79 -5
- package/src/index.ts +1 -1
- package/src/lint/post-synth/audit-entries.ts +1 -0
- package/src/lint/post-synth/index.ts +2 -0
- package/src/lint/post-synth/postgres-checks.test.ts +8 -1
- package/src/lint/post-synth/postgres-names.ts +2 -0
- package/src/lint/post-synth/sqlch128.test.ts +107 -0
- package/src/lint/post-synth/sqlch128.ts +230 -0
- package/src/lint/rules/postgres-templates.ts +2 -2
- package/src/lsp/postgres-template.ts +20 -0
- package/src/mcp/postgres.ts +1 -1
- package/src/migrate/from-postgres/cli.test.ts +165 -0
- package/src/migrate/from-postgres/detect.ts +7 -0
- package/src/migrate/from-postgres/emit.ts +96 -0
- package/src/migrate/from-postgres/example.test.ts +205 -0
- package/src/migrate/from-postgres/index.ts +122 -0
- package/src/migrate/from-postgres/translate.test.ts +242 -0
- package/src/migrate/from-postgres/translate.ts +359 -0
- package/src/migrate/from-postgres/types.test.ts +116 -0
- package/src/migrate/from-postgres/types.ts +236 -0
- package/src/migrate/from-postgres/validate.e2e.test.ts +44 -0
- package/src/migrate/from-postgres/workspace.e2e.test.ts +114 -0
- package/src/migration-classify.test.ts +150 -0
- package/src/migration-classify.ts +45 -0
- package/src/migration-replay.e2e.test.ts +155 -0
- package/src/migration-replay.test.ts +173 -0
- package/src/migration-replay.ts +289 -0
- package/src/op/__snapshots__/watch-pipeline.test.ts.snap +2 -2
- package/src/op/activities/postgres-migration.ts +4 -0
- package/src/op/activity-contracts.ts +2 -0
- package/src/op/watch-pipeline.test.ts +8 -1
- package/src/plugin.ts +51 -2
- package/src/postgres/access/acl.ts +1 -1
- package/src/postgres/access/import.ts +1 -1
- package/src/postgres/apply/apply.ts +14 -1
- package/src/postgres/apply/statements.ts +225 -4
- package/src/postgres/constraint-names.ts +71 -0
- package/src/postgres/database-kinds.test.ts +865 -0
- package/src/postgres/entities.ts +541 -5
- package/src/postgres/entity-types.ts +10 -0
- package/src/postgres/import/generator.ts +54 -2
- package/src/postgres/import/live-export.ts +1 -0
- package/src/postgres/live/catalog-kinds.ts +494 -0
- package/src/postgres/live/catalog.ts +6 -1
- package/src/postgres/live/database-kinds.e2e.test.ts +164 -0
- package/src/postgres/live/describe-resources.ts +13 -2
- package/src/postgres/live/undeclarable.e2e.test.ts +13 -6
- package/src/postgres/migrate/backfill.ts +13 -1
- package/src/postgres/migrate/carry.ts +103 -8
- package/src/postgres/migrate/followups.e2e.test.ts +218 -0
- package/src/postgres/migrate/followups.test.ts +199 -0
- package/src/postgres/migrate/kinds.e2e.test.ts +5 -5
- package/src/postgres/migrate/observe.ts +56 -15
- package/src/postgres/migrate/op.ts +28 -1
- package/src/postgres/migrate/partition.e2e.test.ts +129 -0
- package/src/postgres/migrate/partition.test.ts +206 -0
- package/src/postgres/migrate/replication.ts +66 -0
- package/src/postgres/migrate/steps.ts +157 -12
- package/src/postgres/migrate/subscriber.e2e.test.ts +141 -0
- package/src/postgres/migrate/subscriber.test.ts +59 -0
- package/src/postgres/parser.ts +455 -4
- package/src/postgres/plan/deep.ts +42 -4
- package/src/postgres/plan/diff.ts +137 -1
- package/src/postgres/plan/normalize.ts +277 -1
- package/src/postgres/plan/rules.ts +32 -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/secret-options.ts +10 -0
- package/src/postgres/testing/roundtrip-schema.ts +24 -1
- package/src/postgres.ts +33 -0
- package/src/serializer.ts +13 -2
- package/src/skills/chant-sql-postgres-migration.md +4 -3
- package/src/skills/chant-sql-postgres.md +11 -1
- package/src/skills/chant-sql.md +2 -1
- package/src/sql-files.test.ts +33 -0
- package/src/sql-types-command.ts +38 -16
- package/src/sql-types.ts +11 -6
- package/src/sqlserver/fixture.test.ts +186 -0
- package/src/sqlserver/import-cli.test.ts +61 -0
- package/src/sqlserver/lexer.ts +260 -0
- package/src/sqlserver/parse.ts +865 -0
- package/src/sqlserver/translate.test.ts +396 -0
- package/src/sqlserver/translate.ts +558 -0
- package/src/sqlserver/types.test.ts +102 -0
- package/src/sqlserver/types.ts +154 -0
- package/src/sqlserver/validate.e2e.test.ts +32 -0
- package/src/sqlserver/validate.test.ts +49 -0
- package/src/sqlserver/validate.ts +76 -0
- package/src/validate.ts +10 -0
- package/src/workspace-kinds.test.ts +11 -0
- package/workspace-kinds.json +100 -2
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `StreamIngest`: the usual ClickHouse ingestion chain, a stream table, a materialized view reading it and a MergeTree target.
|
|
3
|
+
*
|
|
4
|
+
* The stream table (Kafka, S3Queue, AzureQueue, RabbitMQ, NATS or FileLog)
|
|
5
|
+
* stores no rows: it is the consumer. The materialized view pulls each batch
|
|
6
|
+
* through it with `TO` and writes the target, which is an ordinary MergeTree
|
|
7
|
+
* table that can be queried, altered and backfilled on its own. Every column
|
|
8
|
+
* the view's select list writes has to be one the target declares (SQLCH110).
|
|
9
|
+
*
|
|
10
|
+
* The stream engine usually carries credentials. Name a named collection as
|
|
11
|
+
* its first argument (`Kafka(kafka_creds)`, `S3Queue(lake_creds)`) and keep
|
|
12
|
+
* the broker, bucket and keys in the collection on the server: chant never
|
|
13
|
+
* declares or reads one (#4395), and SQLCH128 fails a build that writes a
|
|
14
|
+
* password in the engine's arguments.
|
|
15
|
+
*
|
|
16
|
+
* A change to the stream table is planned as SQLCH225, not as a rebuild: the
|
|
17
|
+
* view is detached, the table replaced and the view attached again. A
|
|
18
|
+
* different `kafka_group_name` or S3Queue `keeper_path` loses the table's
|
|
19
|
+
* position, and the plan says so (#4396).
|
|
20
|
+
*/
|
|
21
|
+
import { type ClickHouseTable, type ClickHouseView } from "../clickhouse/entities.js";
|
|
22
|
+
import type { ClickHouseMemberName } from "../core/typed.js";
|
|
23
|
+
import type { Instance, TypedComposite } from "./typed.js";
|
|
24
|
+
export interface StreamIngestProps {
|
|
25
|
+
/** The target table's name. The stream table is `<name>_stream` and the view `<name>_mv`. */
|
|
26
|
+
name: string;
|
|
27
|
+
/** The target's columns, as SQL: `ts DateTime, user_id UInt64, kind LowCardinality(String)`. */
|
|
28
|
+
columns: string;
|
|
29
|
+
/**
|
|
30
|
+
* The stream table's engine, with a named collection as its first argument
|
|
31
|
+
* rather than inline credentials: `Kafka(kafka_creds)`, `S3Queue(lake_creds)`.
|
|
32
|
+
*/
|
|
33
|
+
engine: string;
|
|
34
|
+
/**
|
|
35
|
+
* The engine's settings, the body of a `SETTINGS` clause:
|
|
36
|
+
* `kafka_topic_list = 'events', kafka_group_name = 'ingest', kafka_format = 'JSONEachRow'`.
|
|
37
|
+
* Settings the named collection already holds are left out.
|
|
38
|
+
*/
|
|
39
|
+
settings?: string;
|
|
40
|
+
/** The stream table's columns when they differ from the target's: the message as it arrives. Default: `columns`. */
|
|
41
|
+
streamColumns?: string;
|
|
42
|
+
/** The view's select list over the stream table, each item aliased to a target column. Default: `*`. */
|
|
43
|
+
select?: string;
|
|
44
|
+
/** The target's sort key (a column list or an expression). */
|
|
45
|
+
orderBy: string;
|
|
46
|
+
/** The target's engine (default `MergeTree`). */
|
|
47
|
+
targetEngine?: string;
|
|
48
|
+
/** The target's partition key. Left out by default. */
|
|
49
|
+
partitionBy?: string;
|
|
50
|
+
}
|
|
51
|
+
/** `Target`, `Stream` and `View` are the members' names, when the call's props give them (chant#3787). */
|
|
52
|
+
export type StreamIngestMembers<Target extends string = string, Stream extends string = string, View extends string = string> = {
|
|
53
|
+
target: ClickHouseTable<Target>;
|
|
54
|
+
stream: ClickHouseTable<Stream>;
|
|
55
|
+
view: ClickHouseView<View>;
|
|
56
|
+
};
|
|
57
|
+
type StreamIngestCall = <const N extends string>(props: StreamIngestProps & {
|
|
58
|
+
name: N;
|
|
59
|
+
}) => Instance<StreamIngestMembers<ClickHouseMemberName<N>, ClickHouseMemberName<N, "_stream">, ClickHouseMemberName<N, "_mv">>>;
|
|
60
|
+
/** A stream table, the materialized view that reads it, and the MergeTree target the view writes. */
|
|
61
|
+
export declare const StreamIngest: TypedComposite<StreamIngestProps, StreamIngestMembers<string, string, string>, StreamIngestCall>;
|
|
62
|
+
export {};
|
|
63
|
+
//# sourceMappingURL=stream-ingest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-ingest.d.ts","sourceRoot":"","sources":["../../src/composites/stream-ingest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAe,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAChG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAExD,MAAM,WAAW,iBAAiB;IAChC,6FAA6F;IAC7F,IAAI,EAAE,MAAM,CAAC;IACb,gGAAgG;IAChG,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oHAAoH;IACpH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wGAAwG;IACxG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,uDAAuD;IACvD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,0GAA0G;AAC1G,MAAM,MAAM,mBAAmB,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,EAAE,MAAM,SAAS,MAAM,GAAG,MAAM,EAAE,IAAI,SAAS,MAAM,GAAG,MAAM,IAAI;IAC9H,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IAChC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;CAC5B,CAAC;AAEF,KAAK,gBAAgB,GAAG,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EAC7C,KAAK,EAAE,iBAAiB,GAAG;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,KACnC,QAAQ,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,oBAAoB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AAEhI,qGAAqG;AACrG,eAAO,MAAM,YAAY,kGAeP,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `StreamIngest`: the usual ClickHouse ingestion chain, a stream table, a materialized view reading it and a MergeTree target.
|
|
3
|
+
*
|
|
4
|
+
* The stream table (Kafka, S3Queue, AzureQueue, RabbitMQ, NATS or FileLog)
|
|
5
|
+
* stores no rows: it is the consumer. The materialized view pulls each batch
|
|
6
|
+
* through it with `TO` and writes the target, which is an ordinary MergeTree
|
|
7
|
+
* table that can be queried, altered and backfilled on its own. Every column
|
|
8
|
+
* the view's select list writes has to be one the target declares (SQLCH110).
|
|
9
|
+
*
|
|
10
|
+
* The stream engine usually carries credentials. Name a named collection as
|
|
11
|
+
* its first argument (`Kafka(kafka_creds)`, `S3Queue(lake_creds)`) and keep
|
|
12
|
+
* the broker, bucket and keys in the collection on the server: chant never
|
|
13
|
+
* declares or reads one (#4395), and SQLCH128 fails a build that writes a
|
|
14
|
+
* password in the engine's arguments.
|
|
15
|
+
*
|
|
16
|
+
* A change to the stream table is planned as SQLCH225, not as a rebuild: the
|
|
17
|
+
* view is detached, the table replaced and the view attached again. A
|
|
18
|
+
* different `kafka_group_name` or S3Queue `keeper_path` loses the table's
|
|
19
|
+
* position, and the plan says so (#4396).
|
|
20
|
+
*/
|
|
21
|
+
import { Composite } from "@intentius/chant/composite";
|
|
22
|
+
import { table, view } from "../clickhouse/entities.js";
|
|
23
|
+
/** A stream table, the materialized view that reads it, and the MergeTree target the view writes. */
|
|
24
|
+
export const StreamIngest = Composite((props) => {
|
|
25
|
+
const target = table `
|
|
26
|
+
CREATE TABLE ${props.name} (${props.columns})
|
|
27
|
+
ENGINE = ${props.targetEngine ?? "MergeTree"}
|
|
28
|
+
${props.partitionBy ? `PARTITION BY ${props.partitionBy}` : ""}
|
|
29
|
+
ORDER BY ${props.orderBy}`;
|
|
30
|
+
const stream = table `
|
|
31
|
+
CREATE TABLE ${`${props.name}_stream`} (${props.streamColumns ?? props.columns})
|
|
32
|
+
ENGINE = ${props.engine}
|
|
33
|
+
${props.settings ? `SETTINGS ${props.settings}` : ""}`;
|
|
34
|
+
const ingest = view `
|
|
35
|
+
CREATE MATERIALIZED VIEW ${`${props.name}_mv`} TO ${target} AS
|
|
36
|
+
SELECT ${props.select ?? "*"}
|
|
37
|
+
FROM ${stream}`;
|
|
38
|
+
return { target, stream, view: ingest };
|
|
39
|
+
}, "StreamIngest");
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the statement classifiers (`../clickhouse/plan/statements.ts`,
|
|
3
|
+
* `../postgres/plan/statements.ts`) answer, in one shape for both dialects
|
|
4
|
+
* (#4407). They read a migration file's statements offline and give each the
|
|
5
|
+
* class the schema-diff classifier gives the same change, citing its rule.
|
|
6
|
+
* Nothing runs against a server.
|
|
7
|
+
*/
|
|
8
|
+
import type { ClassifierRule } from "./classifier.js";
|
|
9
|
+
/** One change a statement makes, under one rule. */
|
|
10
|
+
export interface StatementClassified {
|
|
11
|
+
rule: string;
|
|
12
|
+
/** The rule's class, e.g. `rebuild`, `concurrently`. */
|
|
13
|
+
class: string;
|
|
14
|
+
/** The class as a report names it, e.g. `REBUILD`. */
|
|
15
|
+
label: string;
|
|
16
|
+
title: string;
|
|
17
|
+
/** Postgres: the lock the rule's restriction names, e.g. `SHARE`. */
|
|
18
|
+
lock?: string;
|
|
19
|
+
/** Data is removed and not recoverable. */
|
|
20
|
+
destructive?: boolean;
|
|
21
|
+
note?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* - `classified`: every change has a rule.
|
|
25
|
+
* - `undecided`: the statement alone cannot say which of `candidates` applies
|
|
26
|
+
* (a column type change is a rewrite, or a rebuild when the column is in a
|
|
27
|
+
* key); the answer `classifyDisruption()` calls `unknown`.
|
|
28
|
+
* - `unclassified`: a schema change no rule covers; `note` says what.
|
|
29
|
+
* - `data`: the statement reads or writes rows or the session, not the schema.
|
|
30
|
+
*/
|
|
31
|
+
export type StatementOutcome = "classified" | "undecided" | "unclassified" | "data";
|
|
32
|
+
export interface StatementVerdict {
|
|
33
|
+
/** 1-based position among the file's up statements. */
|
|
34
|
+
index: number;
|
|
35
|
+
/** The statement's first line, cut to 120 characters. */
|
|
36
|
+
sql: string;
|
|
37
|
+
outcome: StatementOutcome;
|
|
38
|
+
/** `classified`: one entry per change in the statement (an `ALTER TABLE` can hold several). */
|
|
39
|
+
changes: StatementClassified[];
|
|
40
|
+
/** `undecided`: the rules that could apply, in the order a reader should weigh them. */
|
|
41
|
+
candidates?: StatementClassified[];
|
|
42
|
+
note?: string;
|
|
43
|
+
}
|
|
44
|
+
/** A statement's own text cut for a note: the first line, at most 120 characters. */
|
|
45
|
+
export declare function sqlHead(sql: string): string;
|
|
46
|
+
/** The pieces of a classified change from a dialect's rule table. */
|
|
47
|
+
export declare function classifiedOf<C extends string>(rules: Readonly<Record<string, ClassifierRule<C>>>, labels: Readonly<Record<C, string>>, id: string, extra?: Partial<StatementClassified>): StatementClassified;
|
|
48
|
+
/** The first lock a rule's restriction names, or undefined when it names none. */
|
|
49
|
+
export declare const lockOf: (restriction: string) => string | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Split a statement's tokens' text into the pieces between top-level commas
|
|
52
|
+
* (an `ALTER TABLE`'s actions). Parentheses and brackets nest.
|
|
53
|
+
*/
|
|
54
|
+
export declare function splitTopLevel(words: readonly string[]): string[][];
|
|
55
|
+
//# sourceMappingURL=statement-class.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statement-class.d.ts","sourceRoot":"","sources":["../../src/core/statement-class.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,oDAAoD;AACpD,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,KAAK,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,qEAAqE;IACrE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG,WAAW,GAAG,cAAc,GAAG,MAAM,CAAC;AAEpF,MAAM,WAAW,gBAAgB;IAC/B,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,gBAAgB,CAAC;IAC1B,+FAA+F;IAC/F,OAAO,EAAE,mBAAmB,EAAE,CAAC;IAC/B,wFAAwF;IACxF,UAAU,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,qFAAqF;AACrF,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI3C;AAED,qEAAqE;AACrE,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAC3C,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,EAClD,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,EACnC,EAAE,EAAE,MAAM,EACV,KAAK,GAAE,OAAO,CAAC,mBAAmB,CAAM,GACvC,mBAAmB,CAIrB;AAKD,kFAAkF;AAClF,eAAO,MAAM,MAAM,GAAI,aAAa,MAAM,KAAG,MAAM,GAAG,SAAwC,CAAC;AAE/F;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE,CAUlE"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the statement classifiers (`../clickhouse/plan/statements.ts`,
|
|
3
|
+
* `../postgres/plan/statements.ts`) answer, in one shape for both dialects
|
|
4
|
+
* (#4407). They read a migration file's statements offline and give each the
|
|
5
|
+
* class the schema-diff classifier gives the same change, citing its rule.
|
|
6
|
+
* Nothing runs against a server.
|
|
7
|
+
*/
|
|
8
|
+
/** A statement's own text cut for a note: the first line, at most 120 characters. */
|
|
9
|
+
export function sqlHead(sql) {
|
|
10
|
+
const line = sql.split(/\r?\n/).find((l) => l.trim() !== "" && !l.trim().startsWith("--")) ?? sql;
|
|
11
|
+
const t = line.trim().replace(/\s+/g, " ");
|
|
12
|
+
return t.length > 120 ? `${t.slice(0, 117)}...` : t;
|
|
13
|
+
}
|
|
14
|
+
/** The pieces of a classified change from a dialect's rule table. */
|
|
15
|
+
export function classifiedOf(rules, labels, id, extra = {}) {
|
|
16
|
+
const r = rules[id];
|
|
17
|
+
if (!r)
|
|
18
|
+
throw new Error(`no classifier rule ${id}`);
|
|
19
|
+
return { rule: id, class: r.class, label: labels[r.class], title: r.title, ...extra };
|
|
20
|
+
}
|
|
21
|
+
/** Lock names, longest first so `SHARE UPDATE EXCLUSIVE` is not read as `SHARE`. */
|
|
22
|
+
const LOCK = /\b(ACCESS EXCLUSIVE|SHARE UPDATE EXCLUSIVE|SHARE ROW EXCLUSIVE|ROW EXCLUSIVE|ROW SHARE|EXCLUSIVE|SHARE)\b/;
|
|
23
|
+
/** The first lock a rule's restriction names, or undefined when it names none. */
|
|
24
|
+
export const lockOf = (restriction) => LOCK.exec(restriction)?.[1];
|
|
25
|
+
/**
|
|
26
|
+
* Split a statement's tokens' text into the pieces between top-level commas
|
|
27
|
+
* (an `ALTER TABLE`'s actions). Parentheses and brackets nest.
|
|
28
|
+
*/
|
|
29
|
+
export function splitTopLevel(words) {
|
|
30
|
+
const out = [[]];
|
|
31
|
+
let depth = 0;
|
|
32
|
+
for (const w of words) {
|
|
33
|
+
if (w === "(" || w === "[")
|
|
34
|
+
depth++;
|
|
35
|
+
else if (w === ")" || w === "]")
|
|
36
|
+
depth--;
|
|
37
|
+
if (w === "," && depth === 0)
|
|
38
|
+
out.push([]);
|
|
39
|
+
else
|
|
40
|
+
out[out.length - 1].push(w);
|
|
41
|
+
}
|
|
42
|
+
return out.filter((a) => a.length > 0);
|
|
43
|
+
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
{ "command": "CREATE HANDLER", "kind": "HTTP handler", "status": "refused", "reason": "an HTTP handler is server-level configuration, not a schema object" },
|
|
9
9
|
{ "command": "CREATE INDEX", "kind": "index", "status": "declared", "entity": "ClickHouse::Table", "note": "an index is part of its table: SHOW CREATE TABLE prints it, and the table's declaration holds it" },
|
|
10
10
|
{ "command": "CREATE MASKING POLICY", "kind": "masking policy", "status": "refused", "reason": "masking policies are available only in ClickHouse Cloud, not on the pinned server" },
|
|
11
|
-
{ "command": "CREATE NAMED COLLECTION", "kind": "named collection", "status": "
|
|
11
|
+
{ "command": "CREATE NAMED COLLECTION", "kind": "named collection", "status": "referenced", "reason": "a named collection holds credentials (a password, a secret key), which are the environment's: chant never declares one or reads its values. An engine, a table function or a dictionary SOURCE names it, a plan checks that it exists, and import lists the server's as prerequisites" },
|
|
12
12
|
{ "command": "CREATE QUOTA", "kind": "quota", "status": "declared", "entity": "ClickHouse::Quota", "note": "import reads only the access objects a build declares" },
|
|
13
13
|
{ "command": "CREATE RESOURCE", "kind": "workload resource", "status": "refused", "reason": "a resource is server-level scheduling (a disk's reads or writes), configured with the server, not a schema object" },
|
|
14
14
|
{ "command": "CREATE ROLE", "kind": "role", "status": "declared", "entity": "ClickHouse::Role", "note": "import reads only the access objects a build declares" },
|
|
@@ -10,32 +10,32 @@
|
|
|
10
10
|
{ "command": "CREATE DOMAIN", "kind": "domain", "status": "declared", "entity": "Postgres::Domain" },
|
|
11
11
|
{ "command": "CREATE EVENT TRIGGER", "kind": "event trigger", "status": "declared", "entity": "Postgres::EventTrigger", "note": "the database's, not a schema's; creating one takes a superuser" },
|
|
12
12
|
{ "command": "CREATE EXTENSION", "kind": "extension", "status": "declared", "entity": "Postgres::Extension" },
|
|
13
|
-
{ "command": "CREATE FOREIGN DATA WRAPPER", "kind": "foreign data wrapper", "status": "
|
|
14
|
-
{ "command": "CREATE FOREIGN TABLE", "kind": "foreign table", "status": "
|
|
13
|
+
{ "command": "CREATE FOREIGN DATA WRAPPER", "kind": "foreign data wrapper", "status": "declared", "entity": "Postgres::ForeignDataWrapper", "note": "the database's, not a schema's; creating one takes a superuser; one an extension installs comes with the extension; an option that holds a credential is refused" },
|
|
14
|
+
{ "command": "CREATE FOREIGN TABLE", "kind": "foreign table", "status": "declared", "entity": "Postgres::ForeignTable", "note": "its own tag, not table: another CREATE and ALTER, no key, index or storage clauses; its server cannot be altered; one that is a partition, inherits or has a generated column is not declared; an option that holds a credential is refused" },
|
|
15
15
|
{ "command": "CREATE FUNCTION", "kind": "function", "status": "declared", "entity": "Postgres::Function" },
|
|
16
16
|
{ "command": "CREATE FUNCTION", "form": "RETURN or BEGIN ATOMIC body", "match": "\\b(?:RETURN|BEGIN\\s+ATOMIC)\\b", "kind": "routine with a SQL-standard body", "status": "refused", "reason": "the server stores a SQL-standard body parsed and prints it back rewritten, so a declaration cannot be compared with it; declare the routine with a string body (AS $$ ... $$)" },
|
|
17
17
|
{ "command": "CREATE GROUP", "kind": "group", "status": "declared", "entity": "Postgres::Role", "note": "an alias of CREATE ROLE" },
|
|
18
18
|
{ "command": "CREATE INDEX", "kind": "index", "status": "declared", "entity": "Postgres::Index" },
|
|
19
19
|
{ "command": "CREATE LANGUAGE", "kind": "procedural language", "status": "refused", "reason": "no tag declares a procedural language; an extension installs one, and the extension is declared instead" },
|
|
20
20
|
{ "command": "CREATE MATERIALIZED VIEW", "kind": "materialized view", "status": "declared", "entity": "Postgres::MaterializedView" },
|
|
21
|
-
{ "command": "CREATE OPERATOR", "kind": "operator", "status": "
|
|
22
|
-
{ "command": "CREATE OPERATOR CLASS", "kind": "operator class", "status": "
|
|
23
|
-
{ "command": "CREATE OPERATOR FAMILY", "kind": "operator family", "status": "
|
|
21
|
+
{ "command": "CREATE OPERATOR", "kind": "operator", "status": "declared", "entity": "Postgres::Operator", "note": "identified by its name and operand types; RESTRICT and JOIN change in place, and from 17 so does setting a commutator or negator or turning on HASHES or MERGES; anything else is a drop and a create" },
|
|
22
|
+
{ "command": "CREATE OPERATOR CLASS", "kind": "operator class", "status": "declared", "entity": "Postgres::OperatorClass", "note": "identified by its name and index method; a change is a drop and a create, since ALTER OPERATOR CLASS only renames or moves it; its own family, named as the class, comes with it" },
|
|
23
|
+
{ "command": "CREATE OPERATOR FAMILY", "kind": "operator family", "status": "declared", "entity": "Postgres::OperatorFamily", "note": "identified by its name and index method; its members come with the classes that name it, and loose members added with ALTER OPERATOR FAMILY are not declared" },
|
|
24
24
|
{ "command": "CREATE POLICY", "kind": "policy", "status": "declared", "entity": "Postgres::Policy", "note": "read where the profile manages access (sql.profiles.<env>.access)" },
|
|
25
25
|
{ "command": "CREATE PROCEDURE", "kind": "procedure", "status": "declared", "entity": "Postgres::Procedure" },
|
|
26
|
-
{ "command": "CREATE PUBLICATION", "kind": "publication", "status": "
|
|
26
|
+
{ "command": "CREATE PUBLICATION", "kind": "publication", "status": "declared", "entity": "Postgres::Publication", "note": "the database's, not a schema's; a table of it may carry a column list and row filter from 15" },
|
|
27
27
|
{ "command": "CREATE ROLE", "kind": "role", "status": "declared", "entity": "Postgres::Role", "note": "import reads only the roles a build declares, since a role is the cluster's" },
|
|
28
28
|
{ "command": "CREATE RULE", "kind": "rule", "status": "refused", "reason": "no tag declares a rewrite rule; a view's own rule is the view's" },
|
|
29
29
|
{ "command": "CREATE SCHEMA", "kind": "schema", "status": "declared", "entity": "Postgres::Schema" },
|
|
30
30
|
{ "command": "CREATE SEQUENCE", "kind": "sequence", "status": "declared", "entity": "Postgres::Sequence" },
|
|
31
|
-
{ "command": "CREATE SERVER", "kind": "foreign server", "status": "
|
|
32
|
-
{ "command": "CREATE STATISTICS", "kind": "extended statistics", "status": "
|
|
33
|
-
{ "command": "CREATE SUBSCRIPTION", "kind": "subscription", "status": "refused", "reason": "
|
|
31
|
+
{ "command": "CREATE SERVER", "kind": "foreign server", "status": "declared", "entity": "Postgres::ForeignServer", "note": "the database's, not a schema's; its user mappings are refused, so credentials stay out of the declaration" },
|
|
32
|
+
{ "command": "CREATE STATISTICS", "kind": "extended statistics", "status": "declared", "entity": "Postgres::Statistics" },
|
|
33
|
+
{ "command": "CREATE SUBSCRIPTION", "kind": "subscription", "status": "refused", "reason": "a subscription's connection string carries a credential, and creating one opens a replication slot on the publisher, outside this database; the environment makes it" },
|
|
34
34
|
{ "command": "CREATE TABLE", "kind": "table", "status": "declared", "entity": "Postgres::Table" },
|
|
35
35
|
{ "command": "CREATE TABLE AS", "kind": "table from a query", "status": "declared", "entity": "Postgres::Table", "note": "the server keeps no query, so the table it made reads as a CREATE TABLE" },
|
|
36
36
|
{ "command": "CREATE TABLESPACE", "kind": "tablespace", "status": "out-of-scope", "reason": "a tablespace is the cluster's, a directory on the server; a table's TABLESPACE clause is kept" },
|
|
37
|
-
{ "command": "CREATE TEXT SEARCH CONFIGURATION", "kind": "text search configuration", "status": "
|
|
38
|
-
{ "command": "CREATE TEXT SEARCH DICTIONARY", "kind": "text search dictionary", "status": "
|
|
37
|
+
{ "command": "CREATE TEXT SEARCH CONFIGURATION", "kind": "text search configuration", "status": "declared", "entity": "Postgres::TextSearchConfiguration", "note": "PARSER and its ADD MAPPING statements; COPY is refused, since it copies mappings chant does not read; mappings change in place, the parser by drop and create" },
|
|
38
|
+
{ "command": "CREATE TEXT SEARCH DICTIONARY", "kind": "text search dictionary", "status": "declared", "entity": "Postgres::TextSearchDictionary", "note": "a template and its options; options change in place, the template by drop and create" },
|
|
39
39
|
{ "command": "CREATE TEXT SEARCH PARSER", "kind": "text search parser", "status": "refused", "reason": "no tag declares a text search parser; one is C code an extension installs" },
|
|
40
40
|
{ "command": "CREATE TEXT SEARCH TEMPLATE", "kind": "text search template", "status": "refused", "reason": "no tag declares a text search template; one is C code an extension installs" },
|
|
41
41
|
{ "command": "CREATE TRANSFORM", "kind": "transform", "status": "refused", "reason": "no tag declares a transform; an extension installs one" },
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
{ "command": "CREATE TYPE", "form": "AS RANGE", "match": "\\bAS\\s+RANGE\\b", "kind": "range type", "status": "declared", "entity": "Postgres::RangeType", "note": "its multirange type comes with it (MULTIRANGE_TYPE_NAME)" },
|
|
46
46
|
{ "command": "CREATE TYPE", "form": "INPUT, OUTPUT, or a shell type", "kind": "base type", "status": "refused", "reason": "no tag declares a base type; its input and output functions are C code an extension installs" },
|
|
47
47
|
{ "command": "CREATE USER", "kind": "user", "status": "declared", "entity": "Postgres::Role", "note": "an alias of CREATE ROLE ... LOGIN" },
|
|
48
|
-
{ "command": "CREATE USER MAPPING", "kind": "user mapping", "status": "refused", "reason": "
|
|
48
|
+
{ "command": "CREATE USER MAPPING", "kind": "user mapping", "status": "refused", "reason": "a user mapping carries the remote user and password, which the environment supplies and a declaration never holds" },
|
|
49
49
|
{ "command": "CREATE VIEW", "kind": "view", "status": "declared", "entity": "Postgres::View" }
|
|
50
50
|
]
|
|
51
51
|
}
|
package/dist/coverage.d.ts
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
* Which kinds of object each dialect declares (#3911): every `CREATE` command
|
|
5
5
|
* a pinned server has (`./coverage/<dialect>-commands.json`, written by
|
|
6
6
|
* `scripts/sql-create-commands.ts` from the server's own sources) has a row
|
|
7
|
-
* in `./coverage/<dialect>.json` marking it declared, refused
|
|
8
|
-
* or out of scope. A
|
|
7
|
+
* in `./coverage/<dialect>.json` marking it declared, referenced, refused
|
|
8
|
+
* with a reason, or out of scope. A referenced kind (a ClickHouse named
|
|
9
|
+
* collection, #4395) is never declared: a declaration names one, a plan
|
|
10
|
+
* checks it exists, and import lists the server's as prerequisites. A command with several forms that differ in what chant can
|
|
9
11
|
* hold (`CREATE TYPE ... AS ENUM` and `CREATE TYPE ... AS RANGE`) has a row
|
|
10
12
|
* per form. Import refuses an object of a refused kind by that row's `kind`
|
|
11
13
|
* (`./core/undeclarable.ts`), and the docs page is rendered from the rows
|
|
@@ -21,8 +23,15 @@
|
|
|
21
23
|
* that, per section, from the generated tables.
|
|
22
24
|
*/
|
|
23
25
|
import type { SqlDialect } from "./dialects.js";
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
+
/**
|
|
27
|
+
* `declared`: a tag holds it. `referenced`: the environment's, never declared
|
|
28
|
+
* and its values never read; a declaration names it, a plan checks it exists,
|
|
29
|
+
* and import lists the server's as prerequisites (#4395). `refused`: import
|
|
30
|
+
* names it and stops. `out-of-scope`: the environment's, never imported.
|
|
31
|
+
*/
|
|
32
|
+
export type KindStatus = "declared" | "referenced" | "refused" | "out-of-scope";
|
|
33
|
+
/** Every status a coverage row may have. */
|
|
34
|
+
export declare const KIND_STATUSES: readonly KindStatus[];
|
|
26
35
|
/** One row of a dialect's coverage table: a `CREATE` command, or one form of it. */
|
|
27
36
|
export interface KindRow {
|
|
28
37
|
/** The command as the server's reference names it: `CREATE TYPE`. */
|
|
@@ -40,7 +49,7 @@ export interface KindRow {
|
|
|
40
49
|
status: KindStatus;
|
|
41
50
|
/** The entity type that declares it, when declared. */
|
|
42
51
|
entity?: string;
|
|
43
|
-
/** Why it is refused or out of scope. */
|
|
52
|
+
/** Why it is referenced, refused or out of scope. */
|
|
44
53
|
reason?: string;
|
|
45
54
|
/** Anything else a reader should know. */
|
|
46
55
|
note?: string;
|
|
@@ -58,7 +67,8 @@ export declare function kindRow(dialect: SqlDialect, kind: string): KindRow;
|
|
|
58
67
|
* What is wrong with a dialect's coverage table, against its pinned servers'
|
|
59
68
|
* commands: a command a pinned server has and no row covers, a row for a
|
|
60
69
|
* command no pinned server has, a kind named twice, a declared row with no
|
|
61
|
-
* entity, a refused or out-of-scope row with no reason. Empty
|
|
70
|
+
* entity, a referenced, refused or out-of-scope row with no reason. Empty
|
|
71
|
+
* when complete.
|
|
62
72
|
*/
|
|
63
73
|
export declare function kindCoverageProblems(dialect: SqlDialect, opts?: {
|
|
64
74
|
pins?: ReadonlyArray<{
|
package/dist/coverage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coverage.d.ts","sourceRoot":"","sources":["../src/coverage.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"coverage.d.ts","sourceRoot":"","sources":["../src/coverage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAQ7C;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,YAAY,GAAG,SAAS,GAAG,cAAc,CAAC;AAEhF,4CAA4C;AAC5C,eAAO,MAAM,aAAa,EAAE,SAAS,UAAU,EAA0D,CAAC;AAE1G,oFAAoF;AACpF,MAAM,WAAW,OAAO;IACtB,qEAAqE;IACrE,OAAO,EAAE,MAAM,CAAC;IAChB,2GAA2G;IAC3G,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iFAAiF;IACjF,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,UAAU,CAAC;IACnB,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,qCAAqC;AACrC,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,UAAU,EAAE,SAAS,OAAO,EAAE,CAGhE,CAAC;AAEF,2GAA2G;AAC3G,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC,CAG/G,CAAC;AAEF,2HAA2H;AAC3H,wBAAgB,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAIlE;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,GAAE;IAAE,IAAI,CAAC,EAAE,aAAa,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;IAAC,IAAI,CAAC,EAAE,SAAS,OAAO,EAAE,CAAA;CAAO,GAAG,MAAM,EAAE,CAmBpL;AAiBD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAcnF;AAED,sHAAsH;AACtH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,EAAE,CAQnE;AAID,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,eAAe,EAAE,CAAC;CAC7B;AAED,wBAAgB,OAAO,IAAI,cAAc,CAyBxC;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,cAAc,EAAE,IAAI,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,IAAI,CAYjH"}
|
package/dist/coverage.js
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
* Which kinds of object each dialect declares (#3911): every `CREATE` command
|
|
5
5
|
* a pinned server has (`./coverage/<dialect>-commands.json`, written by
|
|
6
6
|
* `scripts/sql-create-commands.ts` from the server's own sources) has a row
|
|
7
|
-
* in `./coverage/<dialect>.json` marking it declared, refused
|
|
8
|
-
* or out of scope. A
|
|
7
|
+
* in `./coverage/<dialect>.json` marking it declared, referenced, refused
|
|
8
|
+
* with a reason, or out of scope. A referenced kind (a ClickHouse named
|
|
9
|
+
* collection, #4395) is never declared: a declaration names one, a plan
|
|
10
|
+
* checks it exists, and import lists the server's as prerequisites. A command with several forms that differ in what chant can
|
|
9
11
|
* hold (`CREATE TYPE ... AS ENUM` and `CREATE TYPE ... AS RANGE`) has a row
|
|
10
12
|
* per form. Import refuses an object of a refused kind by that row's `kind`
|
|
11
13
|
* (`./core/undeclarable.ts`), and the docs page is rendered from the rows
|
|
@@ -26,6 +28,8 @@ import postgresKinds from "./coverage/postgres.json" with { type: "json" };
|
|
|
26
28
|
import clickhouseKinds from "./coverage/clickhouse.json" with { type: "json" };
|
|
27
29
|
import postgresCommands from "./coverage/postgres-commands.json" with { type: "json" };
|
|
28
30
|
import clickhouseCommands from "./coverage/clickhouse-commands.json" with { type: "json" };
|
|
31
|
+
/** Every status a coverage row may have. */
|
|
32
|
+
export const KIND_STATUSES = ["declared", "referenced", "refused", "out-of-scope"];
|
|
29
33
|
/** Each dialect's coverage table. */
|
|
30
34
|
export const KIND_COVERAGE = {
|
|
31
35
|
postgres: postgresKinds.kinds,
|
|
@@ -47,7 +51,8 @@ export function kindRow(dialect, kind) {
|
|
|
47
51
|
* What is wrong with a dialect's coverage table, against its pinned servers'
|
|
48
52
|
* commands: a command a pinned server has and no row covers, a row for a
|
|
49
53
|
* command no pinned server has, a kind named twice, a declared row with no
|
|
50
|
-
* entity, a refused or out-of-scope row with no reason. Empty
|
|
54
|
+
* entity, a referenced, refused or out-of-scope row with no reason. Empty
|
|
55
|
+
* when complete.
|
|
51
56
|
*/
|
|
52
57
|
export function kindCoverageProblems(dialect, opts = {}) {
|
|
53
58
|
const rows = opts.rows ?? KIND_COVERAGE[dialect];
|
|
@@ -68,8 +73,8 @@ export function kindCoverageProblems(dialect, opts = {}) {
|
|
|
68
73
|
if (seen.has(r.kind))
|
|
69
74
|
problems.push(`the kind "${r.kind}" has two rows`);
|
|
70
75
|
seen.add(r.kind);
|
|
71
|
-
if (!
|
|
72
|
-
problems.push(`${r.kind}: status "${r.status}" is not
|
|
76
|
+
if (!KIND_STATUSES.includes(r.status))
|
|
77
|
+
problems.push(`${r.kind}: status "${r.status}" is not ${KIND_STATUSES.slice(0, -1).join(", ")} or ${KIND_STATUSES.at(-1)}`);
|
|
73
78
|
if (r.status === "declared" && !r.entity)
|
|
74
79
|
problems.push(`${r.kind} is declared, and names no entity type`);
|
|
75
80
|
if (r.status !== "declared" && !r.reason)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant sql drizzle [--output <path>] [--check] [--bigint number|bigint]`
|
|
3
|
+
* (#4401): build the project the way `chant build` does, folded, and write the
|
|
4
|
+
* Drizzle schema module {@link renderDrizzle} renders from its entities.
|
|
5
|
+
*
|
|
6
|
+
* The file goes to `<project>/drizzle-schema.ts` by default, outside the
|
|
7
|
+
* source directory the build reads, and starts with chant's generated-file
|
|
8
|
+
* marker either way. `-o` and `--output` put it elsewhere, which is also the
|
|
9
|
+
* flag a workspace `generated` entry's generator passes. `--check` renders the
|
|
10
|
+
* same text and compares it with the file instead of writing it: exit 1,
|
|
11
|
+
* naming the file, when they differ.
|
|
12
|
+
*/
|
|
13
|
+
import type { CommandGroupContext } from "@intentius/chant/cli/command-group";
|
|
14
|
+
/** The file `chant sql drizzle` writes by default, in the project directory. */
|
|
15
|
+
export declare const DRIZZLE_SCHEMA_FILE = "drizzle-schema.ts";
|
|
16
|
+
export declare function runDrizzle(ctx: CommandGroupContext): Promise<number>;
|
|
17
|
+
//# sourceMappingURL=drizzle-command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle-command.d.ts","sourceRoot":"","sources":["../src/drizzle-command.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAI9E,gFAAgF;AAChF,eAAO,MAAM,mBAAmB,sBAAsB,CAAC;AA6BvD,wBAAsB,UAAU,CAAC,GAAG,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,CA4C1E"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant sql drizzle [--output <path>] [--check] [--bigint number|bigint]`
|
|
3
|
+
* (#4401): build the project the way `chant build` does, folded, and write the
|
|
4
|
+
* Drizzle schema module {@link renderDrizzle} renders from its entities.
|
|
5
|
+
*
|
|
6
|
+
* The file goes to `<project>/drizzle-schema.ts` by default, outside the
|
|
7
|
+
* source directory the build reads, and starts with chant's generated-file
|
|
8
|
+
* marker either way. `-o` and `--output` put it elsewhere, which is also the
|
|
9
|
+
* flag a workspace `generated` entry's generator passes. `--check` renders the
|
|
10
|
+
* same text and compares it with the file instead of writing it: exit 1,
|
|
11
|
+
* naming the file, when they differ.
|
|
12
|
+
*/
|
|
13
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
14
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
15
|
+
import { DrizzleDialectError, renderDrizzle } from "./drizzle.js";
|
|
16
|
+
import { buildFolded, loadProject } from "./sql-types-command.js";
|
|
17
|
+
/** The file `chant sql drizzle` writes by default, in the project directory. */
|
|
18
|
+
export const DRIZZLE_SCHEMA_FILE = "drizzle-schema.ts";
|
|
19
|
+
const USAGE = "usage: chant sql drizzle [--output <path>] [--check] [--bigint number|bigint]";
|
|
20
|
+
function parseArgs(args) {
|
|
21
|
+
const out = { check: false };
|
|
22
|
+
for (let i = 0; i < args.length; i++) {
|
|
23
|
+
const a = args[i];
|
|
24
|
+
if (a === "--output" || a === "-o") {
|
|
25
|
+
const v = args[++i];
|
|
26
|
+
if (!v)
|
|
27
|
+
return { error: `${a} needs a path` };
|
|
28
|
+
out.output = v;
|
|
29
|
+
}
|
|
30
|
+
else if (a.startsWith("--output="))
|
|
31
|
+
out.output = a.slice("--output=".length);
|
|
32
|
+
else if (a === "--check")
|
|
33
|
+
out.check = true;
|
|
34
|
+
else if (a === "--bigint" || a.startsWith("--bigint=")) {
|
|
35
|
+
const v = a === "--bigint" ? args[++i] : a.slice("--bigint=".length);
|
|
36
|
+
if (v !== "number" && v !== "bigint")
|
|
37
|
+
return { error: "--bigint takes number or bigint" };
|
|
38
|
+
out.bigint = v;
|
|
39
|
+
}
|
|
40
|
+
else
|
|
41
|
+
return { error: `unknown argument ${a}` };
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
export async function runDrizzle(ctx) {
|
|
46
|
+
const args = parseArgs(ctx.rawArgs);
|
|
47
|
+
if ("error" in args) {
|
|
48
|
+
console.error(`${args.error}\n${USAGE}`);
|
|
49
|
+
return 1;
|
|
50
|
+
}
|
|
51
|
+
const cwd = process.cwd();
|
|
52
|
+
const project = await loadProject(cwd);
|
|
53
|
+
const output = args.output !== undefined ? resolve(cwd, args.output) : join(project.projectDir, DRIZZLE_SCHEMA_FILE);
|
|
54
|
+
const result = await buildFolded(project, "chant sql drizzle", "nothing was written");
|
|
55
|
+
if (!result)
|
|
56
|
+
return 1;
|
|
57
|
+
let rendered;
|
|
58
|
+
try {
|
|
59
|
+
rendered = renderDrizzle(result.entities, { config: project.config, ...(args.bigint ? { bigintMode: args.bigint } : {}) });
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
if (!(err instanceof DrizzleDialectError))
|
|
63
|
+
throw err;
|
|
64
|
+
console.error(`chant sql drizzle: ${err.message}`);
|
|
65
|
+
return 1;
|
|
66
|
+
}
|
|
67
|
+
const shown = relative(cwd, output);
|
|
68
|
+
const named = shown && !shown.startsWith("..") ? shown : output;
|
|
69
|
+
if (args.check) {
|
|
70
|
+
// Compares only; the file is never written.
|
|
71
|
+
const onDisk = existsSync(output) ? readFileSync(output, "utf8") : undefined;
|
|
72
|
+
if (onDisk === rendered.text) {
|
|
73
|
+
console.log(`${named} is current`);
|
|
74
|
+
return 0;
|
|
75
|
+
}
|
|
76
|
+
console.error(onDisk === undefined
|
|
77
|
+
? `chant sql drizzle: ${named} does not exist; run \`chant sql drizzle\` to write it`
|
|
78
|
+
: `chant sql drizzle: ${named} differs from what the build declares; run \`chant sql drizzle\` to rewrite it`);
|
|
79
|
+
return 1;
|
|
80
|
+
}
|
|
81
|
+
mkdirSync(dirname(output), { recursive: true });
|
|
82
|
+
writeFileSync(output, rendered.text);
|
|
83
|
+
const { tables, views, enums, sequences } = rendered.counts;
|
|
84
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
85
|
+
console.log(`wrote ${named}: ${[plural(tables, "table"), plural(views, "view"), plural(enums, "enum"), plural(sequences, "sequence")].join(", ")}`);
|
|
86
|
+
for (const s of rendered.skipped)
|
|
87
|
+
console.log(`not written: ${s.kind} ${s.names.join(", ")} (${s.reason})`);
|
|
88
|
+
for (const n of rendered.approximated)
|
|
89
|
+
console.log(`partly written: ${n}`);
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Drizzle schema module `chant sql drizzle` writes (#4401): a Postgres
|
|
3
|
+
* build's tables, enums, sequences and views as `drizzle-orm/pg-core`
|
|
4
|
+
* declarations, so an application queries with Drizzle's row types while
|
|
5
|
+
* chant owns the schema, the plan and the apply.
|
|
6
|
+
*
|
|
7
|
+
* {@link renderDrizzle} is pure: the entities of a build in, the module's
|
|
8
|
+
* text and a list of what it left out. It reads the objects as the
|
|
9
|
+
* serializer writes them, as `sql-types.ts` does, so a `.sql` file's objects
|
|
10
|
+
* and a composite's members are covered as the build covers them.
|
|
11
|
+
*
|
|
12
|
+
* The API it writes is drizzle-orm {@link DRIZZLE_ORM_CHECKED}'s `pg-core`
|
|
13
|
+
* (type definitions read from the published package):
|
|
14
|
+
*
|
|
15
|
+
* - `pgTable(name, columns, (t) => [...])`, or `pgSchema(name).table(...)`
|
|
16
|
+
* for a schema other than `public` (`pgSchema("public")` throws);
|
|
17
|
+
* - column builders, `.notNull()`, `.default()`, `.primaryKey()`,
|
|
18
|
+
* `.generatedAlwaysAsIdentity()`, `.generatedAlwaysAs()`, `.array()`;
|
|
19
|
+
* - `foreignKey({ name, columns, foreignColumns })` with `.onDelete()` and
|
|
20
|
+
* `.onUpdate()`, `unique(name).on()`, `check(name, sql)`,
|
|
21
|
+
* `index(name).on()`, `uniqueIndex(name).on()`;
|
|
22
|
+
* - `pgEnum`, `pgSequence`, and `pgView(name, columns).existing()`;
|
|
23
|
+
* - `customType` for a column type Drizzle has no builder for.
|
|
24
|
+
*
|
|
25
|
+
* Each column key is the column's name in the database, so a row has the
|
|
26
|
+
* keys `RowOf` has. Every constraint and index carries the name Postgres
|
|
27
|
+
* would give it (`./postgres/constraint-names.ts`) when the DDL names none,
|
|
28
|
+
* so `drizzle-kit` compares equal names.
|
|
29
|
+
*
|
|
30
|
+
* Foreign keys use `foreignKey()` and not a column's `.references()`: the
|
|
31
|
+
* latter takes no name, and Drizzle derives `orders_user_id_users_id_fk`
|
|
32
|
+
* where Postgres says `orders_user_id_fkey`.
|
|
33
|
+
*
|
|
34
|
+
* Views are `.existing()`: chant creates them, and `drizzle-kit` must not.
|
|
35
|
+
*/
|
|
36
|
+
import type { Declarable } from "@intentius/chant/declarable";
|
|
37
|
+
/** The drizzle-orm version whose type definitions the output was written against. */
|
|
38
|
+
export declare const DRIZZLE_ORM_CHECKED = "0.45.4";
|
|
39
|
+
export interface RenderDrizzleOptions {
|
|
40
|
+
/** The project's config: `sql.postgresMajor` for the catalog, `sql.dialect` when nothing is declared. */
|
|
41
|
+
config?: Record<string, unknown>;
|
|
42
|
+
/** How a `bigint` column reads: Drizzle's `number` (the default, as `drizzle-kit pull` writes it) or `bigint`. */
|
|
43
|
+
bigintMode?: "number" | "bigint";
|
|
44
|
+
}
|
|
45
|
+
export interface DrizzleRender {
|
|
46
|
+
text: string;
|
|
47
|
+
/** Objects with no Drizzle declaration, by kind. */
|
|
48
|
+
skipped: Array<{
|
|
49
|
+
kind: string;
|
|
50
|
+
names: string[];
|
|
51
|
+
reason: string;
|
|
52
|
+
}>;
|
|
53
|
+
/** Parts of a mapped object that Drizzle cannot say: `app.orders: ...`. */
|
|
54
|
+
approximated: string[];
|
|
55
|
+
counts: {
|
|
56
|
+
tables: number;
|
|
57
|
+
views: number;
|
|
58
|
+
enums: number;
|
|
59
|
+
sequences: number;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** Thrown for a build that is not Postgres. */
|
|
63
|
+
export declare class DrizzleDialectError extends Error {
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The Drizzle schema module for a build's entities. Throws
|
|
67
|
+
* {@link DrizzleDialectError} when the build is not Postgres.
|
|
68
|
+
*/
|
|
69
|
+
export declare function renderDrizzle(entities: ReadonlyMap<string, Declarable>, opts?: RenderDrizzleOptions): DrizzleRender;
|
|
70
|
+
//# sourceMappingURL=drizzle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle.d.ts","sourceRoot":"","sources":["../src/drizzle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAU9D,qFAAqF;AACrF,eAAO,MAAM,mBAAmB,WAAW,CAAC;AAE5C,MAAM,WAAW,oBAAoB;IACnC,yGAAyG;IACzG,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,kHAAkH;IAClH,UAAU,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;CAClC;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,EAAE,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAClE,2EAA2E;IAC3E,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7E;AAED,+CAA+C;AAC/C,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AA2SjD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,IAAI,GAAE,oBAAyB,GAAG,aAAa,CAyUvH"}
|