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