@supabase/pg-delta 1.0.0-alpha.3 → 1.0.0-alpha.4
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/README.md +22 -0
- package/dist/cli/bin/cli.js +0 -0
- package/dist/cli/commands/plan.js +21 -0
- package/dist/cli/utils.d.ts +2 -0
- package/dist/cli/utils.js +1 -1
- package/dist/core/objects/table/table.model.d.ts +4 -2
- package/dist/core/objects/table/table.model.js +3 -0
- package/dist/core/objects/trigger/changes/trigger.alter.js +23 -0
- package/dist/core/objects/trigger/changes/trigger.create.js +2 -1
- package/dist/core/objects/trigger/trigger.model.d.ts +1 -0
- package/dist/core/objects/trigger/trigger.model.js +3 -0
- package/dist/core/plan/apply.js +3 -3
- package/dist/core/plan/create.js +34 -15
- package/dist/core/plan/sql-format/constants.d.ts +2 -0
- package/dist/core/plan/sql-format/constants.js +11 -0
- package/dist/core/plan/sql-format/fixtures.d.ts +2 -0
- package/dist/core/plan/sql-format/fixtures.js +2449 -0
- package/dist/core/plan/sql-format/format-utils.d.ts +37 -0
- package/dist/core/plan/sql-format/format-utils.js +274 -0
- package/dist/core/plan/sql-format/formatters.d.ts +20 -0
- package/dist/core/plan/sql-format/formatters.js +737 -0
- package/dist/core/plan/sql-format/index.d.ts +2 -0
- package/dist/core/plan/sql-format/index.js +98 -0
- package/dist/core/plan/sql-format/keyword-case.d.ts +2 -0
- package/dist/core/plan/sql-format/keyword-case.js +868 -0
- package/dist/core/plan/sql-format/protect.d.ts +3 -0
- package/dist/core/plan/sql-format/protect.js +269 -0
- package/dist/core/plan/sql-format/sql-scanner.d.ts +59 -0
- package/dist/core/plan/sql-format/sql-scanner.js +202 -0
- package/dist/core/plan/sql-format/tokenizer.d.ts +22 -0
- package/dist/core/plan/sql-format/tokenizer.js +118 -0
- package/dist/core/plan/sql-format/types.d.ts +28 -0
- package/dist/core/plan/sql-format/types.js +1 -0
- package/dist/core/plan/sql-format/wrap.d.ts +2 -0
- package/dist/core/plan/sql-format/wrap.js +165 -0
- package/dist/core/plan/sql-format.d.ts +2 -0
- package/dist/core/plan/sql-format.js +1 -0
- package/dist/core/plan/statements.d.ts +2 -1
- package/dist/core/plan/statements.js +6 -2
- package/dist/core/postgres-config.d.ts +15 -0
- package/dist/core/postgres-config.js +30 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/package.json +37 -22
- package/src/cli/app.ts +28 -0
- package/src/cli/bin/cli.ts +9 -0
- package/src/cli/commands/apply.ts +101 -0
- package/src/cli/commands/plan.ts +195 -0
- package/src/cli/commands/sync.ts +185 -0
- package/src/cli/formatters/index.ts +5 -0
- package/src/cli/formatters/tree/tree-builder.ts +380 -0
- package/src/cli/formatters/tree/tree-renderer.ts +372 -0
- package/src/cli/formatters/tree/tree.ts +237 -0
- package/src/cli/utils/integrations.ts +42 -0
- package/src/cli/utils.ts +231 -0
- package/src/core/catalog.diff.ts +246 -0
- package/src/core/catalog.model.ts +384 -0
- package/src/core/change.types.ts +44 -0
- package/src/core/context.ts +26 -0
- package/src/core/depend.ts +1870 -0
- package/src/core/expand-replace-dependencies.ts +380 -0
- package/src/core/fingerprint.ts +204 -0
- package/src/core/integrations/filter/dsl.ts +204 -0
- package/src/core/integrations/filter/extractors.ts +145 -0
- package/src/core/integrations/filter/filter.types.ts +3 -0
- package/src/core/integrations/integration-dsl.ts +24 -0
- package/src/core/integrations/integration.types.ts +7 -0
- package/src/core/integrations/serialize/dsl.ts +77 -0
- package/src/core/integrations/serialize/serialize.types.ts +3 -0
- package/src/core/integrations/supabase.ts +121 -0
- package/src/core/objects/aggregate/aggregate.diff.test.ts +215 -0
- package/src/core/objects/aggregate/aggregate.diff.ts +278 -0
- package/src/core/objects/aggregate/aggregate.model.ts +317 -0
- package/src/core/objects/aggregate/changes/aggregate.alter.test.ts +64 -0
- package/src/core/objects/aggregate/changes/aggregate.alter.ts +32 -0
- package/src/core/objects/aggregate/changes/aggregate.base.ts +20 -0
- package/src/core/objects/aggregate/changes/aggregate.comment.test.ts +86 -0
- package/src/core/objects/aggregate/changes/aggregate.comment.ts +62 -0
- package/src/core/objects/aggregate/changes/aggregate.create.test.ts +101 -0
- package/src/core/objects/aggregate/changes/aggregate.create.ts +329 -0
- package/src/core/objects/aggregate/changes/aggregate.drop.test.ts +78 -0
- package/src/core/objects/aggregate/changes/aggregate.drop.ts +32 -0
- package/src/core/objects/aggregate/changes/aggregate.privilege.test.ts +130 -0
- package/src/core/objects/aggregate/changes/aggregate.privilege.ts +146 -0
- package/src/core/objects/aggregate/changes/aggregate.types.ts +12 -0
- package/src/core/objects/base.change.ts +62 -0
- package/src/core/objects/base.default-privileges.ts +204 -0
- package/src/core/objects/base.diff.ts +20 -0
- package/src/core/objects/base.model.ts +82 -0
- package/src/core/objects/base.privilege-diff.ts +299 -0
- package/src/core/objects/base.privilege.ts +184 -0
- package/src/core/objects/collation/changes/collation.alter.test.ts +63 -0
- package/src/core/objects/collation/changes/collation.alter.ts +79 -0
- package/src/core/objects/collation/changes/collation.base.ts +20 -0
- package/src/core/objects/collation/changes/collation.comment.ts +68 -0
- package/src/core/objects/collation/changes/collation.create.test.ts +51 -0
- package/src/core/objects/collation/changes/collation.create.ts +106 -0
- package/src/core/objects/collation/changes/collation.drop.test.ts +28 -0
- package/src/core/objects/collation/changes/collation.drop.ts +37 -0
- package/src/core/objects/collation/changes/collation.types.ts +10 -0
- package/src/core/objects/collation/collation.diff.test.ts +100 -0
- package/src/core/objects/collation/collation.diff.ts +126 -0
- package/src/core/objects/collation/collation.model.ts +224 -0
- package/src/core/objects/domain/changes/domain.alter.test.ts +316 -0
- package/src/core/objects/domain/changes/domain.alter.ts +286 -0
- package/src/core/objects/domain/changes/domain.base.ts +20 -0
- package/src/core/objects/domain/changes/domain.comment.ts +59 -0
- package/src/core/objects/domain/changes/domain.create.test.ts +65 -0
- package/src/core/objects/domain/changes/domain.create.ts +118 -0
- package/src/core/objects/domain/changes/domain.drop.test.ts +30 -0
- package/src/core/objects/domain/changes/domain.drop.ts +34 -0
- package/src/core/objects/domain/changes/domain.privilege.ts +171 -0
- package/src/core/objects/domain/changes/domain.types.ts +12 -0
- package/src/core/objects/domain/domain.diff.test.ts +284 -0
- package/src/core/objects/domain/domain.diff.ts +358 -0
- package/src/core/objects/domain/domain.model.ts +190 -0
- package/src/core/objects/event-trigger/changes/event-trigger.alter.test.ts +50 -0
- package/src/core/objects/event-trigger/changes/event-trigger.alter.ts +82 -0
- package/src/core/objects/event-trigger/changes/event-trigger.base.ts +20 -0
- package/src/core/objects/event-trigger/changes/event-trigger.comment.ts +66 -0
- package/src/core/objects/event-trigger/changes/event-trigger.create.test.ts +24 -0
- package/src/core/objects/event-trigger/changes/event-trigger.create.ts +72 -0
- package/src/core/objects/event-trigger/changes/event-trigger.drop.test.ts +22 -0
- package/src/core/objects/event-trigger/changes/event-trigger.drop.ts +34 -0
- package/src/core/objects/event-trigger/changes/event-trigger.types.ts +10 -0
- package/src/core/objects/event-trigger/event-trigger.diff.test.ts +126 -0
- package/src/core/objects/event-trigger/event-trigger.diff.ts +126 -0
- package/src/core/objects/event-trigger/event-trigger.model.ts +106 -0
- package/src/core/objects/extension/changes/extension.alter.test.ts +58 -0
- package/src/core/objects/extension/changes/extension.alter.ts +78 -0
- package/src/core/objects/extension/changes/extension.base.ts +20 -0
- package/src/core/objects/extension/changes/extension.comment.ts +64 -0
- package/src/core/objects/extension/changes/extension.create.test.ts +25 -0
- package/src/core/objects/extension/changes/extension.create.ts +63 -0
- package/src/core/objects/extension/changes/extension.drop.test.ts +23 -0
- package/src/core/objects/extension/changes/extension.drop.ts +34 -0
- package/src/core/objects/extension/changes/extension.types.ts +10 -0
- package/src/core/objects/extension/extension.diff.test.ts +42 -0
- package/src/core/objects/extension/extension.diff.ts +90 -0
- package/src/core/objects/extension/extension.model.ts +280 -0
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.alter.test.ts +125 -0
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.alter.ts +101 -0
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.base.ts +20 -0
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.comment.ts +72 -0
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.create.test.ts +125 -0
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.create.ts +95 -0
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.drop.test.ts +23 -0
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.drop.ts +36 -0
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.privilege.ts +172 -0
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.types.ts +12 -0
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.diff.test.ts +179 -0
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.diff.ts +341 -0
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.model.ts +149 -0
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper.types.ts +10 -0
- package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.alter.test.ts +309 -0
- package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.alter.ts +341 -0
- package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.base.ts +20 -0
- package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.comment.ts +72 -0
- package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.create.test.ts +201 -0
- package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.create.ts +81 -0
- package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.drop.test.ts +43 -0
- package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.drop.ts +37 -0
- package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.privilege.ts +181 -0
- package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.types.ts +12 -0
- package/src/core/objects/foreign-data-wrapper/foreign-table/foreign-table.diff.test.ts +813 -0
- package/src/core/objects/foreign-data-wrapper/foreign-table/foreign-table.diff.ts +406 -0
- package/src/core/objects/foreign-data-wrapper/foreign-table/foreign-table.model.ts +242 -0
- package/src/core/objects/foreign-data-wrapper/server/changes/server.alter.test.ts +168 -0
- package/src/core/objects/foreign-data-wrapper/server/changes/server.alter.ts +126 -0
- package/src/core/objects/foreign-data-wrapper/server/changes/server.base.ts +20 -0
- package/src/core/objects/foreign-data-wrapper/server/changes/server.comment.ts +60 -0
- package/src/core/objects/foreign-data-wrapper/server/changes/server.create.test.ts +131 -0
- package/src/core/objects/foreign-data-wrapper/server/changes/server.create.ts +81 -0
- package/src/core/objects/foreign-data-wrapper/server/changes/server.drop.test.ts +24 -0
- package/src/core/objects/foreign-data-wrapper/server/changes/server.drop.ts +34 -0
- package/src/core/objects/foreign-data-wrapper/server/changes/server.privilege.ts +164 -0
- package/src/core/objects/foreign-data-wrapper/server/changes/server.types.ts +12 -0
- package/src/core/objects/foreign-data-wrapper/server/server.diff.test.ts +167 -0
- package/src/core/objects/foreign-data-wrapper/server/server.diff.ts +317 -0
- package/src/core/objects/foreign-data-wrapper/server/server.model.ts +133 -0
- package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.alter.test.ts +82 -0
- package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.alter.ts +69 -0
- package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.base.ts +20 -0
- package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.create.test.ts +85 -0
- package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.create.ts +66 -0
- package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.drop.test.ts +53 -0
- package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.drop.ts +40 -0
- package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.types.ts +8 -0
- package/src/core/objects/foreign-data-wrapper/user-mapping/user-mapping.diff.test.ts +77 -0
- package/src/core/objects/foreign-data-wrapper/user-mapping/user-mapping.diff.ts +107 -0
- package/src/core/objects/foreign-data-wrapper/user-mapping/user-mapping.model.ts +96 -0
- package/src/core/objects/index/changes/index.alter.test.ts +200 -0
- package/src/core/objects/index/changes/index.alter.ts +144 -0
- package/src/core/objects/index/changes/index.base.ts +20 -0
- package/src/core/objects/index/changes/index.comment.ts +63 -0
- package/src/core/objects/index/changes/index.create.test.ts +66 -0
- package/src/core/objects/index/changes/index.create.ts +68 -0
- package/src/core/objects/index/changes/index.drop.test.ts +44 -0
- package/src/core/objects/index/changes/index.drop.ts +34 -0
- package/src/core/objects/index/changes/index.types.ts +6 -0
- package/src/core/objects/index/changes/utils.ts +16 -0
- package/src/core/objects/index/index.diff.test.ts +153 -0
- package/src/core/objects/index/index.diff.ts +243 -0
- package/src/core/objects/index/index.model.ts +370 -0
- package/src/core/objects/language/changes/language.alter.test.ts +33 -0
- package/src/core/objects/language/changes/language.alter.ts +53 -0
- package/src/core/objects/language/changes/language.base.ts +20 -0
- package/src/core/objects/language/changes/language.comment.ts +58 -0
- package/src/core/objects/language/changes/language.create.test.ts +27 -0
- package/src/core/objects/language/changes/language.create.ts +104 -0
- package/src/core/objects/language/changes/language.drop.test.ts +25 -0
- package/src/core/objects/language/changes/language.drop.ts +39 -0
- package/src/core/objects/language/changes/language.privilege.ts +172 -0
- package/src/core/objects/language/changes/language.types.ts +12 -0
- package/src/core/objects/language/language.diff.test.ts +53 -0
- package/src/core/objects/language/language.diff.ts +176 -0
- package/src/core/objects/language/language.model.ts +150 -0
- package/src/core/objects/materialized-view/changes/materialized-view.alter.test.ts +123 -0
- package/src/core/objects/materialized-view/changes/materialized-view.alter.ts +113 -0
- package/src/core/objects/materialized-view/changes/materialized-view.base.ts +20 -0
- package/src/core/objects/materialized-view/changes/materialized-view.comment.ts +176 -0
- package/src/core/objects/materialized-view/changes/materialized-view.create.test.ts +64 -0
- package/src/core/objects/materialized-view/changes/materialized-view.create.ts +93 -0
- package/src/core/objects/materialized-view/changes/materialized-view.drop.test.ts +34 -0
- package/src/core/objects/materialized-view/changes/materialized-view.drop.ts +60 -0
- package/src/core/objects/materialized-view/changes/materialized-view.privilege.ts +212 -0
- package/src/core/objects/materialized-view/changes/materialized-view.types.ts +12 -0
- package/src/core/objects/materialized-view/materialized-view.diff.test.ts +102 -0
- package/src/core/objects/materialized-view/materialized-view.diff.ts +451 -0
- package/src/core/objects/materialized-view/materialized-view.model.ts +258 -0
- package/src/core/objects/procedure/changes/procedure.alter.test.ts +1005 -0
- package/src/core/objects/procedure/changes/procedure.alter.ts +287 -0
- package/src/core/objects/procedure/changes/procedure.base.ts +20 -0
- package/src/core/objects/procedure/changes/procedure.comment.ts +70 -0
- package/src/core/objects/procedure/changes/procedure.create.test.ts +48 -0
- package/src/core/objects/procedure/changes/procedure.create.ts +92 -0
- package/src/core/objects/procedure/changes/procedure.drop.test.ts +85 -0
- package/src/core/objects/procedure/changes/procedure.drop.ts +49 -0
- package/src/core/objects/procedure/changes/procedure.privilege.ts +188 -0
- package/src/core/objects/procedure/changes/procedure.types.ts +12 -0
- package/src/core/objects/procedure/procedure.diff.test.ts +161 -0
- package/src/core/objects/procedure/procedure.diff.ts +404 -0
- package/src/core/objects/procedure/procedure.model.ts +264 -0
- package/src/core/objects/procedure/utils.ts +58 -0
- package/src/core/objects/publication/changes/publication.alter.test.ts +223 -0
- package/src/core/objects/publication/changes/publication.alter.ts +243 -0
- package/src/core/objects/publication/changes/publication.base.ts +20 -0
- package/src/core/objects/publication/changes/publication.comment.test.ts +70 -0
- package/src/core/objects/publication/changes/publication.comment.ts +64 -0
- package/src/core/objects/publication/changes/publication.create.test.ts +87 -0
- package/src/core/objects/publication/changes/publication.create.ts +82 -0
- package/src/core/objects/publication/changes/publication.drop.test.ts +46 -0
- package/src/core/objects/publication/changes/publication.drop.ts +29 -0
- package/src/core/objects/publication/changes/publication.types.ts +26 -0
- package/src/core/objects/publication/publication.diff.test.ts +292 -0
- package/src/core/objects/publication/publication.diff.ts +253 -0
- package/src/core/objects/publication/publication.model.ts +206 -0
- package/src/core/objects/publication/utils.ts +55 -0
- package/src/core/objects/rls-policy/changes/rls-policy.alter.test.ts +250 -0
- package/src/core/objects/rls-policy/changes/rls-policy.alter.ts +128 -0
- package/src/core/objects/rls-policy/changes/rls-policy.base.ts +20 -0
- package/src/core/objects/rls-policy/changes/rls-policy.comment.ts +69 -0
- package/src/core/objects/rls-policy/changes/rls-policy.create.test.ts +74 -0
- package/src/core/objects/rls-policy/changes/rls-policy.create.ts +100 -0
- package/src/core/objects/rls-policy/changes/rls-policy.drop.test.ts +28 -0
- package/src/core/objects/rls-policy/changes/rls-policy.drop.ts +39 -0
- package/src/core/objects/rls-policy/changes/rls-policy.types.ts +10 -0
- package/src/core/objects/rls-policy/rls-policy.diff.test.ts +79 -0
- package/src/core/objects/rls-policy/rls-policy.diff.ts +121 -0
- package/src/core/objects/rls-policy/rls-policy.model.ts +140 -0
- package/src/core/objects/role/changes/role.alter.test.ts +346 -0
- package/src/core/objects/role/changes/role.alter.ts +110 -0
- package/src/core/objects/role/changes/role.base.ts +24 -0
- package/src/core/objects/role/changes/role.comment.ts +55 -0
- package/src/core/objects/role/changes/role.create.test.ts +52 -0
- package/src/core/objects/role/changes/role.create.ts +102 -0
- package/src/core/objects/role/changes/role.drop.test.ts +29 -0
- package/src/core/objects/role/changes/role.drop.ts +34 -0
- package/src/core/objects/role/changes/role.privilege.ts +376 -0
- package/src/core/objects/role/changes/role.types.ts +12 -0
- package/src/core/objects/role/role.diff.test.ts +44 -0
- package/src/core/objects/role/role.diff.ts +479 -0
- package/src/core/objects/role/role.model.ts +344 -0
- package/src/core/objects/rule/changes/rule.alter.test.ts +78 -0
- package/src/core/objects/rule/changes/rule.alter.ts +72 -0
- package/src/core/objects/rule/changes/rule.base.ts +20 -0
- package/src/core/objects/rule/changes/rule.comment.test.ts +55 -0
- package/src/core/objects/rule/changes/rule.comment.ts +62 -0
- package/src/core/objects/rule/changes/rule.create.test.ts +59 -0
- package/src/core/objects/rule/changes/rule.create.ts +42 -0
- package/src/core/objects/rule/changes/rule.drop.test.ts +38 -0
- package/src/core/objects/rule/changes/rule.drop.ts +29 -0
- package/src/core/objects/rule/changes/rule.types.ts +12 -0
- package/src/core/objects/rule/rule.diff.test.ts +132 -0
- package/src/core/objects/rule/rule.diff.ts +79 -0
- package/src/core/objects/rule/rule.model.ts +173 -0
- package/src/core/objects/schema/changes/schema.alter.test.ts +28 -0
- package/src/core/objects/schema/changes/schema.alter.ts +45 -0
- package/src/core/objects/schema/changes/schema.base.ts +20 -0
- package/src/core/objects/schema/changes/schema.comment.ts +56 -0
- package/src/core/objects/schema/changes/schema.create.test.ts +22 -0
- package/src/core/objects/schema/changes/schema.create.ts +47 -0
- package/src/core/objects/schema/changes/schema.drop.test.ts +20 -0
- package/src/core/objects/schema/changes/schema.drop.ts +34 -0
- package/src/core/objects/schema/changes/schema.privilege.ts +175 -0
- package/src/core/objects/schema/changes/schema.types.ts +12 -0
- package/src/core/objects/schema/schema.diff.test.ts +42 -0
- package/src/core/objects/schema/schema.diff.ts +209 -0
- package/src/core/objects/schema/schema.model.ts +107 -0
- package/src/core/objects/sequence/changes/sequence.alter.test.ts +151 -0
- package/src/core/objects/sequence/changes/sequence.alter.ts +115 -0
- package/src/core/objects/sequence/changes/sequence.base.ts +20 -0
- package/src/core/objects/sequence/changes/sequence.comment.ts +60 -0
- package/src/core/objects/sequence/changes/sequence.create.test.ts +84 -0
- package/src/core/objects/sequence/changes/sequence.create.ts +111 -0
- package/src/core/objects/sequence/changes/sequence.drop.test.ts +32 -0
- package/src/core/objects/sequence/changes/sequence.drop.ts +37 -0
- package/src/core/objects/sequence/changes/sequence.privilege.ts +179 -0
- package/src/core/objects/sequence/changes/sequence.types.ts +12 -0
- package/src/core/objects/sequence/sequence.diff.test.ts +141 -0
- package/src/core/objects/sequence/sequence.diff.ts +359 -0
- package/src/core/objects/sequence/sequence.model.ts +185 -0
- package/src/core/objects/subscription/changes/subscription.alter.test.ts +124 -0
- package/src/core/objects/subscription/changes/subscription.alter.ts +110 -0
- package/src/core/objects/subscription/changes/subscription.base.ts +20 -0
- package/src/core/objects/subscription/changes/subscription.comment.test.ts +67 -0
- package/src/core/objects/subscription/changes/subscription.comment.ts +64 -0
- package/src/core/objects/subscription/changes/subscription.create.test.ts +77 -0
- package/src/core/objects/subscription/changes/subscription.create.ts +69 -0
- package/src/core/objects/subscription/changes/subscription.drop.test.ts +46 -0
- package/src/core/objects/subscription/changes/subscription.drop.ts +20 -0
- package/src/core/objects/subscription/changes/subscription.types.ts +22 -0
- package/src/core/objects/subscription/subscription.diff.test.ts +232 -0
- package/src/core/objects/subscription/subscription.diff.ts +241 -0
- package/src/core/objects/subscription/subscription.model.ts +190 -0
- package/src/core/objects/subscription/utils.ts +156 -0
- package/src/core/objects/table/changes/table.alter.test.ts +823 -0
- package/src/core/objects/table/changes/table.alter.ts +806 -0
- package/src/core/objects/table/changes/table.base.ts +20 -0
- package/src/core/objects/table/changes/table.comment.ts +266 -0
- package/src/core/objects/table/changes/table.create.test.ts +150 -0
- package/src/core/objects/table/changes/table.create.ts +188 -0
- package/src/core/objects/table/changes/table.drop.test.ts +34 -0
- package/src/core/objects/table/changes/table.drop.ts +45 -0
- package/src/core/objects/table/changes/table.privilege.ts +200 -0
- package/src/core/objects/table/changes/table.types.ts +12 -0
- package/src/core/objects/table/table.diff.test.ts +711 -0
- package/src/core/objects/table/table.diff.ts +953 -0
- package/src/core/objects/table/table.model.ts +460 -0
- package/src/core/objects/trigger/changes/trigger.alter.test.ts +46 -0
- package/src/core/objects/trigger/changes/trigger.alter.ts +76 -0
- package/src/core/objects/trigger/changes/trigger.base.ts +20 -0
- package/src/core/objects/trigger/changes/trigger.comment.ts +64 -0
- package/src/core/objects/trigger/changes/trigger.create.test.ts +43 -0
- package/src/core/objects/trigger/changes/trigger.create.ts +85 -0
- package/src/core/objects/trigger/changes/trigger.drop.test.ts +43 -0
- package/src/core/objects/trigger/changes/trigger.drop.ts +39 -0
- package/src/core/objects/trigger/changes/trigger.types.ts +10 -0
- package/src/core/objects/trigger/trigger.diff.test.ts +83 -0
- package/src/core/objects/trigger/trigger.diff.ts +116 -0
- package/src/core/objects/trigger/trigger.model.ts +252 -0
- package/src/core/objects/type/composite-type/changes/composite-type.alter.test.ts +202 -0
- package/src/core/objects/type/composite-type/changes/composite-type.alter.ts +174 -0
- package/src/core/objects/type/composite-type/changes/composite-type.base.ts +20 -0
- package/src/core/objects/type/composite-type/changes/composite-type.comment.ts +145 -0
- package/src/core/objects/type/composite-type/changes/composite-type.create.test.ts +101 -0
- package/src/core/objects/type/composite-type/changes/composite-type.create.ts +95 -0
- package/src/core/objects/type/composite-type/changes/composite-type.drop.test.ts +33 -0
- package/src/core/objects/type/composite-type/changes/composite-type.drop.ts +37 -0
- package/src/core/objects/type/composite-type/changes/composite-type.privilege.ts +175 -0
- package/src/core/objects/type/composite-type/changes/composite-type.types.ts +12 -0
- package/src/core/objects/type/composite-type/composite-type.diff.test.ts +191 -0
- package/src/core/objects/type/composite-type/composite-type.diff.ts +372 -0
- package/src/core/objects/type/composite-type/composite-type.model.ts +252 -0
- package/src/core/objects/type/enum/changes/enum.alter.test.ts +104 -0
- package/src/core/objects/type/enum/changes/enum.alter.ts +91 -0
- package/src/core/objects/type/enum/changes/enum.base.ts +20 -0
- package/src/core/objects/type/enum/changes/enum.comment.ts +64 -0
- package/src/core/objects/type/enum/changes/enum.create.test.ts +28 -0
- package/src/core/objects/type/enum/changes/enum.create.ts +56 -0
- package/src/core/objects/type/enum/changes/enum.drop.test.ts +25 -0
- package/src/core/objects/type/enum/changes/enum.drop.ts +34 -0
- package/src/core/objects/type/enum/changes/enum.privilege.ts +175 -0
- package/src/core/objects/type/enum/changes/enum.types.ts +12 -0
- package/src/core/objects/type/enum/enum.diff.test.ts +191 -0
- package/src/core/objects/type/enum/enum.diff.ts +396 -0
- package/src/core/objects/type/enum/enum.model.ts +194 -0
- package/src/core/objects/type/range/changes/range.alter.test.ts +27 -0
- package/src/core/objects/type/range/changes/range.alter.ts +51 -0
- package/src/core/objects/type/range/changes/range.base.ts +20 -0
- package/src/core/objects/type/range/changes/range.comment.ts +64 -0
- package/src/core/objects/type/range/changes/range.create.test.ts +51 -0
- package/src/core/objects/type/range/changes/range.create.ts +151 -0
- package/src/core/objects/type/range/changes/range.drop.test.ts +26 -0
- package/src/core/objects/type/range/changes/range.drop.ts +34 -0
- package/src/core/objects/type/range/changes/range.privilege.ts +175 -0
- package/src/core/objects/type/range/changes/range.types.ts +12 -0
- package/src/core/objects/type/range/range.diff.test.ts +70 -0
- package/src/core/objects/type/range/range.diff.ts +259 -0
- package/src/core/objects/type/range/range.model.ts +187 -0
- package/src/core/objects/type/type.types.ts +5 -0
- package/src/core/objects/utils.ts +171 -0
- package/src/core/objects/view/changes/view.alter.test.ts +110 -0
- package/src/core/objects/view/changes/view.alter.ts +112 -0
- package/src/core/objects/view/changes/view.base.ts +20 -0
- package/src/core/objects/view/changes/view.comment.ts +59 -0
- package/src/core/objects/view/changes/view.create.test.ts +65 -0
- package/src/core/objects/view/changes/view.create.ts +73 -0
- package/src/core/objects/view/changes/view.drop.test.ts +34 -0
- package/src/core/objects/view/changes/view.drop.ts +40 -0
- package/src/core/objects/view/changes/view.privilege.ts +200 -0
- package/src/core/objects/view/changes/view.types.ts +12 -0
- package/src/core/objects/view/view.diff.test.ts +91 -0
- package/src/core/objects/view/view.diff.ts +365 -0
- package/src/core/objects/view/view.model.ts +276 -0
- package/src/core/plan/apply.ts +190 -0
- package/src/core/plan/create.ts +432 -0
- package/src/core/plan/hierarchy.ts +574 -0
- package/src/core/plan/index.ts +29 -0
- package/src/core/plan/io.ts +20 -0
- package/src/core/plan/risk.ts +48 -0
- package/src/core/plan/serialize.ts +195 -0
- package/src/core/plan/sql-format/constants.ts +13 -0
- package/src/core/plan/sql-format/fixtures.ts +2806 -0
- package/src/core/plan/sql-format/format-comment-literals.test.ts +96 -0
- package/src/core/plan/sql-format/format-functions.test.ts +127 -0
- package/src/core/plan/sql-format/format-lowercase-coverage.test.ts +67 -0
- package/src/core/plan/sql-format/format-off.test.ts +809 -0
- package/src/core/plan/sql-format/format-pretty-lower-leading.test.ts +1056 -0
- package/src/core/plan/sql-format/format-pretty-narrow.test.ts +1283 -0
- package/src/core/plan/sql-format/format-pretty-preserve.test.ts +1052 -0
- package/src/core/plan/sql-format/format-pretty-upper.test.ts +1045 -0
- package/src/core/plan/sql-format/format-stress.test.ts +616 -0
- package/src/core/plan/sql-format/format-utils.test.ts +91 -0
- package/src/core/plan/sql-format/format-utils.ts +391 -0
- package/src/core/plan/sql-format/formatters.ts +921 -0
- package/src/core/plan/sql-format/index.ts +149 -0
- package/src/core/plan/sql-format/keyword-case.test.ts +118 -0
- package/src/core/plan/sql-format/keyword-case.ts +1085 -0
- package/src/core/plan/sql-format/protect.test.ts +127 -0
- package/src/core/plan/sql-format/protect.ts +337 -0
- package/src/core/plan/sql-format/sql-scanner.test.ts +240 -0
- package/src/core/plan/sql-format/sql-scanner.ts +252 -0
- package/src/core/plan/sql-format/tokenizer.test.ts +68 -0
- package/src/core/plan/sql-format/tokenizer.ts +152 -0
- package/src/core/plan/sql-format/types.ts +31 -0
- package/src/core/plan/sql-format/wrap.test.ts +119 -0
- package/src/core/plan/sql-format/wrap.ts +196 -0
- package/src/core/plan/sql-format.ts +2 -0
- package/src/core/plan/statements.ts +22 -0
- package/src/core/plan/types.ts +165 -0
- package/src/core/postgres-config.ts +169 -0
- package/src/core/sort/custom-constraints.ts +161 -0
- package/src/core/sort/debug-visualization.ts +239 -0
- package/src/core/sort/dependency-filter.ts +224 -0
- package/src/core/sort/graph-builder.ts +223 -0
- package/src/core/sort/graph-utils.ts +51 -0
- package/src/core/sort/logical-sort.ts +590 -0
- package/src/core/sort/sort-changes.ts +234 -0
- package/src/core/sort/topological-sort.ts +184 -0
- package/src/core/sort/types.ts +112 -0
- package/src/core/sort/utils.ts +69 -0
- package/src/index.ts +14 -0
|
@@ -0,0 +1,806 @@
|
|
|
1
|
+
import type { ColumnProps } from "../../base.model.ts";
|
|
2
|
+
import { stableId } from "../../utils.ts";
|
|
3
|
+
import type { Table, TableConstraintProps } from "../table.model.ts";
|
|
4
|
+
import { AlterTableChange } from "./table.base.ts";
|
|
5
|
+
|
|
6
|
+
// No drop+create paths; destructive operations are out of scope
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Alter a table.
|
|
10
|
+
*
|
|
11
|
+
* @see https://www.postgresql.org/docs/17/sql-altertable.html
|
|
12
|
+
*
|
|
13
|
+
* Synopsis
|
|
14
|
+
* ```sql
|
|
15
|
+
* ALTER TABLE [ IF EXISTS ] [ ONLY ] name [ * ]
|
|
16
|
+
* action [, ... ]
|
|
17
|
+
* where action is one of:
|
|
18
|
+
* ADD [ COLUMN ] [ IF NOT EXISTS ] column_name data_type [ COLLATE collation ] [ column_constraint [ ... ] ]
|
|
19
|
+
* DROP [ COLUMN ] [ IF EXISTS ] column_name [ RESTRICT | CASCADE ]
|
|
20
|
+
* ALTER [ COLUMN ] column_name [ SET DATA ] TYPE data_type [ COLLATE collation ] [ USING expression ]
|
|
21
|
+
* ALTER [ COLUMN ] column_name SET DEFAULT expression
|
|
22
|
+
* ALTER [ COLUMN ] column_name DROP DEFAULT
|
|
23
|
+
* ALTER [ COLUMN ] column_name { SET | DROP } NOT NULL
|
|
24
|
+
* ALTER [ COLUMN ] column_name SET STATISTICS integer
|
|
25
|
+
* ALTER [ COLUMN ] column_name SET ( attribute_option = value [, ... ] )
|
|
26
|
+
* ALTER [ COLUMN ] column_name RESET ( attribute_option [, ... ] )
|
|
27
|
+
* ALTER [ COLUMN ] column_name SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN }
|
|
28
|
+
* ALTER [ COLUMN ] column_name SET COMPRESSION compression_method
|
|
29
|
+
* ADD table_constraint [ NOT VALID ]
|
|
30
|
+
* ADD table_constraint_using_index
|
|
31
|
+
* ALTER CONSTRAINT constraint_name [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
|
|
32
|
+
* VALIDATE CONSTRAINT constraint_name
|
|
33
|
+
* DROP CONSTRAINT [ IF EXISTS ] constraint_name [ RESTRICT | CASCADE ]
|
|
34
|
+
* DISABLE TRIGGER [ trigger_name | ALL | USER ]
|
|
35
|
+
* ENABLE TRIGGER [ trigger_name | ALL | USER ]
|
|
36
|
+
* ENABLE REPLICA TRIGGER trigger_name
|
|
37
|
+
* ENABLE ALWAYS TRIGGER trigger_name
|
|
38
|
+
* DISABLE RULE rewrite_rule_name
|
|
39
|
+
* ENABLE RULE rewrite_rule_name
|
|
40
|
+
* ENABLE REPLICA RULE rewrite_rule_name
|
|
41
|
+
* ENABLE ALWAYS RULE rewrite_rule_name
|
|
42
|
+
* CLUSTER ON index_name
|
|
43
|
+
* SET WITHOUT CLUSTER
|
|
44
|
+
* SET WITH OIDS
|
|
45
|
+
* SET WITHOUT OIDS
|
|
46
|
+
* SET ( storage_parameter [= value] [, ... ] )
|
|
47
|
+
* RESET ( storage_parameter [, ... ] )
|
|
48
|
+
* INHERIT parent_table
|
|
49
|
+
* NO INHERIT parent_table
|
|
50
|
+
* OF type_name
|
|
51
|
+
* NOT OF
|
|
52
|
+
* OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
|
|
53
|
+
* SET TABLESPACE new_tablespace
|
|
54
|
+
* SET { LOGGED | UNLOGGED }
|
|
55
|
+
* SET ACCESS METHOD new_access_method
|
|
56
|
+
* REFRESH MATERIALIZED VIEW [ CONCURRENTLY ] [ WITH [ NO ] DATA ]
|
|
57
|
+
* ATTACH PARTITION partition_name { FOR VALUES partition_bound_spec | DEFAULT }
|
|
58
|
+
* DETACH PARTITION partition_name [ CONCURRENTLY | FINALIZE ]
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
export type AlterTable =
|
|
63
|
+
| AlterTableAddColumn
|
|
64
|
+
| AlterTableAddConstraint
|
|
65
|
+
| AlterTableAlterColumnDropDefault
|
|
66
|
+
| AlterTableAlterColumnDropNotNull
|
|
67
|
+
| AlterTableAlterColumnSetDefault
|
|
68
|
+
| AlterTableAlterColumnSetNotNull
|
|
69
|
+
| AlterTableAlterColumnType
|
|
70
|
+
| AlterTableAttachPartition
|
|
71
|
+
| AlterTableChangeOwner
|
|
72
|
+
| AlterTableDetachPartition
|
|
73
|
+
| AlterTableDisableRowLevelSecurity
|
|
74
|
+
| AlterTableDropColumn
|
|
75
|
+
| AlterTableDropConstraint
|
|
76
|
+
| AlterTableEnableRowLevelSecurity
|
|
77
|
+
| AlterTableForceRowLevelSecurity
|
|
78
|
+
| AlterTableNoForceRowLevelSecurity
|
|
79
|
+
| AlterTableResetStorageParams
|
|
80
|
+
| AlterTableSetLogged
|
|
81
|
+
| AlterTableSetReplicaIdentity
|
|
82
|
+
| AlterTableSetStorageParams
|
|
83
|
+
| AlterTableSetUnlogged
|
|
84
|
+
| AlterTableValidateConstraint;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* ALTER TABLE ... OWNER TO ...
|
|
88
|
+
*/
|
|
89
|
+
export class AlterTableChangeOwner extends AlterTableChange {
|
|
90
|
+
public readonly table: Table;
|
|
91
|
+
public readonly owner: string;
|
|
92
|
+
public readonly scope = "object" as const;
|
|
93
|
+
|
|
94
|
+
constructor(props: { table: Table; owner: string }) {
|
|
95
|
+
super();
|
|
96
|
+
this.table = props.table;
|
|
97
|
+
this.owner = props.owner;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
get requires() {
|
|
101
|
+
return [this.table.stableId];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
serialize(): string {
|
|
105
|
+
return [
|
|
106
|
+
"ALTER TABLE",
|
|
107
|
+
`${this.table.schema}.${this.table.name}`,
|
|
108
|
+
"OWNER TO",
|
|
109
|
+
this.owner,
|
|
110
|
+
].join(" ");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* ALTER TABLE ... SET LOGGED
|
|
116
|
+
*/
|
|
117
|
+
export class AlterTableSetLogged extends AlterTableChange {
|
|
118
|
+
public readonly table: Table;
|
|
119
|
+
public readonly scope = "object" as const;
|
|
120
|
+
|
|
121
|
+
constructor(props: { table: Table }) {
|
|
122
|
+
super();
|
|
123
|
+
this.table = props.table;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
get requires() {
|
|
127
|
+
return [this.table.stableId];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
serialize(): string {
|
|
131
|
+
return [
|
|
132
|
+
"ALTER TABLE",
|
|
133
|
+
`${this.table.schema}.${this.table.name}`,
|
|
134
|
+
"SET LOGGED",
|
|
135
|
+
].join(" ");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* ALTER TABLE ... SET UNLOGGED
|
|
141
|
+
*/
|
|
142
|
+
export class AlterTableSetUnlogged extends AlterTableChange {
|
|
143
|
+
public readonly table: Table;
|
|
144
|
+
public readonly scope = "object" as const;
|
|
145
|
+
|
|
146
|
+
constructor(props: { table: Table }) {
|
|
147
|
+
super();
|
|
148
|
+
this.table = props.table;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
get requires() {
|
|
152
|
+
return [this.table.stableId];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
serialize(): string {
|
|
156
|
+
return [
|
|
157
|
+
"ALTER TABLE",
|
|
158
|
+
`${this.table.schema}.${this.table.name}`,
|
|
159
|
+
"SET UNLOGGED",
|
|
160
|
+
].join(" ");
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* ALTER TABLE ... ENABLE ROW LEVEL SECURITY
|
|
166
|
+
*/
|
|
167
|
+
export class AlterTableEnableRowLevelSecurity extends AlterTableChange {
|
|
168
|
+
public readonly table: Table;
|
|
169
|
+
public readonly scope = "object" as const;
|
|
170
|
+
|
|
171
|
+
constructor(props: { table: Table }) {
|
|
172
|
+
super();
|
|
173
|
+
this.table = props.table;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
get requires() {
|
|
177
|
+
return [this.table.stableId];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
serialize(): string {
|
|
181
|
+
return [
|
|
182
|
+
"ALTER TABLE",
|
|
183
|
+
`${this.table.schema}.${this.table.name}`,
|
|
184
|
+
"ENABLE ROW LEVEL SECURITY",
|
|
185
|
+
].join(" ");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* ALTER TABLE ... DISABLE ROW LEVEL SECURITY
|
|
191
|
+
*/
|
|
192
|
+
export class AlterTableDisableRowLevelSecurity extends AlterTableChange {
|
|
193
|
+
public readonly table: Table;
|
|
194
|
+
public readonly scope = "object" as const;
|
|
195
|
+
|
|
196
|
+
constructor(props: { table: Table }) {
|
|
197
|
+
super();
|
|
198
|
+
this.table = props.table;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
get requires() {
|
|
202
|
+
return [this.table.stableId];
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
serialize(): string {
|
|
206
|
+
return [
|
|
207
|
+
"ALTER TABLE",
|
|
208
|
+
`${this.table.schema}.${this.table.name}`,
|
|
209
|
+
"DISABLE ROW LEVEL SECURITY",
|
|
210
|
+
].join(" ");
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* ALTER TABLE ... FORCE ROW LEVEL SECURITY
|
|
216
|
+
*/
|
|
217
|
+
export class AlterTableForceRowLevelSecurity extends AlterTableChange {
|
|
218
|
+
public readonly table: Table;
|
|
219
|
+
public readonly scope = "object" as const;
|
|
220
|
+
|
|
221
|
+
constructor(props: { table: Table }) {
|
|
222
|
+
super();
|
|
223
|
+
this.table = props.table;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
get requires() {
|
|
227
|
+
return [this.table.stableId];
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
serialize(): string {
|
|
231
|
+
return [
|
|
232
|
+
"ALTER TABLE",
|
|
233
|
+
`${this.table.schema}.${this.table.name}`,
|
|
234
|
+
"FORCE ROW LEVEL SECURITY",
|
|
235
|
+
].join(" ");
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* ALTER TABLE ... NO FORCE ROW LEVEL SECURITY
|
|
241
|
+
*/
|
|
242
|
+
export class AlterTableNoForceRowLevelSecurity extends AlterTableChange {
|
|
243
|
+
public readonly table: Table;
|
|
244
|
+
public readonly scope = "object" as const;
|
|
245
|
+
|
|
246
|
+
constructor(props: { table: Table }) {
|
|
247
|
+
super();
|
|
248
|
+
this.table = props.table;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
get requires() {
|
|
252
|
+
return [this.table.stableId];
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
serialize(): string {
|
|
256
|
+
return [
|
|
257
|
+
"ALTER TABLE",
|
|
258
|
+
`${this.table.schema}.${this.table.name}`,
|
|
259
|
+
"NO FORCE ROW LEVEL SECURITY",
|
|
260
|
+
].join(" ");
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* ALTER TABLE ... SET ( storage_parameter = value [, ... ] )
|
|
266
|
+
*/
|
|
267
|
+
export class AlterTableSetStorageParams extends AlterTableChange {
|
|
268
|
+
public readonly table: Table;
|
|
269
|
+
public readonly options: string[];
|
|
270
|
+
public readonly scope = "object" as const;
|
|
271
|
+
|
|
272
|
+
constructor(props: { table: Table; options: string[] }) {
|
|
273
|
+
super();
|
|
274
|
+
this.table = props.table;
|
|
275
|
+
this.options = props.options;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
get requires() {
|
|
279
|
+
return [this.table.stableId];
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
serialize(): string {
|
|
283
|
+
const storageParams = this.options.join(", ");
|
|
284
|
+
return [
|
|
285
|
+
"ALTER TABLE",
|
|
286
|
+
`${this.table.schema}.${this.table.name}`,
|
|
287
|
+
`SET (${storageParams})`,
|
|
288
|
+
].join(" ");
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* ALTER TABLE ... RESET ( storage_parameter [, ... ] )
|
|
294
|
+
*/
|
|
295
|
+
export class AlterTableResetStorageParams extends AlterTableChange {
|
|
296
|
+
public readonly table: Table;
|
|
297
|
+
public readonly params: string[];
|
|
298
|
+
public readonly scope = "object" as const;
|
|
299
|
+
|
|
300
|
+
constructor(props: { table: Table; params: string[] }) {
|
|
301
|
+
super();
|
|
302
|
+
this.table = props.table;
|
|
303
|
+
this.params = props.params;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
get requires() {
|
|
307
|
+
return [this.table.stableId];
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
serialize(): string {
|
|
311
|
+
const paramsSql = this.params.join(", ");
|
|
312
|
+
return [
|
|
313
|
+
"ALTER TABLE",
|
|
314
|
+
`${this.table.schema}.${this.table.name}`,
|
|
315
|
+
`RESET (${paramsSql})`,
|
|
316
|
+
].join(" ");
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// Intentionally no ReplaceTable: destructive changes are not emitted
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* ALTER TABLE ... ADD CONSTRAINT ...
|
|
324
|
+
*/
|
|
325
|
+
export class AlterTableAddConstraint extends AlterTableChange {
|
|
326
|
+
public readonly table: Table;
|
|
327
|
+
public readonly constraint: TableConstraintProps;
|
|
328
|
+
public readonly scope = "object" as const;
|
|
329
|
+
|
|
330
|
+
constructor(props: { table: Table; constraint: TableConstraintProps }) {
|
|
331
|
+
super();
|
|
332
|
+
this.table = props.table;
|
|
333
|
+
this.constraint = props.constraint;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
get creates() {
|
|
337
|
+
return [
|
|
338
|
+
stableId.constraint(
|
|
339
|
+
this.table.schema,
|
|
340
|
+
this.table.name,
|
|
341
|
+
this.constraint.name,
|
|
342
|
+
),
|
|
343
|
+
];
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
get requires() {
|
|
347
|
+
const reqs: string[] = [this.table.stableId];
|
|
348
|
+
if (this.constraint.constraint_type === "f") {
|
|
349
|
+
const referencingColumns = this.constraint.key_columns.map((columnName) =>
|
|
350
|
+
stableId.column(this.table.schema, this.table.name, columnName),
|
|
351
|
+
);
|
|
352
|
+
const referencedColumns =
|
|
353
|
+
// biome-ignore lint/style/noNonNullAssertion: constraint_type "f" means foreign_key_columns is not null
|
|
354
|
+
this.constraint.foreign_key_columns!.map((columnName) =>
|
|
355
|
+
stableId.column(
|
|
356
|
+
// biome-ignore lint/style/noNonNullAssertion: constraint_type "f" means foreign_key_schema is not null
|
|
357
|
+
this.constraint.foreign_key_schema!,
|
|
358
|
+
// biome-ignore lint/style/noNonNullAssertion: constraint_type "f" means foreign_key_table is not null
|
|
359
|
+
this.constraint.foreign_key_table!,
|
|
360
|
+
columnName,
|
|
361
|
+
),
|
|
362
|
+
);
|
|
363
|
+
reqs.push(...referencingColumns, ...referencedColumns);
|
|
364
|
+
}
|
|
365
|
+
return reqs;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
serialize(): string {
|
|
369
|
+
return [
|
|
370
|
+
"ALTER TABLE",
|
|
371
|
+
`${this.table.schema}.${this.table.name}`,
|
|
372
|
+
"ADD CONSTRAINT",
|
|
373
|
+
this.constraint.name,
|
|
374
|
+
this.constraint.definition,
|
|
375
|
+
].join(" ");
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* ALTER TABLE ... DROP CONSTRAINT ...
|
|
381
|
+
*/
|
|
382
|
+
export class AlterTableDropConstraint extends AlterTableChange {
|
|
383
|
+
public readonly table: Table;
|
|
384
|
+
public readonly constraint: TableConstraintProps;
|
|
385
|
+
public readonly scope = "object" as const;
|
|
386
|
+
|
|
387
|
+
constructor(props: { table: Table; constraint: TableConstraintProps }) {
|
|
388
|
+
super();
|
|
389
|
+
this.table = props.table;
|
|
390
|
+
this.constraint = props.constraint;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
get drops() {
|
|
394
|
+
return [
|
|
395
|
+
stableId.constraint(
|
|
396
|
+
this.table.schema,
|
|
397
|
+
this.table.name,
|
|
398
|
+
this.constraint.name,
|
|
399
|
+
),
|
|
400
|
+
];
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
get requires() {
|
|
404
|
+
return [
|
|
405
|
+
stableId.constraint(
|
|
406
|
+
this.table.schema,
|
|
407
|
+
this.table.name,
|
|
408
|
+
this.constraint.name,
|
|
409
|
+
),
|
|
410
|
+
this.table.stableId,
|
|
411
|
+
];
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
serialize(): string {
|
|
415
|
+
return [
|
|
416
|
+
"ALTER TABLE",
|
|
417
|
+
`${this.table.schema}.${this.table.name}`,
|
|
418
|
+
"DROP CONSTRAINT",
|
|
419
|
+
this.constraint.name,
|
|
420
|
+
].join(" ");
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* ALTER TABLE ... VALIDATE CONSTRAINT ...
|
|
426
|
+
*/
|
|
427
|
+
export class AlterTableValidateConstraint extends AlterTableChange {
|
|
428
|
+
public readonly table: Table;
|
|
429
|
+
public readonly constraint: TableConstraintProps;
|
|
430
|
+
public readonly scope = "object" as const;
|
|
431
|
+
|
|
432
|
+
constructor(props: { table: Table; constraint: TableConstraintProps }) {
|
|
433
|
+
super();
|
|
434
|
+
this.table = props.table;
|
|
435
|
+
this.constraint = props.constraint;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
get requires() {
|
|
439
|
+
return [
|
|
440
|
+
stableId.constraint(
|
|
441
|
+
this.table.schema,
|
|
442
|
+
this.table.name,
|
|
443
|
+
this.constraint.name,
|
|
444
|
+
),
|
|
445
|
+
this.table.stableId,
|
|
446
|
+
];
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
serialize(): string {
|
|
450
|
+
return [
|
|
451
|
+
"ALTER TABLE",
|
|
452
|
+
`${this.table.schema}.${this.table.name}`,
|
|
453
|
+
"VALIDATE CONSTRAINT",
|
|
454
|
+
this.constraint.name,
|
|
455
|
+
].join(" ");
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* ALTER TABLE ... REPLICA IDENTITY ...
|
|
461
|
+
*/
|
|
462
|
+
export class AlterTableSetReplicaIdentity extends AlterTableChange {
|
|
463
|
+
public readonly table: Table;
|
|
464
|
+
public readonly mode: "d" | "n" | "f" | "i";
|
|
465
|
+
public readonly scope = "object" as const;
|
|
466
|
+
|
|
467
|
+
constructor(props: { table: Table; mode: "d" | "n" | "f" | "i" }) {
|
|
468
|
+
super();
|
|
469
|
+
this.table = props.table;
|
|
470
|
+
this.mode = props.mode;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
get requires() {
|
|
474
|
+
return [this.table.stableId];
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
serialize(): string {
|
|
478
|
+
const clause =
|
|
479
|
+
this.mode === "d"
|
|
480
|
+
? "DEFAULT"
|
|
481
|
+
: this.mode === "n"
|
|
482
|
+
? "NOTHING"
|
|
483
|
+
: this.mode === "f"
|
|
484
|
+
? "FULL"
|
|
485
|
+
: "DEFAULT"; // 'i' (USING INDEX) is handled via index changes; fallback to DEFAULT
|
|
486
|
+
return [
|
|
487
|
+
"ALTER TABLE",
|
|
488
|
+
`${this.table.schema}.${this.table.name}`,
|
|
489
|
+
"REPLICA IDENTITY",
|
|
490
|
+
clause,
|
|
491
|
+
].join(" ");
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* ALTER TABLE ... ADD COLUMN ...
|
|
497
|
+
*/
|
|
498
|
+
export class AlterTableAddColumn extends AlterTableChange {
|
|
499
|
+
public readonly table: Table;
|
|
500
|
+
public readonly column: ColumnProps;
|
|
501
|
+
public readonly scope = "object" as const;
|
|
502
|
+
|
|
503
|
+
constructor(props: { table: Table; column: ColumnProps }) {
|
|
504
|
+
super();
|
|
505
|
+
this.table = props.table;
|
|
506
|
+
this.column = props.column;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
get creates() {
|
|
510
|
+
return [
|
|
511
|
+
stableId.column(this.table.schema, this.table.name, this.column.name),
|
|
512
|
+
];
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
get requires() {
|
|
516
|
+
return [this.table.stableId];
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
serialize(): string {
|
|
520
|
+
const parts: string[] = [
|
|
521
|
+
"ALTER TABLE",
|
|
522
|
+
`${this.table.schema}.${this.table.name}`,
|
|
523
|
+
"ADD COLUMN",
|
|
524
|
+
this.column.name,
|
|
525
|
+
this.column.data_type_str,
|
|
526
|
+
];
|
|
527
|
+
if (this.column.collation) {
|
|
528
|
+
parts.push("COLLATE", this.column.collation);
|
|
529
|
+
}
|
|
530
|
+
if (this.column.is_identity) {
|
|
531
|
+
parts.push(
|
|
532
|
+
this.column.is_identity_always
|
|
533
|
+
? "GENERATED ALWAYS AS IDENTITY"
|
|
534
|
+
: "GENERATED BY DEFAULT AS IDENTITY",
|
|
535
|
+
);
|
|
536
|
+
} else if (this.column.is_generated && this.column.default !== null) {
|
|
537
|
+
parts.push(`GENERATED ALWAYS AS (${this.column.default}) STORED`);
|
|
538
|
+
} else if (this.column.default !== null) {
|
|
539
|
+
parts.push("DEFAULT", this.column.default);
|
|
540
|
+
}
|
|
541
|
+
if (this.column.not_null) {
|
|
542
|
+
parts.push("NOT NULL");
|
|
543
|
+
}
|
|
544
|
+
return parts.join(" ");
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* ALTER TABLE ... DROP COLUMN ...
|
|
550
|
+
*/
|
|
551
|
+
export class AlterTableDropColumn extends AlterTableChange {
|
|
552
|
+
public readonly table: Table;
|
|
553
|
+
public readonly column: ColumnProps;
|
|
554
|
+
public readonly scope = "object" as const;
|
|
555
|
+
|
|
556
|
+
constructor(props: { table: Table; column: ColumnProps }) {
|
|
557
|
+
super();
|
|
558
|
+
this.table = props.table;
|
|
559
|
+
this.column = props.column;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
get drops() {
|
|
563
|
+
return [
|
|
564
|
+
stableId.column(this.table.schema, this.table.name, this.column.name),
|
|
565
|
+
];
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
get requires() {
|
|
569
|
+
return [
|
|
570
|
+
this.table.stableId,
|
|
571
|
+
stableId.column(this.table.schema, this.table.name, this.column.name),
|
|
572
|
+
];
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
serialize(): string {
|
|
576
|
+
return [
|
|
577
|
+
"ALTER TABLE",
|
|
578
|
+
`${this.table.schema}.${this.table.name}`,
|
|
579
|
+
"DROP COLUMN",
|
|
580
|
+
this.column.name,
|
|
581
|
+
].join(" ");
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* ALTER TABLE ... ALTER COLUMN ... TYPE ...
|
|
587
|
+
*/
|
|
588
|
+
export class AlterTableAlterColumnType extends AlterTableChange {
|
|
589
|
+
public readonly table: Table;
|
|
590
|
+
public readonly column: ColumnProps;
|
|
591
|
+
public readonly scope = "object" as const;
|
|
592
|
+
|
|
593
|
+
constructor(props: { table: Table; column: ColumnProps }) {
|
|
594
|
+
super();
|
|
595
|
+
this.table = props.table;
|
|
596
|
+
this.column = props.column;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
get requires() {
|
|
600
|
+
return [
|
|
601
|
+
stableId.column(this.table.schema, this.table.name, this.column.name),
|
|
602
|
+
];
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
serialize(): string {
|
|
606
|
+
const parts: string[] = [
|
|
607
|
+
"ALTER TABLE",
|
|
608
|
+
`${this.table.schema}.${this.table.name}`,
|
|
609
|
+
"ALTER COLUMN",
|
|
610
|
+
this.column.name,
|
|
611
|
+
"TYPE",
|
|
612
|
+
this.column.data_type_str,
|
|
613
|
+
];
|
|
614
|
+
if (this.column.collation) {
|
|
615
|
+
parts.push("COLLATE", this.column.collation);
|
|
616
|
+
}
|
|
617
|
+
return parts.join(" ");
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* ALTER TABLE ... ALTER COLUMN ... SET DEFAULT ...
|
|
623
|
+
*/
|
|
624
|
+
export class AlterTableAlterColumnSetDefault extends AlterTableChange {
|
|
625
|
+
public readonly table: Table;
|
|
626
|
+
public readonly column: ColumnProps;
|
|
627
|
+
public readonly scope = "object" as const;
|
|
628
|
+
|
|
629
|
+
constructor(props: { table: Table; column: ColumnProps }) {
|
|
630
|
+
super();
|
|
631
|
+
this.table = props.table;
|
|
632
|
+
this.column = props.column;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
get requires() {
|
|
636
|
+
return [
|
|
637
|
+
stableId.column(this.table.schema, this.table.name, this.column.name),
|
|
638
|
+
];
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
serialize(): string {
|
|
642
|
+
const set = this.column.is_generated ? "SET EXPRESSION AS" : "SET DEFAULT";
|
|
643
|
+
|
|
644
|
+
return [
|
|
645
|
+
"ALTER TABLE",
|
|
646
|
+
`${this.table.schema}.${this.table.name}`,
|
|
647
|
+
"ALTER COLUMN",
|
|
648
|
+
this.column.name,
|
|
649
|
+
set,
|
|
650
|
+
this.column.default ?? "NULL",
|
|
651
|
+
].join(" ");
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* ALTER TABLE ... ALTER COLUMN ... DROP DEFAULT
|
|
657
|
+
*/
|
|
658
|
+
export class AlterTableAlterColumnDropDefault extends AlterTableChange {
|
|
659
|
+
public readonly table: Table;
|
|
660
|
+
public readonly column: ColumnProps;
|
|
661
|
+
public readonly scope = "object" as const;
|
|
662
|
+
|
|
663
|
+
constructor(props: { table: Table; column: ColumnProps }) {
|
|
664
|
+
super();
|
|
665
|
+
this.table = props.table;
|
|
666
|
+
this.column = props.column;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
get requires() {
|
|
670
|
+
return [
|
|
671
|
+
stableId.column(this.table.schema, this.table.name, this.column.name),
|
|
672
|
+
];
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
serialize(): string {
|
|
676
|
+
return [
|
|
677
|
+
"ALTER TABLE",
|
|
678
|
+
`${this.table.schema}.${this.table.name}`,
|
|
679
|
+
"ALTER COLUMN",
|
|
680
|
+
this.column.name,
|
|
681
|
+
"DROP DEFAULT",
|
|
682
|
+
].join(" ");
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* ALTER TABLE ... ALTER COLUMN ... SET NOT NULL
|
|
688
|
+
*/
|
|
689
|
+
export class AlterTableAlterColumnSetNotNull extends AlterTableChange {
|
|
690
|
+
public readonly table: Table;
|
|
691
|
+
public readonly column: ColumnProps;
|
|
692
|
+
public readonly scope = "object" as const;
|
|
693
|
+
|
|
694
|
+
constructor(props: { table: Table; column: ColumnProps }) {
|
|
695
|
+
super();
|
|
696
|
+
this.table = props.table;
|
|
697
|
+
this.column = props.column;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
get requires() {
|
|
701
|
+
return [
|
|
702
|
+
stableId.column(this.table.schema, this.table.name, this.column.name),
|
|
703
|
+
];
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
serialize(): string {
|
|
707
|
+
return [
|
|
708
|
+
"ALTER TABLE",
|
|
709
|
+
`${this.table.schema}.${this.table.name}`,
|
|
710
|
+
"ALTER COLUMN",
|
|
711
|
+
this.column.name,
|
|
712
|
+
"SET NOT NULL",
|
|
713
|
+
].join(" ");
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* ALTER TABLE ... ALTER COLUMN ... DROP NOT NULL
|
|
719
|
+
*/
|
|
720
|
+
export class AlterTableAlterColumnDropNotNull extends AlterTableChange {
|
|
721
|
+
public readonly table: Table;
|
|
722
|
+
public readonly column: ColumnProps;
|
|
723
|
+
public readonly scope = "object" as const;
|
|
724
|
+
|
|
725
|
+
constructor(props: { table: Table; column: ColumnProps }) {
|
|
726
|
+
super();
|
|
727
|
+
this.table = props.table;
|
|
728
|
+
this.column = props.column;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
get requires() {
|
|
732
|
+
return [
|
|
733
|
+
stableId.column(this.table.schema, this.table.name, this.column.name),
|
|
734
|
+
];
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
serialize(): string {
|
|
738
|
+
return [
|
|
739
|
+
"ALTER TABLE",
|
|
740
|
+
`${this.table.schema}.${this.table.name}`,
|
|
741
|
+
"ALTER COLUMN",
|
|
742
|
+
this.column.name,
|
|
743
|
+
"DROP NOT NULL",
|
|
744
|
+
].join(" ");
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* ALTER TABLE ... ATTACH PARTITION ...
|
|
750
|
+
*/
|
|
751
|
+
export class AlterTableAttachPartition extends AlterTableChange {
|
|
752
|
+
public readonly table: Table;
|
|
753
|
+
public readonly partition: Table;
|
|
754
|
+
public readonly scope = "object" as const;
|
|
755
|
+
|
|
756
|
+
constructor(props: { table: Table; partition: Table }) {
|
|
757
|
+
super();
|
|
758
|
+
this.table = props.table;
|
|
759
|
+
this.partition = props.partition;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
get requires() {
|
|
763
|
+
// Depend on the partition child so that it is created before attach
|
|
764
|
+
return [this.partition.stableId, this.table.stableId];
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
serialize(): string {
|
|
768
|
+
const bound = this.partition.partition_bound ?? "DEFAULT";
|
|
769
|
+
return [
|
|
770
|
+
"ALTER TABLE",
|
|
771
|
+
`${this.table.schema}.${this.table.name}`,
|
|
772
|
+
"ATTACH PARTITION",
|
|
773
|
+
`${this.partition.schema}.${this.partition.name}`,
|
|
774
|
+
bound,
|
|
775
|
+
].join(" ");
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
/**
|
|
780
|
+
* ALTER TABLE ... DETACH PARTITION ...
|
|
781
|
+
*/
|
|
782
|
+
export class AlterTableDetachPartition extends AlterTableChange {
|
|
783
|
+
public readonly table: Table;
|
|
784
|
+
public readonly partition: Table;
|
|
785
|
+
public readonly scope = "object" as const;
|
|
786
|
+
|
|
787
|
+
constructor(props: { table: Table; partition: Table }) {
|
|
788
|
+
super();
|
|
789
|
+
this.table = props.table;
|
|
790
|
+
this.partition = props.partition;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
get requires() {
|
|
794
|
+
// Depend on the partition child for consistent ordering with potential drops
|
|
795
|
+
return [this.table.stableId, this.partition.stableId];
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
serialize(): string {
|
|
799
|
+
return [
|
|
800
|
+
"ALTER TABLE",
|
|
801
|
+
`${this.table.schema}.${this.table.name}`,
|
|
802
|
+
"DETACH PARTITION",
|
|
803
|
+
`${this.partition.schema}.${this.partition.name}`,
|
|
804
|
+
].join(" ");
|
|
805
|
+
}
|
|
806
|
+
}
|