@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
|
@@ -44,11 +44,13 @@ export const pgQualified = (schema, name) => (schema ? `${quoteIdent(schema)}.${
|
|
|
44
44
|
*/
|
|
45
45
|
export const objectIdent = (o) => o.kind === "cast"
|
|
46
46
|
? o.name
|
|
47
|
-
: o.kind === "schema" || o.kind === "extension" || o.kind === "role" || o.kind === "eventTrigger"
|
|
47
|
+
: o.kind === "schema" || o.kind === "extension" || o.kind === "role" || o.kind === "eventTrigger" || o.kind === "foreignDataWrapper" || o.kind === "foreignServer" || o.kind === "publication"
|
|
48
48
|
? quoteIdent(o.name)
|
|
49
49
|
: o.kind === "trigger" || o.kind === "policy"
|
|
50
50
|
? `${quoteIdent(o.name)}${o.signature ?? ""}`
|
|
51
|
-
:
|
|
51
|
+
: o.kind === "operator"
|
|
52
|
+
? `${o.schema ? `${quoteIdent(o.schema)}.` : ""}${o.name}${o.signature ?? ""}`
|
|
53
|
+
: `${pgQualified(o.schema, o.name)}${o.signature ?? ""}`;
|
|
52
54
|
/** The words a statement names the object's kind with. */
|
|
53
55
|
export const KIND_WORDS = {
|
|
54
56
|
schema: "SCHEMA",
|
|
@@ -68,6 +70,16 @@ export const KIND_WORDS = {
|
|
|
68
70
|
collation: "COLLATION",
|
|
69
71
|
cast: "CAST",
|
|
70
72
|
eventTrigger: "EVENT TRIGGER",
|
|
73
|
+
operator: "OPERATOR",
|
|
74
|
+
operatorClass: "OPERATOR CLASS",
|
|
75
|
+
operatorFamily: "OPERATOR FAMILY",
|
|
76
|
+
foreignTable: "FOREIGN TABLE",
|
|
77
|
+
textSearchConfiguration: "TEXT SEARCH CONFIGURATION",
|
|
78
|
+
textSearchDictionary: "TEXT SEARCH DICTIONARY",
|
|
79
|
+
statistics: "STATISTICS",
|
|
80
|
+
foreignDataWrapper: "FOREIGN DATA WRAPPER",
|
|
81
|
+
foreignServer: "SERVER",
|
|
82
|
+
publication: "PUBLICATION",
|
|
71
83
|
trigger: "TRIGGER",
|
|
72
84
|
policy: "POLICY",
|
|
73
85
|
role: "ROLE",
|
|
@@ -242,7 +254,7 @@ function identitySetClauses(options) {
|
|
|
242
254
|
out.push("SET NO CYCLE");
|
|
243
255
|
return out;
|
|
244
256
|
}
|
|
245
|
-
const COLUMN_FIELD = /^columns\.(.+?)(?:\.(type|default|notNull|generated|identity|collate|storage|comment))?$/;
|
|
257
|
+
const COLUMN_FIELD = /^columns\.(.+?)(?:\.(type|default|notNull|generated|identity|collate|storage|options|comment))?$/;
|
|
246
258
|
// ── Constraints ────────────────────────────────────────────────────────
|
|
247
259
|
/** A table's declared constraints in the canonical order (primary key, unique, check, foreign key, exclusion), each with its props. */
|
|
248
260
|
function declaredConstraintDefs(p) {
|
|
@@ -480,6 +492,196 @@ export function setNotNullSteps(table, column, live) {
|
|
|
480
492
|
steps[0] = { ...steps[0], precheck: nullPrecheck(table, column) };
|
|
481
493
|
return steps;
|
|
482
494
|
}
|
|
495
|
+
/** An `OPTIONS (...)` clause that takes the options `have` to `want`: ADD, SET and DROP per option; empty when they agree. */
|
|
496
|
+
function optionsClause(want, have) {
|
|
497
|
+
const w = (want ?? {});
|
|
498
|
+
const h = (have ?? {});
|
|
499
|
+
const parts = [
|
|
500
|
+
...Object.keys(w).filter((k) => !(k in h)).map((k) => `ADD ${quoteIdent(k)} ${pgString(w[k])}`),
|
|
501
|
+
...Object.keys(w).filter((k) => k in h && h[k] !== w[k]).map((k) => `SET ${quoteIdent(k)} ${pgString(w[k])}`),
|
|
502
|
+
...Object.keys(h).filter((k) => !(k in w)).map((k) => `DROP ${quoteIdent(k)}`),
|
|
503
|
+
];
|
|
504
|
+
return parts.length > 0 ? `OPTIONS (${parts.join(", ")})` : "";
|
|
505
|
+
}
|
|
506
|
+
/** A publication's table as `ADD TABLE` writes it: its name, column list and row filter. */
|
|
507
|
+
const publicationTable = (t) => `${t.table}${t.columns && t.columns.length > 0 ? ` (${t.columns.map(quoteIdent).join(", ")})` : ""}${t.where ? ` WHERE (${t.where})` : ""}`;
|
|
508
|
+
/**
|
|
509
|
+
* The ALTER statements that take a foreign data wrapper, a foreign server or
|
|
510
|
+
* a publication to the declaration, in place (SQLPG303): one ALTER for a
|
|
511
|
+
* wrapper or server; for a publication one SET (...) for its options, and a
|
|
512
|
+
* DROP and ADD per table or schema that changed.
|
|
513
|
+
*/
|
|
514
|
+
function alteredSteps(d, live, target) {
|
|
515
|
+
const out = [];
|
|
516
|
+
const f = d.fields;
|
|
517
|
+
const l = live.fields;
|
|
518
|
+
if (d.kind === "foreignDataWrapper") {
|
|
519
|
+
const clauses = [
|
|
520
|
+
!same(f.handler, l.handler) ? (f.handler ? `HANDLER ${String(f.handler)}` : "NO HANDLER") : "",
|
|
521
|
+
!same(f.validator, l.validator) ? (f.validator ? `VALIDATOR ${String(f.validator)}` : "NO VALIDATOR") : "",
|
|
522
|
+
optionsClause(f.options, l.options),
|
|
523
|
+
].filter(Boolean);
|
|
524
|
+
if (clauses.length > 0)
|
|
525
|
+
out.push(`ALTER FOREIGN DATA WRAPPER ${target} ${clauses.join(" ")}`);
|
|
526
|
+
}
|
|
527
|
+
else if (d.kind === "foreignServer") {
|
|
528
|
+
const clauses = [!same(f.version, l.version) ? `VERSION ${f.version === undefined ? "NULL" : pgString(String(f.version))}` : "", optionsClause(f.options, l.options)].filter(Boolean);
|
|
529
|
+
if (clauses.length > 0)
|
|
530
|
+
out.push(`ALTER SERVER ${target} ${clauses.join(" ")}`);
|
|
531
|
+
}
|
|
532
|
+
else if (d.kind === "publication") {
|
|
533
|
+
const sets = [];
|
|
534
|
+
if (!same(f.publish, l.publish))
|
|
535
|
+
sets.push(`publish = ${pgString((f.publish ?? ["insert", "update", "delete", "truncate"]).join(", "))}`);
|
|
536
|
+
if (!same(f.viaRoot, l.viaRoot))
|
|
537
|
+
sets.push(`publish_via_partition_root = ${f.viaRoot === true}`);
|
|
538
|
+
if (!same(f.generatedColumns, l.generatedColumns))
|
|
539
|
+
sets.push(`publish_generated_columns = ${String(f.generatedColumns ?? "none")}`);
|
|
540
|
+
if (sets.length > 0)
|
|
541
|
+
out.push(`ALTER PUBLICATION ${target} SET (${sets.join(", ")})`);
|
|
542
|
+
const want = f.tables ?? [];
|
|
543
|
+
const have = l.tables ?? [];
|
|
544
|
+
const kept = (m) => want.some((w) => w.table === m.table && same(w, m));
|
|
545
|
+
for (const m of have)
|
|
546
|
+
if (!kept(m))
|
|
547
|
+
out.push(`ALTER PUBLICATION ${target} DROP TABLE ${m.table}`);
|
|
548
|
+
for (const m of want)
|
|
549
|
+
if (!have.some((h) => h.table === m.table && same(h, m)))
|
|
550
|
+
out.push(`ALTER PUBLICATION ${target} ADD TABLE ${publicationTable(m)}`);
|
|
551
|
+
const wantSchemas = f.schemas ?? [];
|
|
552
|
+
const haveSchemas = l.schemas ?? [];
|
|
553
|
+
for (const s of haveSchemas)
|
|
554
|
+
if (!wantSchemas.includes(s))
|
|
555
|
+
out.push(`ALTER PUBLICATION ${target} DROP TABLES IN SCHEMA ${s}`);
|
|
556
|
+
for (const s of wantSchemas)
|
|
557
|
+
if (!haveSchemas.includes(s))
|
|
558
|
+
out.push(`ALTER PUBLICATION ${target} ADD TABLES IN SCHEMA ${s}`);
|
|
559
|
+
}
|
|
560
|
+
return out.map((sql) => step(sql, "metadata", "SQLPG303"));
|
|
561
|
+
}
|
|
562
|
+
// ── Operators, text search and foreign tables (#4406) ──────────────────
|
|
563
|
+
/**
|
|
564
|
+
* The clauses of `ALTER OPERATOR ... SET (...)` for the attributes the diff
|
|
565
|
+
* found changeable in place (SQLPG304): RESTRICT and JOIN to the declared
|
|
566
|
+
* estimator or NONE, COMMUTATOR and NEGATOR to the declared operator, and
|
|
567
|
+
* HASHES and MERGES as bare words, since they can only be turned on.
|
|
568
|
+
*/
|
|
569
|
+
function operatorSetClauses(d, changes) {
|
|
570
|
+
const definition = (d.fields.definition ?? {});
|
|
571
|
+
return changes.map((c) => {
|
|
572
|
+
const key = c.field.replace(/^definition\./, "");
|
|
573
|
+
const value = definition[key];
|
|
574
|
+
if (key === "hashes" || key === "merges")
|
|
575
|
+
return key.toUpperCase();
|
|
576
|
+
if (key === "commutator" || key === "negator")
|
|
577
|
+
return `${key.toUpperCase()} = OPERATOR(${value})`;
|
|
578
|
+
return `${key.toUpperCase()} = ${value ?? "NONE"}`;
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* A text search configuration's mappings, or a dictionary's options, taken to
|
|
583
|
+
* the declaration in place (SQLPG305). For a configuration: DROP MAPPING for
|
|
584
|
+
* the token types no longer mapped, ALTER MAPPING for those whose dictionaries
|
|
585
|
+
* changed, ADD MAPPING for the new ones, one statement for the token types
|
|
586
|
+
* that share their dictionaries; the dictionaries are named as the
|
|
587
|
+
* declaration wrote them. For a dictionary: one ALTER with each option that
|
|
588
|
+
* differs set, and each option the declaration dropped named with no value,
|
|
589
|
+
* which removes it.
|
|
590
|
+
*/
|
|
591
|
+
function textSearchSteps(obj, live, target) {
|
|
592
|
+
const d = obj.canonical;
|
|
593
|
+
if (d.kind === "textSearchDictionary") {
|
|
594
|
+
const want = (d.fields.options ?? {});
|
|
595
|
+
const have = (live.fields.options ?? {});
|
|
596
|
+
const parts = [
|
|
597
|
+
...Object.keys(want).filter((k) => have[k] !== want[k]).map((k) => `${quoteIdent(k)} = ${pgString(want[k])}`),
|
|
598
|
+
...Object.keys(have).filter((k) => !(k in want)).map((k) => quoteIdent(k)),
|
|
599
|
+
];
|
|
600
|
+
return parts.length > 0 ? [step(`ALTER TEXT SEARCH DICTIONARY ${target} (${parts.join(", ")})`, "metadata", "SQLPG305")] : [];
|
|
601
|
+
}
|
|
602
|
+
const want = (d.fields.mappings ?? {});
|
|
603
|
+
const have = (live.fields.mappings ?? {});
|
|
604
|
+
const written = new Map();
|
|
605
|
+
for (const m of obj.props.mappings)
|
|
606
|
+
for (const t of m.tokens)
|
|
607
|
+
written.set(t.toLowerCase(), m.dictionaries);
|
|
608
|
+
const group = (tokens) => {
|
|
609
|
+
const out = new Map();
|
|
610
|
+
for (const t of tokens) {
|
|
611
|
+
const key = JSON.stringify(want[t]);
|
|
612
|
+
out.set(key, [...(out.get(key) ?? []), t]);
|
|
613
|
+
}
|
|
614
|
+
return out;
|
|
615
|
+
};
|
|
616
|
+
const dropped = Object.keys(have).filter((t) => !(t in want));
|
|
617
|
+
const added = Object.keys(want).filter((t) => !(t in have));
|
|
618
|
+
const changed = Object.keys(want).filter((t) => t in have && JSON.stringify(have[t]) !== JSON.stringify(want[t]));
|
|
619
|
+
const names = (tokens) => tokens.map(quoteIdent).join(", ");
|
|
620
|
+
const out = [];
|
|
621
|
+
if (dropped.length > 0)
|
|
622
|
+
out.push(step(`ALTER TEXT SEARCH CONFIGURATION ${target} DROP MAPPING FOR ${names(dropped)}`, "metadata", "SQLPG305"));
|
|
623
|
+
for (const [verb, tokens] of [["ALTER", changed], ["ADD", added]]) {
|
|
624
|
+
for (const members of group(tokens).values())
|
|
625
|
+
out.push(step(`ALTER TEXT SEARCH CONFIGURATION ${target} ${verb} MAPPING FOR ${names(members)} WITH ${written.get(members[0]).join(", ")}`, "metadata", "SQLPG305"));
|
|
626
|
+
}
|
|
627
|
+
return out;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* A foreign table's changes in place (SQLPG306), as ALTER FOREIGN TABLE
|
|
631
|
+
* makes them: ADD and DROP COLUMN, a column's type, default, NOT NULL and
|
|
632
|
+
* OPTIONS, CHECK constraints added and dropped, and the table's OPTIONS.
|
|
633
|
+
* A column added with options gets them in an ALTER of its own, since ADD
|
|
634
|
+
* COLUMN has no OPTIONS clause.
|
|
635
|
+
*/
|
|
636
|
+
function foreignTableSteps(c, obj, live, alterKind) {
|
|
637
|
+
const d = obj.canonical;
|
|
638
|
+
const props = obj.props;
|
|
639
|
+
const make = (sql) => step(sql, "metadata", "SQLPG306");
|
|
640
|
+
if (c.field === "options") {
|
|
641
|
+
const clause = optionsClause(d.fields.options, live.fields.options);
|
|
642
|
+
return clause ? [make(`${alterKind} ${clause}`)] : [];
|
|
643
|
+
}
|
|
644
|
+
if (c.field.startsWith("constraints.")) {
|
|
645
|
+
const key = c.field.slice("constraints.".length);
|
|
646
|
+
// A declared CHECK the server lacks is added; one it has and the declaration dropped is dropped by the server's name.
|
|
647
|
+
if (c.before === undefined) {
|
|
648
|
+
const i = d.constraints.findIndex((a) => (a.name ?? a.kind.toLowerCase()) === key && !live.constraints.some((b) => sameConstraint(a, b)));
|
|
649
|
+
return i >= 0 && props.checks[i] ? [make(`${alterKind} ADD ${constraintSql("CHECK", props.checks[i])}`)] : [];
|
|
650
|
+
}
|
|
651
|
+
return [make(`${alterKind} DROP CONSTRAINT ${quoteIdent(key)}`)];
|
|
652
|
+
}
|
|
653
|
+
const m = COLUMN_FIELD.exec(c.field);
|
|
654
|
+
if (!m)
|
|
655
|
+
return [];
|
|
656
|
+
const name = m[1];
|
|
657
|
+
const prop = m[2];
|
|
658
|
+
const def = props.columns.find((x) => x.name === name);
|
|
659
|
+
const column = `${alterKind} ALTER COLUMN ${quoteIdent(name)}`;
|
|
660
|
+
const liveColumn = live.columns.find((x) => x.name === name);
|
|
661
|
+
if (prop === undefined) {
|
|
662
|
+
if (!def)
|
|
663
|
+
return [make(`${alterKind} DROP COLUMN ${quoteIdent(name)}`)];
|
|
664
|
+
const options = optionsClause(def.options, undefined);
|
|
665
|
+
return [make(`${alterKind} ADD COLUMN ${columnDefinition(def)}`), ...(options ? [make(`${column} ${options}`)] : [])];
|
|
666
|
+
}
|
|
667
|
+
if (!def)
|
|
668
|
+
return [];
|
|
669
|
+
switch (prop) {
|
|
670
|
+
case "type":
|
|
671
|
+
case "collate":
|
|
672
|
+
return def.type ? [make(`${column} TYPE ${def.type}${def.collate ? ` COLLATE ${def.collate}` : prop === "collate" ? ' COLLATE "default"' : ""}`)] : [];
|
|
673
|
+
case "default":
|
|
674
|
+
return [make(def.default !== undefined ? `${column} SET DEFAULT ${def.default}` : `${column} DROP DEFAULT`)];
|
|
675
|
+
case "notNull":
|
|
676
|
+
return [make(`${column} ${def.notNull ? "SET" : "DROP"} NOT NULL`)];
|
|
677
|
+
case "options": {
|
|
678
|
+
const clause = optionsClause(def.options, liveColumn?.options);
|
|
679
|
+
return clause ? [make(`${column} ${clause}`)] : [];
|
|
680
|
+
}
|
|
681
|
+
default:
|
|
682
|
+
return [];
|
|
683
|
+
}
|
|
684
|
+
}
|
|
483
685
|
/**
|
|
484
686
|
* The statements for an object that exists on the server, change by change.
|
|
485
687
|
* `live` is the server's definition, matched to the declaration (a renamed
|
|
@@ -510,6 +712,16 @@ export function alterSteps(obj, live, changes, opts) {
|
|
|
510
712
|
steps.push(...createSteps(obj, opts.marker, { cls: c.class, rule: c.rule }));
|
|
511
713
|
continue;
|
|
512
714
|
}
|
|
715
|
+
if (c.rule === "SQLPG306") {
|
|
716
|
+
steps.push(...foreignTableSteps(c, obj, live, alterKind));
|
|
717
|
+
continue;
|
|
718
|
+
}
|
|
719
|
+
if (d.kind === "foreignTable" && c.rule === "SQLPG216" && /^constraints\.[^.]+\.comment$/.test(c.field)) {
|
|
720
|
+
const name = c.field.split(".")[1];
|
|
721
|
+
const declared = d.constraints.find((a) => (a.name ?? a.kind.toLowerCase()) === name);
|
|
722
|
+
steps.push(step(`COMMENT ON CONSTRAINT ${quoteIdent(name)} ON ${target} IS ${declared?.comment === undefined ? "NULL" : pgString(declared.comment)}`, c.class, c.rule));
|
|
723
|
+
continue;
|
|
724
|
+
}
|
|
513
725
|
if (c.field.startsWith("constraints.")) {
|
|
514
726
|
if (!constraintsDone)
|
|
515
727
|
steps.push(...constraintSteps(obj, live, notNullChecks));
|
|
@@ -517,7 +729,7 @@ export function alterSteps(obj, live, changes, opts) {
|
|
|
517
729
|
continue;
|
|
518
730
|
}
|
|
519
731
|
const col = COLUMN_FIELD.exec(c.field);
|
|
520
|
-
if (col && (d.kind === "table")) {
|
|
732
|
+
if (col && (d.kind === "table" || d.kind === "foreignTable")) {
|
|
521
733
|
const name = col[1];
|
|
522
734
|
const prop = col[2];
|
|
523
735
|
const def = columns.get(name);
|
|
@@ -633,6 +845,18 @@ export function alterSteps(obj, live, changes, opts) {
|
|
|
633
845
|
case "SQLPG229":
|
|
634
846
|
steps.push(step(`ALTER INDEX ${objectIdent(live)} RENAME TO ${quoteIdent(d.name)}`, c.class, c.rule));
|
|
635
847
|
break;
|
|
848
|
+
case "SQLPG303":
|
|
849
|
+
if (!steps.some((s) => s.rule === "SQLPG303"))
|
|
850
|
+
steps.push(...alteredSteps(d, live, target));
|
|
851
|
+
break;
|
|
852
|
+
case "SQLPG304":
|
|
853
|
+
if (!steps.some((s) => s.rule === "SQLPG304"))
|
|
854
|
+
steps.push(step(`ALTER OPERATOR ${target} SET (${operatorSetClauses(d, changes.filter((x) => x.rule === "SQLPG304")).join(", ")})`, c.class, c.rule));
|
|
855
|
+
break;
|
|
856
|
+
case "SQLPG305":
|
|
857
|
+
if (!steps.some((s) => s.rule === "SQLPG305"))
|
|
858
|
+
steps.push(...textSearchSteps(obj, live, target));
|
|
859
|
+
break;
|
|
636
860
|
case "SQLPG250":
|
|
637
861
|
case "SQLPG280":
|
|
638
862
|
case "SQLPG302":
|
|
@@ -756,15 +980,30 @@ const DROP_ORDER = {
|
|
|
756
980
|
defaultPrivileges: 0,
|
|
757
981
|
policy: 0,
|
|
758
982
|
trigger: 0,
|
|
983
|
+
// A publication reads tables, extended statistics are on one: both go before it.
|
|
984
|
+
publication: 0,
|
|
985
|
+
statistics: 0,
|
|
759
986
|
materializedView: 1,
|
|
760
987
|
view: 2,
|
|
761
988
|
index: 3,
|
|
762
989
|
table: 4,
|
|
990
|
+
// A foreign table reads a foreign server (below) and a type; a view on it goes before.
|
|
991
|
+
foreignTable: 4,
|
|
763
992
|
sequence: 5,
|
|
764
993
|
// An event trigger and a cast before the function they call; an aggregate before its functions.
|
|
765
994
|
eventTrigger: 5.5,
|
|
766
995
|
cast: 5.5,
|
|
767
996
|
aggregate: 5.5,
|
|
997
|
+
operator: 5.5,
|
|
998
|
+
// A class names operators and functions; a family goes after its classes.
|
|
999
|
+
operatorClass: 5.2,
|
|
1000
|
+
operatorFamily: 5.3,
|
|
1001
|
+
// A configuration maps token types to dictionaries, so it goes first.
|
|
1002
|
+
textSearchConfiguration: 5.7,
|
|
1003
|
+
textSearchDictionary: 5.8,
|
|
1004
|
+
// A server before its wrapper, a wrapper before the handler function it calls.
|
|
1005
|
+
foreignServer: 5.5,
|
|
1006
|
+
foreignDataWrapper: 5.6,
|
|
768
1007
|
// A routine after what calls it (a view, a trigger, a default), before the types its parameters use.
|
|
769
1008
|
function: 6,
|
|
770
1009
|
procedure: 6,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The names Postgres gives a constraint or an index that the DDL leaves
|
|
3
|
+
* unnamed, so a reader of the declarations can spell them without a server.
|
|
4
|
+
*
|
|
5
|
+
* `makeObjectName` and the `Choose*Name` functions are from the Postgres
|
|
6
|
+
* source (`src/backend/commands/indexcmds.c`, `src/backend/catalog/heap.c`,
|
|
7
|
+
* `src/backend/commands/tablecmds.c`): the table name, then the column
|
|
8
|
+
* names joined with `_`, then a label (`pkey`, `key`, `fkey`, `check`),
|
|
9
|
+
* cut to 63 bytes by shortening the longer of the first two parts one
|
|
10
|
+
* character at a time. A name already taken gets a number after the label
|
|
11
|
+
* (`orders_pkey1`).
|
|
12
|
+
*
|
|
13
|
+
* A name the author writes always wins; these are for the rest. Drizzle's
|
|
14
|
+
* own derived names (`orders_user_id_users_id_fk`) differ from them, which is
|
|
15
|
+
* why the Drizzle export names every constraint it writes.
|
|
16
|
+
*/
|
|
17
|
+
/** `makeObjectName(name1, name2, label)`: ASCII names only. */
|
|
18
|
+
export declare function makeObjectName(name1: string, name2: string | undefined, label: string | undefined): string;
|
|
19
|
+
/** The first of `label`, `label1`, `label2`, ... that gives a name not in `taken`. */
|
|
20
|
+
export declare function chooseName(name1: string, name2: string | undefined, label: string, taken: ReadonlySet<string>): string;
|
|
21
|
+
/** The column names of a key or foreign key, joined as Postgres joins them. */
|
|
22
|
+
export declare const columnsAddition: (columns: readonly string[]) => string;
|
|
23
|
+
/**
|
|
24
|
+
* The identifiers `expr` reads as column names: words outside quotes and
|
|
25
|
+
* string literals that are not followed by `(`, and are in `columns`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function referencedColumns(expr: string, columns: readonly string[]): string[];
|
|
28
|
+
/** A check constraint's default name: the column when the expression reads one, else just the table. */
|
|
29
|
+
export declare function checkName(table: string, expr: string, columns: readonly string[], taken: ReadonlySet<string>): string;
|
|
30
|
+
//# sourceMappingURL=constraint-names.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraint-names.d.ts","sourceRoot":"","sources":["../../src/postgres/constraint-names.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,+DAA+D;AAC/D,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAkB1G;AAED,sFAAsF;AACtF,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,MAAM,CAKtH;AAED,+EAA+E;AAC/E,eAAO,MAAM,eAAe,GAAI,SAAS,SAAS,MAAM,EAAE,KAAG,MAA2B,CAAC;AAEzF;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CASpF;AAED,wGAAwG;AACxG,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,MAAM,CAGrH"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The names Postgres gives a constraint or an index that the DDL leaves
|
|
3
|
+
* unnamed, so a reader of the declarations can spell them without a server.
|
|
4
|
+
*
|
|
5
|
+
* `makeObjectName` and the `Choose*Name` functions are from the Postgres
|
|
6
|
+
* source (`src/backend/commands/indexcmds.c`, `src/backend/catalog/heap.c`,
|
|
7
|
+
* `src/backend/commands/tablecmds.c`): the table name, then the column
|
|
8
|
+
* names joined with `_`, then a label (`pkey`, `key`, `fkey`, `check`),
|
|
9
|
+
* cut to 63 bytes by shortening the longer of the first two parts one
|
|
10
|
+
* character at a time. A name already taken gets a number after the label
|
|
11
|
+
* (`orders_pkey1`).
|
|
12
|
+
*
|
|
13
|
+
* A name the author writes always wins; these are for the rest. Drizzle's
|
|
14
|
+
* own derived names (`orders_user_id_users_id_fk`) differ from them, which is
|
|
15
|
+
* why the Drizzle export names every constraint it writes.
|
|
16
|
+
*/
|
|
17
|
+
const NAMEDATALEN = 64;
|
|
18
|
+
/** `makeObjectName(name1, name2, label)`: ASCII names only. */
|
|
19
|
+
export function makeObjectName(name1, name2, label) {
|
|
20
|
+
let overhead = 0;
|
|
21
|
+
let n2 = 0;
|
|
22
|
+
if (name2 !== undefined) {
|
|
23
|
+
n2 = name2.length;
|
|
24
|
+
overhead++;
|
|
25
|
+
}
|
|
26
|
+
if (label !== undefined)
|
|
27
|
+
overhead += label.length + 1;
|
|
28
|
+
const avail = NAMEDATALEN - 1 - overhead;
|
|
29
|
+
let n1 = name1.length;
|
|
30
|
+
while (n1 + n2 > avail) {
|
|
31
|
+
if (n1 > n2)
|
|
32
|
+
n1--;
|
|
33
|
+
else
|
|
34
|
+
n2--;
|
|
35
|
+
}
|
|
36
|
+
let name = name1.slice(0, n1);
|
|
37
|
+
if (name2 !== undefined)
|
|
38
|
+
name += `_${name2.slice(0, n2)}`;
|
|
39
|
+
if (label !== undefined)
|
|
40
|
+
name += `_${label}`;
|
|
41
|
+
return name;
|
|
42
|
+
}
|
|
43
|
+
/** The first of `label`, `label1`, `label2`, ... that gives a name not in `taken`. */
|
|
44
|
+
export function chooseName(name1, name2, label, taken) {
|
|
45
|
+
let pass = 0;
|
|
46
|
+
let candidate = makeObjectName(name1, name2, label);
|
|
47
|
+
while (taken.has(candidate))
|
|
48
|
+
candidate = makeObjectName(name1, name2, `${label}${++pass}`);
|
|
49
|
+
return candidate;
|
|
50
|
+
}
|
|
51
|
+
/** The column names of a key or foreign key, joined as Postgres joins them. */
|
|
52
|
+
export const columnsAddition = (columns) => columns.join("_");
|
|
53
|
+
/**
|
|
54
|
+
* The identifiers `expr` reads as column names: words outside quotes and
|
|
55
|
+
* string literals that are not followed by `(`, and are in `columns`.
|
|
56
|
+
*/
|
|
57
|
+
export function referencedColumns(expr, columns) {
|
|
58
|
+
const known = new Set(columns);
|
|
59
|
+
const found = new Set();
|
|
60
|
+
const re = /'(?:[^']|'')*'|"((?:[^"]|"")+)"|([A-Za-z_][\w$]*)(?!\s*\()(?!\s*\.)/g;
|
|
61
|
+
for (let m = re.exec(expr); m; m = re.exec(expr)) {
|
|
62
|
+
const name = m[1] !== undefined ? m[1].replace(/""/g, '"') : m[2];
|
|
63
|
+
if (name !== undefined && known.has(m[1] !== undefined ? name : name.toLowerCase()))
|
|
64
|
+
found.add(m[1] !== undefined ? name : name.toLowerCase());
|
|
65
|
+
}
|
|
66
|
+
return [...found];
|
|
67
|
+
}
|
|
68
|
+
/** A check constraint's default name: the column when the expression reads one, else just the table. */
|
|
69
|
+
export function checkName(table, expr, columns, taken) {
|
|
70
|
+
const refs = referencedColumns(expr, columns);
|
|
71
|
+
return chooseName(table, refs.length === 1 ? refs[0] : undefined, "check", taken);
|
|
72
|
+
}
|