@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,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Postgres to ClickHouse type map (#4399).
|
|
3
|
+
*
|
|
4
|
+
* A type either maps with no judgment (`note` absent) or carries a `note`
|
|
5
|
+
* naming what the map could not keep. Only the first kind is mechanical: the
|
|
6
|
+
* translator writes no diagnostic for it. A type this file does not know (an
|
|
7
|
+
* enum, a domain, an extension type) maps to `String` with a note, because a
|
|
8
|
+
* mirror still has to hold the value.
|
|
9
|
+
*
|
|
10
|
+
* Source types and defaults are from the Postgres data types chapter
|
|
11
|
+
* (https://www.postgresql.org/docs/current/datatype.html): `timestamp` and
|
|
12
|
+
* `time` take a precision of 0 to 6 and default to microseconds, `numeric`
|
|
13
|
+
* with no precision holds any value, `money` is a fixed-point type with a
|
|
14
|
+
* locale-set scale, `float(n)` is `real` for n up to 24 and `double
|
|
15
|
+
* precision` above.
|
|
16
|
+
*
|
|
17
|
+
* Target types are ClickHouse types of the pinned server (`../../spec/pin.ts`);
|
|
18
|
+
* `types.test.ts` checks every family this file writes against the generated
|
|
19
|
+
* catalog.
|
|
20
|
+
*/
|
|
21
|
+
/** Split a column type as written into its words, its parenthesised arguments and its array dimensions. */
|
|
22
|
+
export function parseType(text) {
|
|
23
|
+
let rest = text.trim();
|
|
24
|
+
let dims = 0;
|
|
25
|
+
for (;;) {
|
|
26
|
+
const m = /\s*\[\s*\d*\s*\]\s*$/.exec(rest);
|
|
27
|
+
if (!m)
|
|
28
|
+
break;
|
|
29
|
+
rest = rest.slice(0, m.index);
|
|
30
|
+
dims++;
|
|
31
|
+
}
|
|
32
|
+
const arrayWord = /\s+array(\s*\[\s*\d*\s*\])?$/i.exec(rest);
|
|
33
|
+
if (arrayWord) {
|
|
34
|
+
rest = rest.slice(0, arrayWord.index);
|
|
35
|
+
dims++;
|
|
36
|
+
}
|
|
37
|
+
const args = [];
|
|
38
|
+
rest = rest.replace(/\(([^)]*)\)/g, (_all, inner) => {
|
|
39
|
+
for (const part of inner.split(",")) {
|
|
40
|
+
const n = Number(part.trim());
|
|
41
|
+
if (Number.isFinite(n))
|
|
42
|
+
args.push(n);
|
|
43
|
+
}
|
|
44
|
+
return " ";
|
|
45
|
+
});
|
|
46
|
+
const base = rest
|
|
47
|
+
.replace(/"/g, "")
|
|
48
|
+
.replace(/^pg_catalog\./i, "")
|
|
49
|
+
.replace(/\s+/g, " ")
|
|
50
|
+
.trim()
|
|
51
|
+
.toLowerCase();
|
|
52
|
+
return { base, args, dims, raw: text.trim() };
|
|
53
|
+
}
|
|
54
|
+
const STRING_NOTE = (what, evidence) => ({ message: `${what} is read as String.`, evidence });
|
|
55
|
+
function mapScalar(t) {
|
|
56
|
+
const { base, args } = t;
|
|
57
|
+
switch (base) {
|
|
58
|
+
case "smallint":
|
|
59
|
+
case "int2":
|
|
60
|
+
return { ok: true, type: "Int16" };
|
|
61
|
+
case "integer":
|
|
62
|
+
case "int":
|
|
63
|
+
case "int4":
|
|
64
|
+
return { ok: true, type: "Int32" };
|
|
65
|
+
case "bigint":
|
|
66
|
+
case "int8":
|
|
67
|
+
return { ok: true, type: "Int64" };
|
|
68
|
+
case "smallserial":
|
|
69
|
+
case "serial2":
|
|
70
|
+
return { ok: true, type: "Int16", serial: true };
|
|
71
|
+
case "serial":
|
|
72
|
+
case "serial4":
|
|
73
|
+
return { ok: true, type: "Int32", serial: true };
|
|
74
|
+
case "bigserial":
|
|
75
|
+
case "serial8":
|
|
76
|
+
return { ok: true, type: "Int64", serial: true };
|
|
77
|
+
case "real":
|
|
78
|
+
case "float4":
|
|
79
|
+
return { ok: true, type: "Float32" };
|
|
80
|
+
case "double precision":
|
|
81
|
+
case "float8":
|
|
82
|
+
return { ok: true, type: "Float64" };
|
|
83
|
+
case "float":
|
|
84
|
+
return { ok: true, type: (args[0] ?? 53) <= 24 ? "Float32" : "Float64" };
|
|
85
|
+
case "numeric":
|
|
86
|
+
case "decimal": {
|
|
87
|
+
if (args.length === 0) {
|
|
88
|
+
return {
|
|
89
|
+
ok: true,
|
|
90
|
+
type: "Decimal(38, 18)",
|
|
91
|
+
note: {
|
|
92
|
+
message: "numeric with no precision is read as Decimal(38, 18).",
|
|
93
|
+
evidence: ["Postgres stores up to 131072 digits before the point and 16383 after; a ClickHouse Decimal has a fixed precision and scale", "a value that does not fit fails the insert"],
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const p = args[0];
|
|
98
|
+
const s = args[1] ?? 0;
|
|
99
|
+
if (p > 76 || s < 0 || s > p) {
|
|
100
|
+
return {
|
|
101
|
+
ok: true,
|
|
102
|
+
type: "Decimal(76, 38)",
|
|
103
|
+
note: { message: `numeric(${String(p)}, ${String(s)}) is read as Decimal(76, 38).`, evidence: ["ClickHouse Decimal holds at most 76 digits"] },
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return { ok: true, type: `Decimal(${String(p)}, ${String(s)})` };
|
|
107
|
+
}
|
|
108
|
+
case "money":
|
|
109
|
+
return {
|
|
110
|
+
ok: true,
|
|
111
|
+
type: "Decimal(19, 2)",
|
|
112
|
+
note: { message: "money is read as Decimal(19, 2).", evidence: ["money takes its scale from the lc_monetary setting of the source server, and two decimals is the common one"] },
|
|
113
|
+
};
|
|
114
|
+
case "boolean":
|
|
115
|
+
case "bool":
|
|
116
|
+
return { ok: true, type: "Bool" };
|
|
117
|
+
case "text":
|
|
118
|
+
case "varchar":
|
|
119
|
+
case "character varying":
|
|
120
|
+
case "name":
|
|
121
|
+
case "citext":
|
|
122
|
+
return { ok: true, type: "String", ...(args[0] !== undefined ? { maxLength: args[0] } : {}) };
|
|
123
|
+
case "char":
|
|
124
|
+
case "character":
|
|
125
|
+
case "bpchar":
|
|
126
|
+
return {
|
|
127
|
+
ok: true,
|
|
128
|
+
type: "String",
|
|
129
|
+
...(args[0] !== undefined ? { maxLength: args[0] } : {}),
|
|
130
|
+
...(args[0] !== undefined && args[0] > 1 ? { note: STRING_NOTE("char(n)", ["Postgres pads a char(n) value with spaces to n characters; a String keeps the value as it is loaded"]) } : {}),
|
|
131
|
+
};
|
|
132
|
+
case "bytea":
|
|
133
|
+
return { ok: true, type: "String" };
|
|
134
|
+
case "uuid":
|
|
135
|
+
return { ok: true, type: "UUID" };
|
|
136
|
+
case "date":
|
|
137
|
+
return { ok: true, type: "Date32" };
|
|
138
|
+
case "time":
|
|
139
|
+
case "time without time zone":
|
|
140
|
+
return { ok: true, type: `Time64(${String(args[0] ?? 6)})` };
|
|
141
|
+
case "timetz":
|
|
142
|
+
case "time with time zone":
|
|
143
|
+
return { ok: true, type: "String", note: STRING_NOTE("timetz", ["a time of day with an offset has no ClickHouse type; the offset is kept in the text"]) };
|
|
144
|
+
case "timestamp":
|
|
145
|
+
case "timestamp without time zone":
|
|
146
|
+
return { ok: true, type: `DateTime64(${String(args[0] ?? 6)})` };
|
|
147
|
+
case "timestamptz":
|
|
148
|
+
case "timestamp with time zone":
|
|
149
|
+
return { ok: true, type: `DateTime64(${String(args[0] ?? 6)}, 'UTC')` };
|
|
150
|
+
case "interval":
|
|
151
|
+
return { ok: true, type: "String", note: STRING_NOTE("interval", ["a ClickHouse Interval type cannot be stored in a column", "the value is kept as Postgres prints it"]) };
|
|
152
|
+
case "json":
|
|
153
|
+
case "jsonb":
|
|
154
|
+
return { ok: true, type: "JSON" };
|
|
155
|
+
case "oid":
|
|
156
|
+
return { ok: true, type: "UInt32" };
|
|
157
|
+
case "inet":
|
|
158
|
+
case "cidr":
|
|
159
|
+
return {
|
|
160
|
+
ok: true,
|
|
161
|
+
type: "IPv6",
|
|
162
|
+
note: { message: `${base} is read as IPv6.`, evidence: ["an IPv6 column holds an IPv4 address in its mapped form", "the prefix length of a network is not kept"] },
|
|
163
|
+
};
|
|
164
|
+
case "xml":
|
|
165
|
+
case "macaddr":
|
|
166
|
+
case "macaddr8":
|
|
167
|
+
case "tsvector":
|
|
168
|
+
case "tsquery":
|
|
169
|
+
case "bit":
|
|
170
|
+
case "bit varying":
|
|
171
|
+
case "varbit":
|
|
172
|
+
case "point":
|
|
173
|
+
case "line":
|
|
174
|
+
case "lseg":
|
|
175
|
+
case "box":
|
|
176
|
+
case "path":
|
|
177
|
+
case "polygon":
|
|
178
|
+
case "circle":
|
|
179
|
+
return { ok: true, type: "String", note: STRING_NOTE(base, [`ClickHouse has no ${base} type`, "the value is kept as Postgres prints it"]) };
|
|
180
|
+
default:
|
|
181
|
+
return {
|
|
182
|
+
ok: true,
|
|
183
|
+
type: "String",
|
|
184
|
+
note: STRING_NOTE(t.raw, [`${t.raw} is not a built-in type chant maps (an enum, a domain, a composite or an extension type)`, "the value is kept as Postgres prints it; an enum could be an Enum8 or Enum16 once its labels are settled"]),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/** Map a column type as the declaration wrote it. */
|
|
189
|
+
export function mapPostgresType(text) {
|
|
190
|
+
const t = parseType(text);
|
|
191
|
+
const inner = mapScalar(t);
|
|
192
|
+
if (t.dims === 0)
|
|
193
|
+
return inner;
|
|
194
|
+
let type = inner.type;
|
|
195
|
+
for (let i = 0; i < t.dims; i++)
|
|
196
|
+
type = `Array(${type})`;
|
|
197
|
+
return {
|
|
198
|
+
ok: true,
|
|
199
|
+
type,
|
|
200
|
+
array: true,
|
|
201
|
+
...(inner.serial ? { serial: true } : {}),
|
|
202
|
+
note: {
|
|
203
|
+
message: `${t.raw} is read as ${type}.`,
|
|
204
|
+
evidence: [
|
|
205
|
+
...(inner.note ? [inner.note.message] : []),
|
|
206
|
+
"ClickHouse cannot make an Array Nullable, so a NULL array is stored as an empty one",
|
|
207
|
+
"Postgres does not enforce the declared dimensions or lengths of an array",
|
|
208
|
+
],
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classify the migration files a pull request adds (#4407), the lexicon's
|
|
3
|
+
* answer to core's `classifyMigrations` hook. The "check" adoption level:
|
|
4
|
+
* each new file's up statements are read and given the class the schema-diff
|
|
5
|
+
* classifier gives the same change, and nothing else happens. No server is
|
|
6
|
+
* contacted, no migration tool runs and nothing is applied, so it needs no
|
|
7
|
+
* environment binding (compare `chant sql replay`, which does).
|
|
8
|
+
*
|
|
9
|
+
* The up statements are the ones replay would run: goose's `-- +goose Up`
|
|
10
|
+
* section, the whole file for golang-migrate and clickhouse-migrations, and a
|
|
11
|
+
* Flyway file after placeholder substitution with the configuration's values.
|
|
12
|
+
*/
|
|
13
|
+
import type { MigrationFileClassification } from "@intentius/chant/pr-migrations";
|
|
14
|
+
import type { WorkspaceTree } from "@intentius/chant/workspace/tree";
|
|
15
|
+
export declare const MIGRATION_DIALECTS: readonly ["postgres", "clickhouse"];
|
|
16
|
+
export declare function classifyMigrationFiles(options: {
|
|
17
|
+
reader: string;
|
|
18
|
+
dialect: string;
|
|
19
|
+
tree: WorkspaceTree;
|
|
20
|
+
dir: string;
|
|
21
|
+
files: string[];
|
|
22
|
+
}): MigrationFileClassification[];
|
|
23
|
+
//# sourceMappingURL=migration-classify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-classify.d.ts","sourceRoot":"","sources":["../src/migration-classify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAElF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAKrE,eAAO,MAAM,kBAAkB,qCAAsC,CAAC;AAKtE,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,aAAa,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG,2BAA2B,EAAE,CAmBrK"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classify the migration files a pull request adds (#4407), the lexicon's
|
|
3
|
+
* answer to core's `classifyMigrations` hook. The "check" adoption level:
|
|
4
|
+
* each new file's up statements are read and given the class the schema-diff
|
|
5
|
+
* classifier gives the same change, and nothing else happens. No server is
|
|
6
|
+
* contacted, no migration tool runs and nothing is applied, so it needs no
|
|
7
|
+
* environment binding (compare `chant sql replay`, which does).
|
|
8
|
+
*
|
|
9
|
+
* The up statements are the ones replay would run: goose's `-- +goose Up`
|
|
10
|
+
* section, the whole file for golang-migrate and clickhouse-migrations, and a
|
|
11
|
+
* Flyway file after placeholder substitution with the configuration's values.
|
|
12
|
+
*/
|
|
13
|
+
import { findFlywayConfig, readFlywayConfig, substitute } from "@intentius/chant/workspace/flyway-layout";
|
|
14
|
+
import { classifyClickHouseStatements } from "./clickhouse/plan/statements.js";
|
|
15
|
+
import { gooseUpStatements, splitStatements } from "./migration-replay.js";
|
|
16
|
+
import { classifyPgStatements } from "./postgres/plan/statements.js";
|
|
17
|
+
export const MIGRATION_DIALECTS = ["postgres", "clickhouse"];
|
|
18
|
+
/** The reader names whose files this lexicon reads. */
|
|
19
|
+
const READERS = new Set(["goose-dir", "golang-migrate-dir", "clickhouse-migrations-dir", "flyway-dir"]);
|
|
20
|
+
export function classifyMigrationFiles(options) {
|
|
21
|
+
const { reader, dialect, tree, dir, files } = options;
|
|
22
|
+
if (!READERS.has(reader) || !MIGRATION_DIALECTS.includes(dialect))
|
|
23
|
+
return [];
|
|
24
|
+
const classify = dialect === "postgres" ? classifyPgStatements : classifyClickHouseStatements;
|
|
25
|
+
let flyway;
|
|
26
|
+
return files.map((file) => {
|
|
27
|
+
try {
|
|
28
|
+
const text = tree.read(file);
|
|
29
|
+
let statements;
|
|
30
|
+
if (reader === "goose-dir")
|
|
31
|
+
statements = gooseUpStatements(text);
|
|
32
|
+
else if (reader === "flyway-dir") {
|
|
33
|
+
flyway ?? (flyway = readFlywayConfig(tree, findFlywayConfig(tree, dir), dir));
|
|
34
|
+
statements = splitStatements(substitute(text, file, flyway));
|
|
35
|
+
}
|
|
36
|
+
else
|
|
37
|
+
statements = splitStatements(text);
|
|
38
|
+
return { file, statements: classify(statements) };
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
return { file, statements: [], error: err instanceof Error ? err.message : String(err) };
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replay a migration directory into an empty server and read the catalog
|
|
3
|
+
* (#4400). The workspace kinds for goose, golang-migrate,
|
|
4
|
+
* clickhouse-migrations and Flyway list a directory's migrations without
|
|
5
|
+
* running anything (`packages/core/src/workspace/migration-dirs.ts`); the
|
|
6
|
+
* tables and columns they produce come from here.
|
|
7
|
+
*
|
|
8
|
+
* chant sql replay <dir> --kind <kind> --env <env> [--dir-field migrationsDir=<sub>] [--check]
|
|
9
|
+
*
|
|
10
|
+
* The replay applies each migration's up statements in the order the kind's
|
|
11
|
+
* reader lists them, then reads the tables, views and columns the server has
|
|
12
|
+
* and writes them as `chant.replay.json` beside the migrations, named by the
|
|
13
|
+
* contract of #3931: `<schema>.<table>` and `<schema>.<table>.<column>` for
|
|
14
|
+
* Postgres, `<database>.<table>` and `<database>.<table>.<column>` for
|
|
15
|
+
* ClickHouse. The file also holds a digest of the files it ran, so the
|
|
16
|
+
* reader knows when a migration changed after it. `--check` replays and
|
|
17
|
+
* compares instead of writing, exiting 1 when the file differs, the way
|
|
18
|
+
* `chant sql types --check` does.
|
|
19
|
+
*
|
|
20
|
+
* What it runs per kind:
|
|
21
|
+
* - goose: the `-- +goose Up` section of each file; `StatementBegin` to
|
|
22
|
+
* `StatementEnd` is one statement.
|
|
23
|
+
* - golang-migrate and clickhouse-migrations: the whole up file.
|
|
24
|
+
* - Flyway: the SQL files of the locations, versioned in version order and
|
|
25
|
+
* then repeatable ones, with placeholders substituted. Baseline and undo
|
|
26
|
+
* files are not run.
|
|
27
|
+
*
|
|
28
|
+
* The server must hold no table, view or column of its own: the replay
|
|
29
|
+
* refuses a server that does, since it cannot tell what the migrations made.
|
|
30
|
+
* It runs the migrations' SQL against the server `--env` binds, so point it
|
|
31
|
+
* at a throwaway server or emulator.
|
|
32
|
+
*/
|
|
33
|
+
import type { CommandGroupContext } from "@intentius/chant/cli/command-group";
|
|
34
|
+
import { type KindReadMigration, type KindReaderInput } from "@intentius/chant/workspace/kind-link-readers";
|
|
35
|
+
import { type ReplaySnapshot } from "@intentius/chant/workspace/migration-dirs";
|
|
36
|
+
import { type WorkspaceTree } from "@intentius/chant/workspace/tree";
|
|
37
|
+
export declare const REPLAY_KINDS: readonly ["goose", "golang-migrate", "clickhouse-migrations", "flyway"];
|
|
38
|
+
export type ReplayKind = (typeof REPLAY_KINDS)[number];
|
|
39
|
+
/** One server the replay runs on. */
|
|
40
|
+
export interface ReplayDb {
|
|
41
|
+
dialect: "postgres" | "clickhouse";
|
|
42
|
+
run(sql: string): Promise<void>;
|
|
43
|
+
rows(sql: string): Promise<Record<string, unknown>[]>;
|
|
44
|
+
close(): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Split SQL text into statements at `;`. Single-quoted strings, quoted
|
|
48
|
+
* identifiers, `--` and `/* *\/` comments and Postgres dollar-quoted bodies
|
|
49
|
+
* hold semicolons without ending the statement. A statement of only
|
|
50
|
+
* comments is dropped.
|
|
51
|
+
*/
|
|
52
|
+
export declare function splitStatements(text: string): string[];
|
|
53
|
+
/** goose's Up statements: the lines between `-- +goose Up` and `-- +goose Down`; a StatementBegin to StatementEnd block is one statement. */
|
|
54
|
+
export declare function gooseUpStatements(text: string): string[];
|
|
55
|
+
export interface ReplayStep {
|
|
56
|
+
migration: KindReadMigration;
|
|
57
|
+
statements: string[];
|
|
58
|
+
}
|
|
59
|
+
/** The statements to run, per migration, in order. Throws when a Flyway placeholder has no value. */
|
|
60
|
+
export declare function replaySteps(kind: ReplayKind, tree: WorkspaceTree, dir: string, fields?: KindReaderInput["fields"]): {
|
|
61
|
+
steps: ReplayStep[];
|
|
62
|
+
files: string[];
|
|
63
|
+
dialect: string;
|
|
64
|
+
};
|
|
65
|
+
/** Apply each migration's statements; a failure names the migration file and the statement. */
|
|
66
|
+
export declare function applySteps(db: ReplayDb, steps: readonly ReplayStep[]): Promise<void>;
|
|
67
|
+
/** The tables, views and columns the server has, as workspace output names (#3931). */
|
|
68
|
+
export declare function readCatalogOutputs(db: ReplayDb): Promise<string[]>;
|
|
69
|
+
/** Replay a directory into `db`, which must hold nothing, and return the snapshot to record. */
|
|
70
|
+
export declare function replayDirectory(db: ReplayDb, kind: ReplayKind, tree: WorkspaceTree, dir: string, fields?: KindReaderInput["fields"]): Promise<ReplaySnapshot>;
|
|
71
|
+
export declare const renderSnapshot: (s: ReplaySnapshot) => string;
|
|
72
|
+
export declare function runReplay(ctx: CommandGroupContext): Promise<number>;
|
|
73
|
+
//# sourceMappingURL=migration-replay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-replay.d.ts","sourceRoot":"","sources":["../src/migration-replay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAIH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EAAgB,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAE,MAAM,8CAA8C,CAAC;AAC1H,OAAO,EAA6C,KAAK,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAE3H,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAElF,eAAO,MAAM,YAAY,yEAA0E,CAAC;AACpG,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAIvD,qCAAqC;AACrC,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,UAAU,GAAG,YAAY,CAAC;IACnC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IACtD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAyCtD;AAED,6IAA6I;AAC7I,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CA8BxD;AAED,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,iBAAiB,CAAC;IAC7B,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,qGAAqG;AACrG,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,eAAe,CAAC,QAAQ,CAAQ,GAAG;IAAE,KAAK,EAAE,UAAU,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAWnL;AAED,+FAA+F;AAC/F,wBAAsB,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAU1F;AAoBD,uFAAuF;AACvF,wBAAsB,kBAAkB,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAaxE;AAED,gGAAgG;AAChG,wBAAsB,eAAe,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,eAAe,CAAC,QAAQ,CAAQ,GAAG,OAAO,CAAC,cAAc,CAAC,CAOzK;AAED,eAAO,MAAM,cAAc,GAAI,GAAG,cAAc,KAAG,MAA2C,CAAC;AAiB/F,wBAAsB,SAAS,CAAC,GAAG,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,CA2DzE"}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replay a migration directory into an empty server and read the catalog
|
|
3
|
+
* (#4400). The workspace kinds for goose, golang-migrate,
|
|
4
|
+
* clickhouse-migrations and Flyway list a directory's migrations without
|
|
5
|
+
* running anything (`packages/core/src/workspace/migration-dirs.ts`); the
|
|
6
|
+
* tables and columns they produce come from here.
|
|
7
|
+
*
|
|
8
|
+
* chant sql replay <dir> --kind <kind> --env <env> [--dir-field migrationsDir=<sub>] [--check]
|
|
9
|
+
*
|
|
10
|
+
* The replay applies each migration's up statements in the order the kind's
|
|
11
|
+
* reader lists them, then reads the tables, views and columns the server has
|
|
12
|
+
* and writes them as `chant.replay.json` beside the migrations, named by the
|
|
13
|
+
* contract of #3931: `<schema>.<table>` and `<schema>.<table>.<column>` for
|
|
14
|
+
* Postgres, `<database>.<table>` and `<database>.<table>.<column>` for
|
|
15
|
+
* ClickHouse. The file also holds a digest of the files it ran, so the
|
|
16
|
+
* reader knows when a migration changed after it. `--check` replays and
|
|
17
|
+
* compares instead of writing, exiting 1 when the file differs, the way
|
|
18
|
+
* `chant sql types --check` does.
|
|
19
|
+
*
|
|
20
|
+
* What it runs per kind:
|
|
21
|
+
* - goose: the `-- +goose Up` section of each file; `StatementBegin` to
|
|
22
|
+
* `StatementEnd` is one statement.
|
|
23
|
+
* - golang-migrate and clickhouse-migrations: the whole up file.
|
|
24
|
+
* - Flyway: the SQL files of the locations, versioned in version order and
|
|
25
|
+
* then repeatable ones, with placeholders substituted. Baseline and undo
|
|
26
|
+
* files are not run.
|
|
27
|
+
*
|
|
28
|
+
* The server must hold no table, view or column of its own: the replay
|
|
29
|
+
* refuses a server that does, since it cannot tell what the migrations made.
|
|
30
|
+
* It runs the migrations' SQL against the server `--env` binds, so point it
|
|
31
|
+
* at a throwaway server or emulator.
|
|
32
|
+
*/
|
|
33
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
34
|
+
import { join, relative, resolve } from "node:path";
|
|
35
|
+
import { LINK_READERS } from "@intentius/chant/workspace/kind-link-readers";
|
|
36
|
+
import { migrationDigest, REPLAY_FILE, replayFiles } from "@intentius/chant/workspace/migration-dirs";
|
|
37
|
+
import { findFlywayConfig, readFlywayConfig, substitute } from "@intentius/chant/workspace/flyway-layout";
|
|
38
|
+
import { workingTree } from "@intentius/chant/workspace/tree";
|
|
39
|
+
export const REPLAY_KINDS = ["goose", "golang-migrate", "clickhouse-migrations", "flyway"];
|
|
40
|
+
const READER = { goose: "goose-dir", "golang-migrate": "golang-migrate-dir", "clickhouse-migrations": "clickhouse-migrations-dir", flyway: "flyway-dir" };
|
|
41
|
+
/**
|
|
42
|
+
* Split SQL text into statements at `;`. Single-quoted strings, quoted
|
|
43
|
+
* identifiers, `--` and `/* *\/` comments and Postgres dollar-quoted bodies
|
|
44
|
+
* hold semicolons without ending the statement. A statement of only
|
|
45
|
+
* comments is dropped.
|
|
46
|
+
*/
|
|
47
|
+
export function splitStatements(text) {
|
|
48
|
+
const out = [];
|
|
49
|
+
let start = 0;
|
|
50
|
+
let i = 0;
|
|
51
|
+
const flush = (end) => {
|
|
52
|
+
const s = text.slice(start, end).trim();
|
|
53
|
+
if (s !== "" && s.replace(/--[^\n]*/g, "").replace(/\/\*[\s\S]*?\*\//g, "").trim() !== "")
|
|
54
|
+
out.push(s);
|
|
55
|
+
start = end + 1;
|
|
56
|
+
};
|
|
57
|
+
while (i < text.length) {
|
|
58
|
+
const c = text[i];
|
|
59
|
+
const two = text.slice(i, i + 2);
|
|
60
|
+
if (two === "--") {
|
|
61
|
+
const nl = text.indexOf("\n", i);
|
|
62
|
+
i = nl < 0 ? text.length : nl + 1;
|
|
63
|
+
}
|
|
64
|
+
else if (two === "/*") {
|
|
65
|
+
const end = text.indexOf("*/", i + 2);
|
|
66
|
+
i = end < 0 ? text.length : end + 2;
|
|
67
|
+
}
|
|
68
|
+
else if (c === "'" || c === '"' || c === "`") {
|
|
69
|
+
i++;
|
|
70
|
+
while (i < text.length) {
|
|
71
|
+
if (text[i] === "\\" && c !== '"')
|
|
72
|
+
i += 2;
|
|
73
|
+
else if (text[i] === c) {
|
|
74
|
+
if (text[i + 1] === c)
|
|
75
|
+
i += 2;
|
|
76
|
+
else
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
else
|
|
80
|
+
i++;
|
|
81
|
+
}
|
|
82
|
+
i++;
|
|
83
|
+
}
|
|
84
|
+
else if (c === "$") {
|
|
85
|
+
const tag = /^\$[A-Za-z_]*\$/.exec(text.slice(i))?.[0];
|
|
86
|
+
if (tag) {
|
|
87
|
+
const end = text.indexOf(tag, i + tag.length);
|
|
88
|
+
i = end < 0 ? text.length : end + tag.length;
|
|
89
|
+
}
|
|
90
|
+
else
|
|
91
|
+
i++;
|
|
92
|
+
}
|
|
93
|
+
else if (c === ";") {
|
|
94
|
+
flush(i);
|
|
95
|
+
i++;
|
|
96
|
+
}
|
|
97
|
+
else
|
|
98
|
+
i++;
|
|
99
|
+
}
|
|
100
|
+
flush(text.length);
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
/** goose's Up statements: the lines between `-- +goose Up` and `-- +goose Down`; a StatementBegin to StatementEnd block is one statement. */
|
|
104
|
+
export function gooseUpStatements(text) {
|
|
105
|
+
const out = [];
|
|
106
|
+
let section = "none";
|
|
107
|
+
let block;
|
|
108
|
+
let plain = [];
|
|
109
|
+
const annotation = (l) => {
|
|
110
|
+
const t = l.trim();
|
|
111
|
+
return t.startsWith("--") && t.includes("+goose") ? t.replace("+goose", "").replace(/^--\s*/, "").trim().toLowerCase() : undefined;
|
|
112
|
+
};
|
|
113
|
+
const flushPlain = () => {
|
|
114
|
+
out.push(...splitStatements(plain.join("\n")));
|
|
115
|
+
plain = [];
|
|
116
|
+
};
|
|
117
|
+
for (const line of text.split(/\r?\n/)) {
|
|
118
|
+
const a = annotation(line);
|
|
119
|
+
if (a === "up")
|
|
120
|
+
section = "up";
|
|
121
|
+
else if (a === "down") {
|
|
122
|
+
flushPlain();
|
|
123
|
+
section = "down";
|
|
124
|
+
}
|
|
125
|
+
else if (a === "statementbegin" && section === "up") {
|
|
126
|
+
flushPlain();
|
|
127
|
+
block = [];
|
|
128
|
+
}
|
|
129
|
+
else if (a === "statementend" && section === "up" && block) {
|
|
130
|
+
const s = block.join("\n").trim();
|
|
131
|
+
if (s !== "")
|
|
132
|
+
out.push(s);
|
|
133
|
+
block = undefined;
|
|
134
|
+
}
|
|
135
|
+
else if (section === "up" && a === undefined)
|
|
136
|
+
(block ?? plain).push(line);
|
|
137
|
+
}
|
|
138
|
+
flushPlain();
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
/** The statements to run, per migration, in order. Throws when a Flyway placeholder has no value. */
|
|
142
|
+
export function replaySteps(kind, tree, dir, fields = null) {
|
|
143
|
+
const read = LINK_READERS[READER[kind]]({ member: { name: "replay" }, dir, fields, tree });
|
|
144
|
+
const migrations = (read.migrations ?? []).filter((m) => m.type === "versioned" || m.type === "repeatable");
|
|
145
|
+
const config = kind === "flyway" ? readFlywayConfig(tree, findFlywayConfig(tree, dir), dir) : undefined;
|
|
146
|
+
const steps = migrations.map((migration) => {
|
|
147
|
+
const text = tree.read(migration.file);
|
|
148
|
+
const statements = kind === "goose" ? gooseUpStatements(text) : splitStatements(config ? substitute(text, migration.file, config) : text);
|
|
149
|
+
return { migration, statements };
|
|
150
|
+
});
|
|
151
|
+
const extra = config?.file !== undefined ? [config.file] : [];
|
|
152
|
+
return { steps, files: replayFiles(tree, read.migrations ?? [], extra), dialect: read.migrations?.[0]?.dialect ?? "postgres" };
|
|
153
|
+
}
|
|
154
|
+
/** Apply each migration's statements; a failure names the migration file and the statement. */
|
|
155
|
+
export async function applySteps(db, steps) {
|
|
156
|
+
for (const { migration, statements } of steps) {
|
|
157
|
+
for (const [i, sql] of statements.entries()) {
|
|
158
|
+
try {
|
|
159
|
+
await db.run(sql);
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
throw new Error(`${migration.file}: statement ${String(i + 1)} failed: ${err.message}\n${sql.slice(0, 200)}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const POSTGRES_CATALOG = `
|
|
168
|
+
select n.nspname as schema, c.relname as relation, a.attname as col
|
|
169
|
+
from pg_class c
|
|
170
|
+
join pg_namespace n on n.oid = c.relnamespace
|
|
171
|
+
left join pg_attribute a on a.attrelid = c.oid and a.attnum > 0 and not a.attisdropped
|
|
172
|
+
where c.relkind in ('r', 'p', 'v', 'm', 'f')
|
|
173
|
+
and n.nspname not in ('pg_catalog', 'information_schema')
|
|
174
|
+
and n.nspname not like 'pg\\_toast%' and n.nspname not like 'pg\\_temp%'
|
|
175
|
+
order by 1, 2, a.attnum`;
|
|
176
|
+
const CLICKHOUSE_CATALOG = `
|
|
177
|
+
select t.database as schema, t.name as relation, c.name as col
|
|
178
|
+
from system.tables t
|
|
179
|
+
left join system.columns c on c.database = t.database and c.table = t.name
|
|
180
|
+
where t.database not in ('system', 'INFORMATION_SCHEMA', 'information_schema')
|
|
181
|
+
and t.is_temporary = 0
|
|
182
|
+
order by t.database, t.name, c.position`;
|
|
183
|
+
/** The tables, views and columns the server has, as workspace output names (#3931). */
|
|
184
|
+
export async function readCatalogOutputs(db) {
|
|
185
|
+
const rows = await db.rows(db.dialect === "postgres" ? POSTGRES_CATALOG : CLICKHOUSE_CATALOG);
|
|
186
|
+
const out = [];
|
|
187
|
+
const seen = new Set();
|
|
188
|
+
for (const r of rows) {
|
|
189
|
+
const rel = `${String(r.schema)}.${String(r.relation)}`;
|
|
190
|
+
if (!seen.has(rel)) {
|
|
191
|
+
seen.add(rel);
|
|
192
|
+
out.push(rel);
|
|
193
|
+
}
|
|
194
|
+
if (r.col !== null && r.col !== undefined)
|
|
195
|
+
out.push(`${rel}.${String(r.col)}`);
|
|
196
|
+
}
|
|
197
|
+
return out;
|
|
198
|
+
}
|
|
199
|
+
/** Replay a directory into `db`, which must hold nothing, and return the snapshot to record. */
|
|
200
|
+
export async function replayDirectory(db, kind, tree, dir, fields = null) {
|
|
201
|
+
const before = await readCatalogOutputs(db);
|
|
202
|
+
if (before.length > 0)
|
|
203
|
+
throw new Error(`the server already has ${before[0].split(".").slice(0, 2).join(".")}${before.length > 1 ? ` and ${String(before.length - 1)} more names` : ""}; replay needs a server with no tables or views of its own, so the tables it finds are the migrations' (use a throwaway server or emulator)`);
|
|
204
|
+
const { steps, files, dialect } = replaySteps(kind, tree, dir, fields);
|
|
205
|
+
if (dialect !== db.dialect)
|
|
206
|
+
throw new Error(`the migrations are ${dialect} and the server is ${db.dialect}; set the member's dialect field or bind the matching server`);
|
|
207
|
+
await applySteps(db, steps);
|
|
208
|
+
return { schema: 1, dialect, digest: migrationDigest((f) => tree.read(f), files), outputs: await readCatalogOutputs(db) };
|
|
209
|
+
}
|
|
210
|
+
export const renderSnapshot = (s) => `${JSON.stringify(s, null, 2)}\n`;
|
|
211
|
+
const USAGE = "usage: chant sql replay <dir> --kind goose|golang-migrate|clickhouse-migrations|flyway --env <env> [--migrations-dir <sub>] [--dialect postgres|clickhouse] [--check]";
|
|
212
|
+
/** Open the server `--env` binds, of the migrations' dialect. */
|
|
213
|
+
async function openBound(dialect, environment) {
|
|
214
|
+
if (dialect === "postgres") {
|
|
215
|
+
const { bindPostgres } = await import("./postgres/live/bind.js");
|
|
216
|
+
const { client } = await bindPostgres({ environment });
|
|
217
|
+
return { dialect, run: async (sql) => void (await client.query(sql)), rows: (sql) => client.query(sql), close: () => client.end() };
|
|
218
|
+
}
|
|
219
|
+
const { bindClickHouse } = await import("./clickhouse/live/bind.js");
|
|
220
|
+
const { clickhouseQuery } = await import("./clickhouse/http.js");
|
|
221
|
+
const target = await bindClickHouse({ environment });
|
|
222
|
+
return { dialect, run: async (sql) => void (await clickhouseQuery(target.endpoint, sql)), rows: (sql) => clickhouseQuery(target.endpoint, sql), async close() { } };
|
|
223
|
+
}
|
|
224
|
+
export async function runReplay(ctx) {
|
|
225
|
+
const args = ctx.rawArgs;
|
|
226
|
+
let kind;
|
|
227
|
+
let env;
|
|
228
|
+
let sub;
|
|
229
|
+
let dialect;
|
|
230
|
+
const check = args.includes("--check");
|
|
231
|
+
const positional = [];
|
|
232
|
+
for (let i = 0; i < args.length; i++) {
|
|
233
|
+
const a = args[i];
|
|
234
|
+
if (a === "--kind")
|
|
235
|
+
kind = args[++i];
|
|
236
|
+
else if (a === "--env")
|
|
237
|
+
env = args[++i];
|
|
238
|
+
else if (a === "--migrations-dir")
|
|
239
|
+
sub = args[++i];
|
|
240
|
+
else if (a === "--dialect")
|
|
241
|
+
dialect = args[++i];
|
|
242
|
+
else if (a === "--check")
|
|
243
|
+
continue;
|
|
244
|
+
else if (a.startsWith("--")) {
|
|
245
|
+
console.error(`unknown argument ${a}\n${USAGE}`);
|
|
246
|
+
return 1;
|
|
247
|
+
}
|
|
248
|
+
else
|
|
249
|
+
positional.push(a);
|
|
250
|
+
}
|
|
251
|
+
if (positional.length !== 1 || !kind || !REPLAY_KINDS.includes(kind) || !env) {
|
|
252
|
+
console.error(USAGE);
|
|
253
|
+
return 1;
|
|
254
|
+
}
|
|
255
|
+
const abs = resolve(process.cwd(), positional[0]);
|
|
256
|
+
const tree = workingTree(abs);
|
|
257
|
+
const fields = { ...(sub ? { migrationsDir: sub } : {}), ...(dialect ? { dialect } : {}) };
|
|
258
|
+
const { steps, dialect: found } = replaySteps(kind, tree, "", fields);
|
|
259
|
+
if (steps.length === 0) {
|
|
260
|
+
console.error(`chant sql replay: ${relative(process.cwd(), abs) || "."} lists no ${kind} migrations`);
|
|
261
|
+
return 1;
|
|
262
|
+
}
|
|
263
|
+
const db = await openBound(found, env);
|
|
264
|
+
let snapshot;
|
|
265
|
+
try {
|
|
266
|
+
snapshot = await replayDirectory(db, kind, tree, "", fields);
|
|
267
|
+
}
|
|
268
|
+
catch (err) {
|
|
269
|
+
console.error(`chant sql replay: ${err.message}`);
|
|
270
|
+
return 1;
|
|
271
|
+
}
|
|
272
|
+
finally {
|
|
273
|
+
await db.close();
|
|
274
|
+
}
|
|
275
|
+
const file = join(abs, REPLAY_FILE);
|
|
276
|
+
const text = renderSnapshot(snapshot);
|
|
277
|
+
const current = (() => {
|
|
278
|
+
try {
|
|
279
|
+
return readFileSync(file, "utf8");
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
return undefined;
|
|
283
|
+
}
|
|
284
|
+
})();
|
|
285
|
+
if (check) {
|
|
286
|
+
if (current === text)
|
|
287
|
+
return 0;
|
|
288
|
+
console.error(`chant sql replay --check: ${relative(process.cwd(), file)} ${current === undefined ? "is missing" : "differs from a replay of the migrations"}; run chant sql replay and commit it`);
|
|
289
|
+
return 1;
|
|
290
|
+
}
|
|
291
|
+
writeFileSync(file, text);
|
|
292
|
+
console.log(`recorded ${String(snapshot.outputs.length)} names from ${String(steps.length)} migrations in ${relative(process.cwd(), file)}`);
|
|
293
|
+
return 0;
|
|
294
|
+
}
|