@supabase/pg-delta 0.0.0 → 1.0.0-alpha.0
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/LICENSE +21 -0
- package/README.md +149 -0
- package/dist/cli/app.d.ts +1 -0
- package/dist/cli/app.js +26 -0
- package/dist/cli/bin/cli.d.ts +2 -0
- package/dist/cli/bin/cli.js +7 -0
- package/dist/cli/commands/apply.d.ts +5 -0
- package/dist/cli/commands/apply.js +85 -0
- package/dist/cli/commands/plan.d.ts +5 -0
- package/dist/cli/commands/plan.js +137 -0
- package/dist/cli/commands/sync.d.ts +5 -0
- package/dist/cli/commands/sync.js +141 -0
- package/dist/cli/formatters/index.d.ts +4 -0
- package/dist/cli/formatters/index.js +4 -0
- package/dist/cli/formatters/tree/tree-builder.d.ts +10 -0
- package/dist/cli/formatters/tree/tree-builder.js +333 -0
- package/dist/cli/formatters/tree/tree-renderer.d.ts +45 -0
- package/dist/cli/formatters/tree/tree-renderer.js +303 -0
- package/dist/cli/formatters/tree/tree.d.ts +8 -0
- package/dist/cli/formatters/tree/tree.js +161 -0
- package/dist/cli/utils/integrations.d.ts +13 -0
- package/dist/cli/utils/integrations.js +35 -0
- package/dist/cli/utils.d.ts +64 -0
- package/dist/cli/utils.js +160 -0
- package/dist/core/catalog.diff.d.ts +5 -0
- package/dist/core/catalog.diff.js +147 -0
- package/dist/core/catalog.model.d.ts +93 -0
- package/dist/core/catalog.model.js +254 -0
- package/dist/core/change.types.d.ts +22 -0
- package/dist/core/change.types.js +1 -0
- package/dist/core/context.d.ts +11 -0
- package/dist/core/context.js +12 -0
- package/dist/core/depend.d.ts +31 -0
- package/dist/core/depend.js +1833 -0
- package/dist/core/expand-replace-dependencies.d.ts +14 -0
- package/dist/core/expand-replace-dependencies.js +280 -0
- package/dist/core/fingerprint.d.ts +23 -0
- package/dist/core/fingerprint.js +174 -0
- package/dist/core/index.d.ts +15 -0
- package/dist/core/index.js +14 -0
- package/dist/core/integrations/filter/dsl.d.ts +97 -0
- package/dist/core/integrations/filter/dsl.js +107 -0
- package/dist/core/integrations/filter/extractors.d.ts +12 -0
- package/dist/core/integrations/filter/extractors.js +136 -0
- package/dist/core/integrations/integration-dsl.d.ts +22 -0
- package/dist/core/integrations/integration-dsl.js +6 -0
- package/dist/core/integrations/integration.types.d.ts +5 -0
- package/dist/core/integrations/integration.types.js +1 -0
- package/dist/core/integrations/serialize/dsl.d.ts +58 -0
- package/dist/core/integrations/serialize/dsl.js +42 -0
- package/dist/core/main.d.ts +5 -0
- package/dist/core/main.js +44 -0
- package/dist/core/objects/aggregate/aggregate.diff.d.ts +10 -0
- package/dist/core/objects/aggregate/aggregate.diff.js +186 -0
- package/dist/core/objects/aggregate/aggregate.model.d.ts +174 -0
- package/dist/core/objects/aggregate/aggregate.model.js +297 -0
- package/dist/core/objects/aggregate/changes/aggregate.alter.d.ts +19 -0
- package/dist/core/objects/aggregate/changes/aggregate.alter.js +25 -0
- package/dist/core/objects/aggregate/changes/aggregate.base.d.ts +17 -0
- package/dist/core/objects/aggregate/changes/aggregate.base.js +13 -0
- package/dist/core/objects/aggregate/changes/aggregate.comment.d.ts +23 -0
- package/dist/core/objects/aggregate/changes/aggregate.comment.js +44 -0
- package/dist/core/objects/aggregate/changes/aggregate.create.d.ts +19 -0
- package/dist/core/objects/aggregate/changes/aggregate.create.js +228 -0
- package/dist/core/objects/aggregate/changes/aggregate.drop.d.ts +17 -0
- package/dist/core/objects/aggregate/changes/aggregate.drop.js +26 -0
- package/dist/core/objects/aggregate/changes/aggregate.privilege.d.ts +62 -0
- package/dist/core/objects/aggregate/changes/aggregate.privilege.js +102 -0
- package/dist/core/objects/aggregate/changes/aggregate.types.d.ts +6 -0
- package/dist/core/objects/aggregate/changes/aggregate.types.js +1 -0
- package/dist/core/objects/base.change.d.ts +46 -0
- package/dist/core/objects/base.change.js +38 -0
- package/dist/core/objects/base.default-privileges.d.ts +29 -0
- package/dist/core/objects/base.default-privileges.js +167 -0
- package/dist/core/objects/base.diff.d.ts +6 -0
- package/dist/core/objects/base.diff.js +12 -0
- package/dist/core/objects/base.model.d.ts +74 -0
- package/dist/core/objects/base.model.js +47 -0
- package/dist/core/objects/base.privilege-diff.d.ts +54 -0
- package/dist/core/objects/base.privilege-diff.js +216 -0
- package/dist/core/objects/base.privilege.d.ts +27 -0
- package/dist/core/objects/base.privilege.js +169 -0
- package/dist/core/objects/collation/changes/collation.alter.d.ts +45 -0
- package/dist/core/objects/collation/changes/collation.alter.js +52 -0
- package/dist/core/objects/collation/changes/collation.base.d.ts +17 -0
- package/dist/core/objects/collation/changes/collation.base.js +13 -0
- package/dist/core/objects/collation/changes/collation.comment.d.ts +26 -0
- package/dist/core/objects/collation/changes/collation.comment.js +50 -0
- package/dist/core/objects/collation/changes/collation.create.d.ts +32 -0
- package/dist/core/objects/collation/changes/collation.create.js +86 -0
- package/dist/core/objects/collation/changes/collation.drop.d.ts +22 -0
- package/dist/core/objects/collation/changes/collation.drop.js +31 -0
- package/dist/core/objects/collation/changes/collation.types.d.ts +5 -0
- package/dist/core/objects/collation/changes/collation.types.js +1 -0
- package/dist/core/objects/collation/collation.diff.d.ts +13 -0
- package/dist/core/objects/collation/collation.diff.js +85 -0
- package/dist/core/objects/collation/collation.model.d.ts +67 -0
- package/dist/core/objects/collation/collation.model.js +207 -0
- package/dist/core/objects/domain/changes/domain.alter.d.ts +143 -0
- package/dist/core/objects/domain/changes/domain.alter.js +191 -0
- package/dist/core/objects/domain/changes/domain.base.d.ts +17 -0
- package/dist/core/objects/domain/changes/domain.base.js +13 -0
- package/dist/core/objects/domain/changes/domain.comment.d.ts +25 -0
- package/dist/core/objects/domain/changes/domain.comment.js +47 -0
- package/dist/core/objects/domain/changes/domain.create.d.ts +30 -0
- package/dist/core/objects/domain/changes/domain.create.js +92 -0
- package/dist/core/objects/domain/changes/domain.drop.d.ts +22 -0
- package/dist/core/objects/domain/changes/domain.drop.js +28 -0
- package/dist/core/objects/domain/changes/domain.privilege.d.ts +97 -0
- package/dist/core/objects/domain/changes/domain.privilege.js +127 -0
- package/dist/core/objects/domain/changes/domain.types.d.ts +6 -0
- package/dist/core/objects/domain/changes/domain.types.js +1 -0
- package/dist/core/objects/domain/domain.diff.d.ts +18 -0
- package/dist/core/objects/domain/domain.diff.js +244 -0
- package/dist/core/objects/domain/domain.model.d.ts +103 -0
- package/dist/core/objects/domain/domain.model.js +172 -0
- package/dist/core/objects/event-trigger/changes/event-trigger.alter.d.ts +44 -0
- package/dist/core/objects/event-trigger/changes/event-trigger.alter.js +51 -0
- package/dist/core/objects/event-trigger/changes/event-trigger.base.d.ts +17 -0
- package/dist/core/objects/event-trigger/changes/event-trigger.base.js +13 -0
- package/dist/core/objects/event-trigger/changes/event-trigger.comment.d.ts +23 -0
- package/dist/core/objects/event-trigger/changes/event-trigger.comment.js +46 -0
- package/dist/core/objects/event-trigger/changes/event-trigger.create.d.ts +25 -0
- package/dist/core/objects/event-trigger/changes/event-trigger.create.js +55 -0
- package/dist/core/objects/event-trigger/changes/event-trigger.drop.d.ts +22 -0
- package/dist/core/objects/event-trigger/changes/event-trigger.drop.js +28 -0
- package/dist/core/objects/event-trigger/changes/event-trigger.types.d.ts +5 -0
- package/dist/core/objects/event-trigger/changes/event-trigger.types.js +1 -0
- package/dist/core/objects/event-trigger/event-trigger.diff.d.ts +13 -0
- package/dist/core/objects/event-trigger/event-trigger.diff.js +81 -0
- package/dist/core/objects/event-trigger/event-trigger.model.d.ts +45 -0
- package/dist/core/objects/event-trigger/event-trigger.model.js +89 -0
- package/dist/core/objects/extension/changes/extension.alter.d.ts +44 -0
- package/dist/core/objects/extension/changes/extension.alter.js +51 -0
- package/dist/core/objects/extension/changes/extension.base.d.ts +17 -0
- package/dist/core/objects/extension/changes/extension.base.js +13 -0
- package/dist/core/objects/extension/changes/extension.comment.d.ts +26 -0
- package/dist/core/objects/extension/changes/extension.comment.js +46 -0
- package/dist/core/objects/extension/changes/extension.create.d.ts +25 -0
- package/dist/core/objects/extension/changes/extension.create.js +49 -0
- package/dist/core/objects/extension/changes/extension.drop.d.ts +22 -0
- package/dist/core/objects/extension/changes/extension.drop.js +28 -0
- package/dist/core/objects/extension/changes/extension.types.d.ts +5 -0
- package/dist/core/objects/extension/changes/extension.types.js +1 -0
- package/dist/core/objects/extension/extension.diff.d.ts +10 -0
- package/dist/core/objects/extension/extension.diff.js +65 -0
- package/dist/core/objects/extension/extension.model.d.ts +52 -0
- package/dist/core/objects/extension/extension.model.js +268 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.alter.d.ts +51 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.alter.js +61 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.base.d.ts +17 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.base.js +13 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.comment.d.ts +26 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.comment.js +50 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.create.d.ts +25 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.create.js +78 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.drop.d.ts +22 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.drop.js +28 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.privilege.d.ts +97 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.privilege.js +123 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.types.d.ts +6 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.types.js +1 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.diff.d.ts +18 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.diff.js +221 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.model.d.ts +59 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.model.js +128 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper.types.d.ts +5 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper.types.js +1 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.alter.d.ts +163 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.alter.js +248 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.base.d.ts +17 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.base.js +13 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.comment.d.ts +26 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.comment.js +50 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.create.d.ts +25 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.create.js +64 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.drop.d.ts +22 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.drop.js +31 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.privilege.d.ts +97 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.privilege.js +129 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.types.d.ts +6 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.types.js +1 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/foreign-table.diff.d.ts +18 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/foreign-table.diff.js +268 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/foreign-table.model.d.ts +117 -0
- package/dist/core/objects/foreign-data-wrapper/foreign-table/foreign-table.model.js +215 -0
- package/dist/core/objects/foreign-data-wrapper/server/changes/server.alter.d.ts +65 -0
- package/dist/core/objects/foreign-data-wrapper/server/changes/server.alter.js +84 -0
- package/dist/core/objects/foreign-data-wrapper/server/changes/server.base.d.ts +17 -0
- package/dist/core/objects/foreign-data-wrapper/server/changes/server.base.js +13 -0
- package/dist/core/objects/foreign-data-wrapper/server/changes/server.comment.d.ts +26 -0
- package/dist/core/objects/foreign-data-wrapper/server/changes/server.comment.js +43 -0
- package/dist/core/objects/foreign-data-wrapper/server/changes/server.create.d.ts +24 -0
- package/dist/core/objects/foreign-data-wrapper/server/changes/server.create.js +62 -0
- package/dist/core/objects/foreign-data-wrapper/server/changes/server.drop.d.ts +22 -0
- package/dist/core/objects/foreign-data-wrapper/server/changes/server.drop.js +28 -0
- package/dist/core/objects/foreign-data-wrapper/server/changes/server.privilege.d.ts +97 -0
- package/dist/core/objects/foreign-data-wrapper/server/changes/server.privilege.js +123 -0
- package/dist/core/objects/foreign-data-wrapper/server/changes/server.types.d.ts +6 -0
- package/dist/core/objects/foreign-data-wrapper/server/changes/server.types.js +1 -0
- package/dist/core/objects/foreign-data-wrapper/server/server.diff.d.ts +18 -0
- package/dist/core/objects/foreign-data-wrapper/server/server.diff.js +209 -0
- package/dist/core/objects/foreign-data-wrapper/server/server.model.d.ts +62 -0
- package/dist/core/objects/foreign-data-wrapper/server/server.model.js +118 -0
- package/dist/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.alter.d.ts +37 -0
- package/dist/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.alter.js +38 -0
- package/dist/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.base.d.ts +17 -0
- package/dist/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.base.js +13 -0
- package/dist/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.create.d.ts +24 -0
- package/dist/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.create.js +52 -0
- package/dist/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.drop.d.ts +23 -0
- package/dist/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.drop.js +34 -0
- package/dist/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.types.d.ts +4 -0
- package/dist/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.types.js +1 -0
- package/dist/core/objects/foreign-data-wrapper/user-mapping/user-mapping.diff.d.ts +10 -0
- package/dist/core/objects/foreign-data-wrapper/user-mapping/user-mapping.diff.js +77 -0
- package/dist/core/objects/foreign-data-wrapper/user-mapping/user-mapping.model.d.ts +36 -0
- package/dist/core/objects/foreign-data-wrapper/user-mapping/user-mapping.model.js +85 -0
- package/dist/core/objects/index/changes/index.alter.d.ts +76 -0
- package/dist/core/objects/index/changes/index.alter.js +94 -0
- package/dist/core/objects/index/changes/index.base.d.ts +17 -0
- package/dist/core/objects/index/changes/index.base.js +13 -0
- package/dist/core/objects/index/changes/index.comment.d.ts +26 -0
- package/dist/core/objects/index/changes/index.comment.js +50 -0
- package/dist/core/objects/index/changes/index.create.d.ts +30 -0
- package/dist/core/objects/index/changes/index.create.js +53 -0
- package/dist/core/objects/index/changes/index.drop.d.ts +22 -0
- package/dist/core/objects/index/changes/index.drop.js +28 -0
- package/dist/core/objects/index/changes/index.types.d.ts +5 -0
- package/dist/core/objects/index/changes/index.types.js +1 -0
- package/dist/core/objects/index/changes/utils.d.ts +3 -0
- package/dist/core/objects/index/changes/utils.js +6 -0
- package/dist/core/objects/index/index.diff.d.ts +12 -0
- package/dist/core/objects/index/index.diff.js +182 -0
- package/dist/core/objects/index/index.model.d.ts +150 -0
- package/dist/core/objects/index/index.model.js +340 -0
- package/dist/core/objects/language/changes/language.alter.d.ts +32 -0
- package/dist/core/objects/language/changes/language.alter.js +30 -0
- package/dist/core/objects/language/changes/language.base.d.ts +17 -0
- package/dist/core/objects/language/changes/language.base.js +13 -0
- package/dist/core/objects/language/changes/language.comment.d.ts +26 -0
- package/dist/core/objects/language/changes/language.comment.js +45 -0
- package/dist/core/objects/language/changes/language.create.d.ts +25 -0
- package/dist/core/objects/language/changes/language.create.js +76 -0
- package/dist/core/objects/language/changes/language.drop.d.ts +22 -0
- package/dist/core/objects/language/changes/language.drop.js +31 -0
- package/dist/core/objects/language/changes/language.privilege.d.ts +97 -0
- package/dist/core/objects/language/changes/language.privilege.js +128 -0
- package/dist/core/objects/language/changes/language.types.d.ts +6 -0
- package/dist/core/objects/language/changes/language.types.js +1 -0
- package/dist/core/objects/language/language.diff.d.ts +15 -0
- package/dist/core/objects/language/language.diff.js +117 -0
- package/dist/core/objects/language/language.model.d.ts +62 -0
- package/dist/core/objects/language/language.model.js +128 -0
- package/dist/core/objects/materialized-view/changes/materialized-view.alter.d.ts +67 -0
- package/dist/core/objects/materialized-view/changes/materialized-view.alter.js +63 -0
- package/dist/core/objects/materialized-view/changes/materialized-view.base.d.ts +17 -0
- package/dist/core/objects/materialized-view/changes/materialized-view.base.js +13 -0
- package/dist/core/objects/materialized-view/changes/materialized-view.comment.d.ts +53 -0
- package/dist/core/objects/materialized-view/changes/materialized-view.comment.js +112 -0
- package/dist/core/objects/materialized-view/changes/materialized-view.create.d.ts +35 -0
- package/dist/core/objects/materialized-view/changes/materialized-view.create.js +71 -0
- package/dist/core/objects/materialized-view/changes/materialized-view.drop.d.ts +26 -0
- package/dist/core/objects/materialized-view/changes/materialized-view.drop.js +42 -0
- package/dist/core/objects/materialized-view/changes/materialized-view.privilege.d.ts +105 -0
- package/dist/core/objects/materialized-view/changes/materialized-view.privilege.js +151 -0
- package/dist/core/objects/materialized-view/changes/materialized-view.types.d.ts +6 -0
- package/dist/core/objects/materialized-view/changes/materialized-view.types.js +1 -0
- package/dist/core/objects/materialized-view/materialized-view.diff.d.ts +18 -0
- package/dist/core/objects/materialized-view/materialized-view.diff.js +335 -0
- package/dist/core/objects/materialized-view/materialized-view.model.d.ts +152 -0
- package/dist/core/objects/materialized-view/materialized-view.model.js +228 -0
- package/dist/core/objects/procedure/changes/procedure.alter.d.ts +143 -0
- package/dist/core/objects/procedure/changes/procedure.alter.js +207 -0
- package/dist/core/objects/procedure/changes/procedure.base.d.ts +17 -0
- package/dist/core/objects/procedure/changes/procedure.base.js +13 -0
- package/dist/core/objects/procedure/changes/procedure.comment.d.ts +26 -0
- package/dist/core/objects/procedure/changes/procedure.comment.js +52 -0
- package/dist/core/objects/procedure/changes/procedure.create.d.ts +42 -0
- package/dist/core/objects/procedure/changes/procedure.create.js +77 -0
- package/dist/core/objects/procedure/changes/procedure.drop.d.ts +23 -0
- package/dist/core/objects/procedure/changes/procedure.drop.js +37 -0
- package/dist/core/objects/procedure/changes/procedure.privilege.d.ts +98 -0
- package/dist/core/objects/procedure/changes/procedure.privilege.js +144 -0
- package/dist/core/objects/procedure/changes/procedure.types.d.ts +6 -0
- package/dist/core/objects/procedure/changes/procedure.types.js +1 -0
- package/dist/core/objects/procedure/procedure.diff.d.ts +18 -0
- package/dist/core/objects/procedure/procedure.diff.js +282 -0
- package/dist/core/objects/procedure/procedure.model.d.ts +132 -0
- package/dist/core/objects/procedure/procedure.model.js +244 -0
- package/dist/core/objects/procedure/utils.d.ts +14 -0
- package/dist/core/objects/procedure/utils.js +55 -0
- package/dist/core/objects/publication/changes/publication.alter.d.ts +88 -0
- package/dist/core/objects/publication/changes/publication.alter.js +176 -0
- package/dist/core/objects/publication/changes/publication.base.d.ts +17 -0
- package/dist/core/objects/publication/changes/publication.base.js +13 -0
- package/dist/core/objects/publication/changes/publication.comment.d.ts +23 -0
- package/dist/core/objects/publication/changes/publication.comment.js +46 -0
- package/dist/core/objects/publication/changes/publication.create.d.ts +17 -0
- package/dist/core/objects/publication/changes/publication.create.js +61 -0
- package/dist/core/objects/publication/changes/publication.drop.d.ts +17 -0
- package/dist/core/objects/publication/changes/publication.drop.js +23 -0
- package/dist/core/objects/publication/changes/publication.types.d.ts +5 -0
- package/dist/core/objects/publication/changes/publication.types.js +1 -0
- package/dist/core/objects/publication/publication.diff.d.ts +5 -0
- package/dist/core/objects/publication/publication.diff.js +161 -0
- package/dist/core/objects/publication/publication.model.d.ts +96 -0
- package/dist/core/objects/publication/publication.model.js +186 -0
- package/dist/core/objects/publication/utils.d.ts +5 -0
- package/dist/core/objects/publication/utils.js +45 -0
- package/dist/core/objects/rls-policy/changes/rls-policy.alter.d.ts +62 -0
- package/dist/core/objects/rls-policy/changes/rls-policy.alter.js +90 -0
- package/dist/core/objects/rls-policy/changes/rls-policy.base.d.ts +17 -0
- package/dist/core/objects/rls-policy/changes/rls-policy.base.js +13 -0
- package/dist/core/objects/rls-policy/changes/rls-policy.comment.d.ts +23 -0
- package/dist/core/objects/rls-policy/changes/rls-policy.comment.js +51 -0
- package/dist/core/objects/rls-policy/changes/rls-policy.create.d.ts +27 -0
- package/dist/core/objects/rls-policy/changes/rls-policy.create.js +79 -0
- package/dist/core/objects/rls-policy/changes/rls-policy.drop.d.ts +22 -0
- package/dist/core/objects/rls-policy/changes/rls-policy.drop.js +33 -0
- package/dist/core/objects/rls-policy/changes/rls-policy.types.d.ts +5 -0
- package/dist/core/objects/rls-policy/changes/rls-policy.types.js +1 -0
- package/dist/core/objects/rls-policy/rls-policy.diff.d.ts +10 -0
- package/dist/core/objects/rls-policy/rls-policy.diff.js +80 -0
- package/dist/core/objects/rls-policy/rls-policy.model.d.ts +52 -0
- package/dist/core/objects/rls-policy/rls-policy.model.js +127 -0
- package/dist/core/objects/role/changes/role.alter.d.ts +78 -0
- package/dist/core/objects/role/changes/role.alter.js +55 -0
- package/dist/core/objects/role/changes/role.base.d.ts +17 -0
- package/dist/core/objects/role/changes/role.base.js +13 -0
- package/dist/core/objects/role/changes/role.comment.d.ts +23 -0
- package/dist/core/objects/role/changes/role.comment.js +42 -0
- package/dist/core/objects/role/changes/role.create.d.ts +38 -0
- package/dist/core/objects/role/changes/role.create.js +83 -0
- package/dist/core/objects/role/changes/role.drop.d.ts +22 -0
- package/dist/core/objects/role/changes/role.drop.js +28 -0
- package/dist/core/objects/role/changes/role.privilege.d.ts +148 -0
- package/dist/core/objects/role/changes/role.privilege.js +283 -0
- package/dist/core/objects/role/changes/role.types.d.ts +6 -0
- package/dist/core/objects/role/changes/role.types.js +1 -0
- package/dist/core/objects/role/role.diff.d.ts +13 -0
- package/dist/core/objects/role/role.diff.js +386 -0
- package/dist/core/objects/role/role.model.d.ts +89 -0
- package/dist/core/objects/role/role.model.js +312 -0
- package/dist/core/objects/rule/changes/rule.alter.d.ts +22 -0
- package/dist/core/objects/rule/changes/rule.alter.js +58 -0
- package/dist/core/objects/rule/changes/rule.base.d.ts +17 -0
- package/dist/core/objects/rule/changes/rule.base.js +13 -0
- package/dist/core/objects/rule/changes/rule.comment.d.ts +22 -0
- package/dist/core/objects/rule/changes/rule.comment.js +51 -0
- package/dist/core/objects/rule/changes/rule.create.d.ts +14 -0
- package/dist/core/objects/rule/changes/rule.create.js +28 -0
- package/dist/core/objects/rule/changes/rule.drop.d.ts +12 -0
- package/dist/core/objects/rule/changes/rule.drop.js +23 -0
- package/dist/core/objects/rule/changes/rule.types.d.ts +5 -0
- package/dist/core/objects/rule/changes/rule.types.js +1 -0
- package/dist/core/objects/rule/rule.diff.d.ts +3 -0
- package/dist/core/objects/rule/rule.diff.js +53 -0
- package/dist/core/objects/rule/rule.model.d.ts +72 -0
- package/dist/core/objects/rule/rule.model.js +156 -0
- package/dist/core/objects/schema/changes/schema.alter.d.ts +32 -0
- package/dist/core/objects/schema/changes/schema.alter.js +25 -0
- package/dist/core/objects/schema/changes/schema.base.d.ts +17 -0
- package/dist/core/objects/schema/changes/schema.base.js +13 -0
- package/dist/core/objects/schema/changes/schema.comment.d.ts +23 -0
- package/dist/core/objects/schema/changes/schema.comment.js +43 -0
- package/dist/core/objects/schema/changes/schema.create.d.ts +27 -0
- package/dist/core/objects/schema/changes/schema.create.js +38 -0
- package/dist/core/objects/schema/changes/schema.drop.d.ts +22 -0
- package/dist/core/objects/schema/changes/schema.drop.js +28 -0
- package/dist/core/objects/schema/changes/schema.privilege.d.ts +97 -0
- package/dist/core/objects/schema/changes/schema.privilege.js +131 -0
- package/dist/core/objects/schema/changes/schema.types.d.ts +6 -0
- package/dist/core/objects/schema/changes/schema.types.js +1 -0
- package/dist/core/objects/schema/schema.diff.d.ts +18 -0
- package/dist/core/objects/schema/schema.diff.js +142 -0
- package/dist/core/objects/schema/schema.model.d.ts +47 -0
- package/dist/core/objects/schema/schema.model.js +91 -0
- package/dist/core/objects/sequence/changes/sequence.alter.d.ts +59 -0
- package/dist/core/objects/sequence/changes/sequence.alter.js +75 -0
- package/dist/core/objects/sequence/changes/sequence.base.d.ts +17 -0
- package/dist/core/objects/sequence/changes/sequence.base.js +13 -0
- package/dist/core/objects/sequence/changes/sequence.comment.d.ts +23 -0
- package/dist/core/objects/sequence/changes/sequence.comment.js +47 -0
- package/dist/core/objects/sequence/changes/sequence.create.d.ts +25 -0
- package/dist/core/objects/sequence/changes/sequence.create.js +78 -0
- package/dist/core/objects/sequence/changes/sequence.drop.d.ts +22 -0
- package/dist/core/objects/sequence/changes/sequence.drop.js +31 -0
- package/dist/core/objects/sequence/changes/sequence.privilege.d.ts +101 -0
- package/dist/core/objects/sequence/changes/sequence.privilege.js +135 -0
- package/dist/core/objects/sequence/changes/sequence.types.d.ts +6 -0
- package/dist/core/objects/sequence/changes/sequence.types.js +1 -0
- package/dist/core/objects/sequence/sequence.diff.d.ts +20 -0
- package/dist/core/objects/sequence/sequence.diff.js +258 -0
- package/dist/core/objects/sequence/sequence.model.d.ts +76 -0
- package/dist/core/objects/sequence/sequence.model.js +169 -0
- package/dist/core/objects/subscription/changes/subscription.alter.d.ts +56 -0
- package/dist/core/objects/subscription/changes/subscription.alter.js +82 -0
- package/dist/core/objects/subscription/changes/subscription.base.d.ts +17 -0
- package/dist/core/objects/subscription/changes/subscription.base.js +13 -0
- package/dist/core/objects/subscription/changes/subscription.comment.d.ts +23 -0
- package/dist/core/objects/subscription/changes/subscription.comment.js +46 -0
- package/dist/core/objects/subscription/changes/subscription.create.d.ts +12 -0
- package/dist/core/objects/subscription/changes/subscription.create.js +52 -0
- package/dist/core/objects/subscription/changes/subscription.drop.d.ts +11 -0
- package/dist/core/objects/subscription/changes/subscription.drop.js +15 -0
- package/dist/core/objects/subscription/changes/subscription.types.d.ts +5 -0
- package/dist/core/objects/subscription/changes/subscription.types.js +1 -0
- package/dist/core/objects/subscription/subscription.diff.d.ts +5 -0
- package/dist/core/objects/subscription/subscription.diff.js +167 -0
- package/dist/core/objects/subscription/subscription.model.d.ts +80 -0
- package/dist/core/objects/subscription/subscription.model.js +166 -0
- package/dist/core/objects/subscription/utils.d.ts +37 -0
- package/dist/core/objects/subscription/utils.js +112 -0
- package/dist/core/objects/table/changes/table.alter.d.ts +357 -0
- package/dist/core/objects/table/changes/table.alter.js +607 -0
- package/dist/core/objects/table/changes/table.base.d.ts +17 -0
- package/dist/core/objects/table/changes/table.base.js +13 -0
- package/dist/core/objects/table/changes/table.comment.d.ts +106 -0
- package/dist/core/objects/table/changes/table.comment.js +175 -0
- package/dist/core/objects/table/changes/table.create.d.ts +33 -0
- package/dist/core/objects/table/changes/table.create.js +145 -0
- package/dist/core/objects/table/changes/table.drop.d.ts +22 -0
- package/dist/core/objects/table/changes/table.drop.js +35 -0
- package/dist/core/objects/table/changes/table.privilege.d.ts +107 -0
- package/dist/core/objects/table/changes/table.privilege.js +150 -0
- package/dist/core/objects/table/changes/table.types.d.ts +6 -0
- package/dist/core/objects/table/changes/table.types.js +1 -0
- package/dist/core/objects/table/table.diff.d.ts +18 -0
- package/dist/core/objects/table/table.diff.js +668 -0
- package/dist/core/objects/table/table.model.d.ts +341 -0
- package/dist/core/objects/table/table.model.js +426 -0
- package/dist/core/objects/trigger/changes/trigger.alter.d.ts +29 -0
- package/dist/core/objects/trigger/changes/trigger.alter.js +27 -0
- package/dist/core/objects/trigger/changes/trigger.base.d.ts +17 -0
- package/dist/core/objects/trigger/changes/trigger.base.js +13 -0
- package/dist/core/objects/trigger/changes/trigger.comment.d.ts +23 -0
- package/dist/core/objects/trigger/changes/trigger.comment.js +51 -0
- package/dist/core/objects/trigger/changes/trigger.create.d.ts +41 -0
- package/dist/core/objects/trigger/changes/trigger.create.js +61 -0
- package/dist/core/objects/trigger/changes/trigger.drop.d.ts +22 -0
- package/dist/core/objects/trigger/changes/trigger.drop.js +33 -0
- package/dist/core/objects/trigger/changes/trigger.types.d.ts +5 -0
- package/dist/core/objects/trigger/changes/trigger.types.js +1 -0
- package/dist/core/objects/trigger/trigger.diff.d.ts +11 -0
- package/dist/core/objects/trigger/trigger.diff.js +84 -0
- package/dist/core/objects/trigger/trigger.model.d.ts +92 -0
- package/dist/core/objects/trigger/trigger.model.js +235 -0
- package/dist/core/objects/type/composite-type/changes/composite-type.alter.d.ts +81 -0
- package/dist/core/objects/type/composite-type/changes/composite-type.alter.js +123 -0
- package/dist/core/objects/type/composite-type/changes/composite-type.base.d.ts +17 -0
- package/dist/core/objects/type/composite-type/changes/composite-type.base.js +13 -0
- package/dist/core/objects/type/composite-type/changes/composite-type.comment.d.ts +53 -0
- package/dist/core/objects/type/composite-type/changes/composite-type.comment.js +108 -0
- package/dist/core/objects/type/composite-type/changes/composite-type.create.d.ts +23 -0
- package/dist/core/objects/type/composite-type/changes/composite-type.create.js +72 -0
- package/dist/core/objects/type/composite-type/changes/composite-type.drop.d.ts +22 -0
- package/dist/core/objects/type/composite-type/changes/composite-type.drop.js +31 -0
- package/dist/core/objects/type/composite-type/changes/composite-type.privilege.d.ts +97 -0
- package/dist/core/objects/type/composite-type/changes/composite-type.privilege.js +131 -0
- package/dist/core/objects/type/composite-type/changes/composite-type.types.d.ts +6 -0
- package/dist/core/objects/type/composite-type/changes/composite-type.types.js +1 -0
- package/dist/core/objects/type/composite-type/composite-type.diff.d.ts +18 -0
- package/dist/core/objects/type/composite-type/composite-type.diff.js +250 -0
- package/dist/core/objects/type/composite-type/composite-type.model.d.ts +148 -0
- package/dist/core/objects/type/composite-type/composite-type.model.js +223 -0
- package/dist/core/objects/type/enum/changes/enum.alter.d.ts +52 -0
- package/dist/core/objects/type/enum/changes/enum.alter.js +60 -0
- package/dist/core/objects/type/enum/changes/enum.base.d.ts +17 -0
- package/dist/core/objects/type/enum/changes/enum.base.js +13 -0
- package/dist/core/objects/type/enum/changes/enum.comment.d.ts +26 -0
- package/dist/core/objects/type/enum/changes/enum.comment.js +47 -0
- package/dist/core/objects/type/enum/changes/enum.create.d.ts +22 -0
- package/dist/core/objects/type/enum/changes/enum.create.js +43 -0
- package/dist/core/objects/type/enum/changes/enum.drop.d.ts +22 -0
- package/dist/core/objects/type/enum/changes/enum.drop.js +28 -0
- package/dist/core/objects/type/enum/changes/enum.privilege.d.ts +97 -0
- package/dist/core/objects/type/enum/changes/enum.privilege.js +131 -0
- package/dist/core/objects/type/enum/changes/enum.types.d.ts +6 -0
- package/dist/core/objects/type/enum/changes/enum.types.js +1 -0
- package/dist/core/objects/type/enum/enum.diff.d.ts +18 -0
- package/dist/core/objects/type/enum/enum.diff.js +268 -0
- package/dist/core/objects/type/enum/enum.model.d.ts +66 -0
- package/dist/core/objects/type/enum/enum.model.js +154 -0
- package/dist/core/objects/type/range/changes/range.alter.d.ts +33 -0
- package/dist/core/objects/type/range/changes/range.alter.js +30 -0
- package/dist/core/objects/type/range/changes/range.base.d.ts +17 -0
- package/dist/core/objects/type/range/changes/range.base.js +13 -0
- package/dist/core/objects/type/range/changes/range.comment.d.ts +26 -0
- package/dist/core/objects/type/range/changes/range.comment.js +47 -0
- package/dist/core/objects/type/range/changes/range.create.d.ts +31 -0
- package/dist/core/objects/type/range/changes/range.create.js +113 -0
- package/dist/core/objects/type/range/changes/range.drop.d.ts +22 -0
- package/dist/core/objects/type/range/changes/range.drop.js +28 -0
- package/dist/core/objects/type/range/changes/range.privilege.d.ts +97 -0
- package/dist/core/objects/type/range/changes/range.privilege.js +131 -0
- package/dist/core/objects/type/range/changes/range.types.d.ts +6 -0
- package/dist/core/objects/type/range/changes/range.types.js +1 -0
- package/dist/core/objects/type/range/range.diff.d.ts +18 -0
- package/dist/core/objects/type/range/range.diff.js +172 -0
- package/dist/core/objects/type/range/range.model.d.ts +81 -0
- package/dist/core/objects/type/range/range.model.js +165 -0
- package/dist/core/objects/type/type.types.d.ts +4 -0
- package/dist/core/objects/type/type.types.js +1 -0
- package/dist/core/objects/utils.d.ts +57 -0
- package/dist/core/objects/utils.js +137 -0
- package/dist/core/objects/view/changes/view.alter.d.ts +62 -0
- package/dist/core/objects/view/changes/view.alter.js +75 -0
- package/dist/core/objects/view/changes/view.base.d.ts +17 -0
- package/dist/core/objects/view/changes/view.base.js +13 -0
- package/dist/core/objects/view/changes/view.comment.d.ts +23 -0
- package/dist/core/objects/view/changes/view.comment.js +46 -0
- package/dist/core/objects/view/changes/view.create.d.ts +27 -0
- package/dist/core/objects/view/changes/view.create.js +57 -0
- package/dist/core/objects/view/changes/view.drop.d.ts +17 -0
- package/dist/core/objects/view/changes/view.drop.js +30 -0
- package/dist/core/objects/view/changes/view.privilege.d.ts +107 -0
- package/dist/core/objects/view/changes/view.privilege.js +150 -0
- package/dist/core/objects/view/changes/view.types.d.ts +6 -0
- package/dist/core/objects/view/changes/view.types.js +1 -0
- package/dist/core/objects/view/view.diff.d.ts +18 -0
- package/dist/core/objects/view/view.diff.js +270 -0
- package/dist/core/objects/view/view.model.d.ts +152 -0
- package/dist/core/objects/view/view.model.js +250 -0
- package/dist/core/plan/apply.d.ts +33 -0
- package/dist/core/plan/apply.js +112 -0
- package/dist/core/plan/create.d.ts +22 -0
- package/dist/core/plan/create.js +228 -0
- package/dist/core/plan/hierarchy.d.ts +19 -0
- package/dist/core/plan/hierarchy.js +488 -0
- package/dist/core/plan/index.d.ts +19 -0
- package/dist/core/plan/index.js +21 -0
- package/dist/core/plan/io.d.ts +12 -0
- package/dist/core/plan/io.js +17 -0
- package/dist/core/plan/risk.d.ts +10 -0
- package/dist/core/plan/risk.js +38 -0
- package/dist/core/plan/serialize.d.ts +26 -0
- package/dist/core/plan/serialize.js +176 -0
- package/dist/core/plan/statements.d.ts +8 -0
- package/dist/core/plan/statements.js +13 -0
- package/dist/core/plan/types.d.ts +153 -0
- package/dist/core/plan/types.js +32 -0
- package/dist/core/postgres-config.d.ts +8 -0
- package/dist/core/postgres-config.js +46 -0
- package/dist/core/sort/custom-constraints.d.ts +9 -0
- package/dist/core/sort/custom-constraints.js +133 -0
- package/dist/core/sort/debug-visualization.d.ts +8 -0
- package/dist/core/sort/debug-visualization.js +145 -0
- package/dist/core/sort/dependency-filter.d.ts +19 -0
- package/dist/core/sort/dependency-filter.js +152 -0
- package/dist/core/sort/graph-builder.d.ts +37 -0
- package/dist/core/sort/graph-builder.js +172 -0
- package/dist/core/sort/graph-utils.d.ts +14 -0
- package/dist/core/sort/graph-utils.js +41 -0
- package/dist/core/sort/logical-sort.d.ts +26 -0
- package/dist/core/sort/logical-sort.js +532 -0
- package/dist/core/sort/sort-changes.d.ts +28 -0
- package/dist/core/sort/sort-changes.js +147 -0
- package/dist/core/sort/topological-sort.d.ts +20 -0
- package/dist/core/sort/topological-sort.js +138 -0
- package/dist/core/sort/types.d.ts +102 -0
- package/dist/core/sort/types.js +1 -0
- package/dist/core/sort/utils.d.ts +23 -0
- package/dist/core/sort/utils.js +51 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +58 -12
|
@@ -0,0 +1,668 @@
|
|
|
1
|
+
import { diffObjects } from "../base.diff.js";
|
|
2
|
+
import { diffPrivileges, groupPrivilegesByColumns, } from "../base.privilege-diff.js";
|
|
3
|
+
import { deepEqual } from "../utils.js";
|
|
4
|
+
import { AlterTableAddColumn, AlterTableAddConstraint, AlterTableAlterColumnDropDefault, AlterTableAlterColumnDropNotNull, AlterTableAlterColumnSetDefault, AlterTableAlterColumnSetNotNull, AlterTableAlterColumnType, AlterTableAttachPartition, AlterTableChangeOwner, AlterTableDetachPartition, AlterTableDisableRowLevelSecurity, AlterTableDropColumn, AlterTableDropConstraint, AlterTableEnableRowLevelSecurity, AlterTableForceRowLevelSecurity, AlterTableNoForceRowLevelSecurity, AlterTableResetStorageParams, AlterTableSetLogged, AlterTableSetReplicaIdentity, AlterTableSetStorageParams, AlterTableSetUnlogged, AlterTableValidateConstraint, } from "./changes/table.alter.js";
|
|
5
|
+
import { CreateCommentOnColumn, CreateCommentOnConstraint, CreateCommentOnTable, DropCommentOnColumn, DropCommentOnConstraint, DropCommentOnTable, } from "./changes/table.comment.js";
|
|
6
|
+
import { CreateTable } from "./changes/table.create.js";
|
|
7
|
+
import { DropTable } from "./changes/table.drop.js";
|
|
8
|
+
import { GrantTablePrivileges, RevokeGrantOptionTablePrivileges, RevokeTablePrivileges, } from "./changes/table.privilege.js";
|
|
9
|
+
import { Table } from "./table.model.js";
|
|
10
|
+
function createAlterConstraintChange(mainTable, branchTable) {
|
|
11
|
+
const changes = [];
|
|
12
|
+
// Note: Table renaming would also use ALTER TABLE ... RENAME TO ...
|
|
13
|
+
// But since our Table model uses 'name' as the identity field,
|
|
14
|
+
// a name change would be handled as drop + create by diffObjects()
|
|
15
|
+
// TABLE CONSTRAINTS
|
|
16
|
+
const mainByName = new Map((mainTable.constraints ?? []).map((c) => [c.name, c]));
|
|
17
|
+
const branchByName = new Map((branchTable.constraints ?? []).map((c) => [c.name, c]));
|
|
18
|
+
// Created constraints
|
|
19
|
+
for (const [name, c] of branchByName) {
|
|
20
|
+
// Skip constraint clones on partitions - they are automatically created when the parent constraint is created
|
|
21
|
+
if (c.is_partition_clone) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (!mainByName.has(name)) {
|
|
25
|
+
changes.push(new AlterTableAddConstraint({
|
|
26
|
+
table: branchTable,
|
|
27
|
+
constraint: c,
|
|
28
|
+
}));
|
|
29
|
+
if (!c.validated) {
|
|
30
|
+
changes.push(new AlterTableValidateConstraint({
|
|
31
|
+
table: branchTable,
|
|
32
|
+
constraint: c,
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
// Add comment for newly created constraint
|
|
36
|
+
if (c.comment !== null) {
|
|
37
|
+
changes.push(new CreateCommentOnConstraint({
|
|
38
|
+
table: branchTable,
|
|
39
|
+
constraint: c,
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Dropped constraints
|
|
45
|
+
for (const [name, c] of mainByName) {
|
|
46
|
+
// Skip constraint clones on partitions - they are automatically dropped when the parent constraint is dropped
|
|
47
|
+
if (c.is_partition_clone) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (!branchByName.has(name)) {
|
|
51
|
+
changes.push(new AlterTableDropConstraint({ table: mainTable, constraint: c }));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Altered constraints -> drop + add
|
|
55
|
+
for (const [name, mainC] of mainByName) {
|
|
56
|
+
const branchC = branchByName.get(name);
|
|
57
|
+
if (!branchC)
|
|
58
|
+
continue;
|
|
59
|
+
// Skip constraint clones on partitions - they are automatically updated when the parent constraint is updated
|
|
60
|
+
if (mainC.is_partition_clone || branchC.is_partition_clone) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const changed = mainC.constraint_type !== branchC.constraint_type ||
|
|
64
|
+
mainC.deferrable !== branchC.deferrable ||
|
|
65
|
+
mainC.initially_deferred !== branchC.initially_deferred ||
|
|
66
|
+
mainC.validated !== branchC.validated ||
|
|
67
|
+
mainC.is_local !== branchC.is_local ||
|
|
68
|
+
mainC.no_inherit !== branchC.no_inherit ||
|
|
69
|
+
JSON.stringify(mainC.key_columns) !==
|
|
70
|
+
JSON.stringify(branchC.key_columns) ||
|
|
71
|
+
JSON.stringify(mainC.foreign_key_columns) !==
|
|
72
|
+
JSON.stringify(branchC.foreign_key_columns) ||
|
|
73
|
+
mainC.foreign_key_table !== branchC.foreign_key_table ||
|
|
74
|
+
mainC.foreign_key_schema !== branchC.foreign_key_schema ||
|
|
75
|
+
mainC.on_update !== branchC.on_update ||
|
|
76
|
+
mainC.on_delete !== branchC.on_delete ||
|
|
77
|
+
mainC.match_type !== branchC.match_type ||
|
|
78
|
+
mainC.check_expression !== branchC.check_expression;
|
|
79
|
+
if (changed) {
|
|
80
|
+
changes.push(new AlterTableDropConstraint({
|
|
81
|
+
table: mainTable,
|
|
82
|
+
constraint: mainC,
|
|
83
|
+
}));
|
|
84
|
+
changes.push(new AlterTableAddConstraint({
|
|
85
|
+
table: branchTable,
|
|
86
|
+
constraint: branchC,
|
|
87
|
+
}));
|
|
88
|
+
if (!branchC.validated) {
|
|
89
|
+
changes.push(new AlterTableValidateConstraint({
|
|
90
|
+
table: branchTable,
|
|
91
|
+
constraint: branchC,
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
// Ensure constraint comment is applied after re-creation
|
|
95
|
+
if (branchC.comment !== null) {
|
|
96
|
+
changes.push(new CreateCommentOnConstraint({
|
|
97
|
+
table: branchTable,
|
|
98
|
+
constraint: branchC,
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// Comment-only change on constraint
|
|
104
|
+
if (mainC.comment !== branchC.comment) {
|
|
105
|
+
if (branchC.comment === null) {
|
|
106
|
+
changes.push(new DropCommentOnConstraint({
|
|
107
|
+
table: mainTable,
|
|
108
|
+
constraint: mainC,
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
changes.push(new CreateCommentOnConstraint({
|
|
113
|
+
table: branchTable,
|
|
114
|
+
constraint: branchC,
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return changes;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Diff two sets of tables from main and branch catalogs.
|
|
124
|
+
*
|
|
125
|
+
* @param ctx - Context containing version, currentUser, and defaultPrivilegeState
|
|
126
|
+
* @param main - The tables in the main catalog.
|
|
127
|
+
* @param branch - The tables in the branch catalog.
|
|
128
|
+
* @returns A list of changes to apply to main to make it match branch.
|
|
129
|
+
*/
|
|
130
|
+
export function diffTables(ctx, main, branch) {
|
|
131
|
+
const { created, dropped, altered } = diffObjects(main, branch);
|
|
132
|
+
const changes = [];
|
|
133
|
+
for (const tableId of created) {
|
|
134
|
+
changes.push(new CreateTable({ table: branch[tableId] }));
|
|
135
|
+
const branchTable = branch[tableId];
|
|
136
|
+
// OWNER: If the table should be owned by someone other than the current user,
|
|
137
|
+
// emit ALTER TABLE ... OWNER TO after creation
|
|
138
|
+
if (branchTable.owner !== ctx.currentUser) {
|
|
139
|
+
changes.push(new AlterTableChangeOwner({
|
|
140
|
+
table: branchTable,
|
|
141
|
+
owner: branchTable.owner,
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
// ROW LEVEL SECURITY: If RLS should be enabled, emit ALTER TABLE ... ENABLE ROW LEVEL SECURITY
|
|
145
|
+
if (branchTable.row_security) {
|
|
146
|
+
changes.push(new AlterTableEnableRowLevelSecurity({ table: branchTable }));
|
|
147
|
+
}
|
|
148
|
+
// FORCE ROW LEVEL SECURITY: If force RLS should be enabled, emit ALTER TABLE ... FORCE ROW LEVEL SECURITY
|
|
149
|
+
if (branchTable.force_row_security) {
|
|
150
|
+
changes.push(new AlterTableForceRowLevelSecurity({ table: branchTable }));
|
|
151
|
+
}
|
|
152
|
+
changes.push(...createAlterConstraintChange(
|
|
153
|
+
// Create a dummy table with no constraints do diff constraints against
|
|
154
|
+
new Table({
|
|
155
|
+
...branchTable,
|
|
156
|
+
constraints: [],
|
|
157
|
+
}), branchTable));
|
|
158
|
+
// Table comment on creation
|
|
159
|
+
if (branchTable.comment !== null && branchTable.comment !== undefined) {
|
|
160
|
+
changes.push(new CreateCommentOnTable({ table: branchTable }));
|
|
161
|
+
}
|
|
162
|
+
// Column comments on creation
|
|
163
|
+
for (const col of branchTable.columns) {
|
|
164
|
+
if (col.comment !== null && col.comment !== undefined) {
|
|
165
|
+
changes.push(new CreateCommentOnColumn({ table: branchTable, column: col }));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// PRIVILEGES: For created objects, compare against default privileges state
|
|
169
|
+
// The migration script will run ALTER DEFAULT PRIVILEGES before CREATE (via constraint spec),
|
|
170
|
+
// so objects are created with the default privileges state in effect.
|
|
171
|
+
// We compare default privileges against desired privileges to generate REVOKE/GRANT statements
|
|
172
|
+
// needed to reach the final desired state.
|
|
173
|
+
const effectiveDefaults = ctx.defaultPrivilegeState.getEffectiveDefaults(ctx.currentUser, "table", branchTable.schema ?? "");
|
|
174
|
+
const desiredPrivileges = branchTable.privileges;
|
|
175
|
+
// Filter out owner privileges - owner always has ALL privileges implicitly
|
|
176
|
+
// and shouldn't be compared. Use the table owner as the reference.
|
|
177
|
+
const privilegeResults = diffPrivileges(effectiveDefaults, desiredPrivileges, branchTable.owner, ctx.mainRoles);
|
|
178
|
+
// Generate grant changes
|
|
179
|
+
for (const [grantee, result] of privilegeResults) {
|
|
180
|
+
if (result.grants.length > 0) {
|
|
181
|
+
const grantGroups = groupPrivilegesByColumns(result.grants);
|
|
182
|
+
for (const [, group] of grantGroups) {
|
|
183
|
+
for (const [grantable, privSet] of group.byGrant) {
|
|
184
|
+
const privileges = Array.from(privSet).map((priv) => ({
|
|
185
|
+
privilege: priv,
|
|
186
|
+
grantable,
|
|
187
|
+
}));
|
|
188
|
+
changes.push(new GrantTablePrivileges({
|
|
189
|
+
table: branchTable,
|
|
190
|
+
grantee,
|
|
191
|
+
privileges,
|
|
192
|
+
columns: group.columns,
|
|
193
|
+
version: ctx.version,
|
|
194
|
+
}));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// Generate revoke changes
|
|
199
|
+
if (result.revokes.length > 0) {
|
|
200
|
+
const revokeGroups = groupPrivilegesByColumns(result.revokes);
|
|
201
|
+
for (const [, group] of revokeGroups) {
|
|
202
|
+
const allPrivileges = new Set();
|
|
203
|
+
for (const [, privSet] of group.byGrant) {
|
|
204
|
+
for (const priv of privSet) {
|
|
205
|
+
allPrivileges.add(priv);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const privileges = Array.from(allPrivileges).map((priv) => ({
|
|
209
|
+
privilege: priv,
|
|
210
|
+
grantable: false,
|
|
211
|
+
}));
|
|
212
|
+
changes.push(new RevokeTablePrivileges({
|
|
213
|
+
table: branchTable,
|
|
214
|
+
grantee,
|
|
215
|
+
privileges,
|
|
216
|
+
columns: group.columns,
|
|
217
|
+
version: ctx.version,
|
|
218
|
+
}));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
// Generate revoke grant option changes
|
|
222
|
+
if (result.revokeGrantOption.length > 0) {
|
|
223
|
+
const revokeGrantGroups = new Map();
|
|
224
|
+
for (const r of result.revokeGrantOption) {
|
|
225
|
+
const originalPriv = effectiveDefaults.find((p) => p.grantee === grantee && p.privilege === r);
|
|
226
|
+
const key = originalPriv?.columns
|
|
227
|
+
? originalPriv.columns.sort().join(",")
|
|
228
|
+
: "";
|
|
229
|
+
if (!revokeGrantGroups.has(key)) {
|
|
230
|
+
revokeGrantGroups.set(key, {
|
|
231
|
+
columns: originalPriv?.columns
|
|
232
|
+
? [...originalPriv.columns]
|
|
233
|
+
: undefined,
|
|
234
|
+
privileges: new Set(),
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
const group = revokeGrantGroups.get(key);
|
|
238
|
+
if (!group)
|
|
239
|
+
continue;
|
|
240
|
+
group.privileges.add(r);
|
|
241
|
+
}
|
|
242
|
+
for (const [, group] of revokeGrantGroups) {
|
|
243
|
+
const privilegeNames = Array.from(group.privileges);
|
|
244
|
+
changes.push(new RevokeGrantOptionTablePrivileges({
|
|
245
|
+
table: branchTable,
|
|
246
|
+
grantee,
|
|
247
|
+
privilegeNames,
|
|
248
|
+
columns: group.columns,
|
|
249
|
+
version: ctx.version,
|
|
250
|
+
}));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
for (const tableId of dropped) {
|
|
256
|
+
changes.push(new DropTable({ table: main[tableId] }));
|
|
257
|
+
}
|
|
258
|
+
for (const tableId of altered) {
|
|
259
|
+
const mainTable = main[tableId];
|
|
260
|
+
const branchTable = branch[tableId];
|
|
261
|
+
// Dangerous operations (drop+create) are not performed by this tool.
|
|
262
|
+
// Only emit safe ALTER statements below.
|
|
263
|
+
// Only alterable properties changed - check each one
|
|
264
|
+
// PERSISTENCE (LOGGED/UNLOGGED)
|
|
265
|
+
if (mainTable.persistence !== branchTable.persistence) {
|
|
266
|
+
if (branchTable.persistence === "u" && mainTable.persistence === "p") {
|
|
267
|
+
changes.push(new AlterTableSetUnlogged({ table: mainTable }));
|
|
268
|
+
}
|
|
269
|
+
else if (branchTable.persistence === "p" &&
|
|
270
|
+
mainTable.persistence === "u") {
|
|
271
|
+
changes.push(new AlterTableSetLogged({ table: mainTable }));
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
// ROW LEVEL SECURITY
|
|
275
|
+
if (mainTable.row_security !== branchTable.row_security) {
|
|
276
|
+
if (branchTable.row_security) {
|
|
277
|
+
changes.push(new AlterTableEnableRowLevelSecurity({ table: mainTable }));
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
changes.push(new AlterTableDisableRowLevelSecurity({ table: mainTable }));
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
// FORCE ROW LEVEL SECURITY
|
|
284
|
+
if (mainTable.force_row_security !== branchTable.force_row_security) {
|
|
285
|
+
if (branchTable.force_row_security) {
|
|
286
|
+
changes.push(new AlterTableForceRowLevelSecurity({ table: mainTable }));
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
changes.push(new AlterTableNoForceRowLevelSecurity({ table: mainTable }));
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// STORAGE PARAMS (WITH (...))
|
|
293
|
+
if (!deepEqual(mainTable.options, branchTable.options)) {
|
|
294
|
+
const mainOpts = mainTable.options ?? [];
|
|
295
|
+
const branchOpts = branchTable.options ?? [];
|
|
296
|
+
// Always set branch options when provided
|
|
297
|
+
if (branchOpts.length > 0) {
|
|
298
|
+
changes.push(new AlterTableSetStorageParams({
|
|
299
|
+
table: mainTable,
|
|
300
|
+
options: branchOpts,
|
|
301
|
+
}));
|
|
302
|
+
}
|
|
303
|
+
// Reset any params that are present in main but absent in branch
|
|
304
|
+
if (mainOpts.length > 0) {
|
|
305
|
+
const mainNames = new Set(mainOpts.map((opt) => opt.split("=")[0]));
|
|
306
|
+
const branchNames = new Set(branchOpts.map((opt) => opt.split("=")[0]));
|
|
307
|
+
const removed = [];
|
|
308
|
+
for (const name of mainNames) {
|
|
309
|
+
if (!branchNames.has(name))
|
|
310
|
+
removed.push(name);
|
|
311
|
+
}
|
|
312
|
+
if (removed.length > 0) {
|
|
313
|
+
changes.push(new AlterTableResetStorageParams({
|
|
314
|
+
table: mainTable,
|
|
315
|
+
params: removed,
|
|
316
|
+
}));
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
// REPLICA IDENTITY
|
|
321
|
+
if (mainTable.replica_identity !== branchTable.replica_identity) {
|
|
322
|
+
// Skip when target is 'i' (USING INDEX) — handled by index changes
|
|
323
|
+
if (branchTable.replica_identity !== "i") {
|
|
324
|
+
changes.push(new AlterTableSetReplicaIdentity({
|
|
325
|
+
table: mainTable,
|
|
326
|
+
mode: branchTable.replica_identity,
|
|
327
|
+
}));
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
// OWNER
|
|
331
|
+
if (mainTable.owner !== branchTable.owner) {
|
|
332
|
+
changes.push(new AlterTableChangeOwner({
|
|
333
|
+
table: mainTable,
|
|
334
|
+
owner: branchTable.owner,
|
|
335
|
+
}));
|
|
336
|
+
}
|
|
337
|
+
// TABLE COMMENT (create/drop when comment changes)
|
|
338
|
+
if (mainTable.comment !== branchTable.comment) {
|
|
339
|
+
if (branchTable.comment === null) {
|
|
340
|
+
changes.push(new DropCommentOnTable({ table: mainTable }));
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
changes.push(new CreateCommentOnTable({ table: branchTable }));
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
// PARTITION ATTACH/DETACH
|
|
347
|
+
const mainIsPartition = Boolean(mainTable.parent_schema && mainTable.parent_name);
|
|
348
|
+
const branchIsPartition = Boolean(branchTable.parent_schema && branchTable.parent_name);
|
|
349
|
+
// Helper to resolve parent table from catalogs
|
|
350
|
+
const resolveParent = (catalog, schema, name) => catalog[`table:${schema}.${name}`];
|
|
351
|
+
if (!mainIsPartition && branchIsPartition) {
|
|
352
|
+
const table = resolveParent(branch, branchTable.parent_schema, branchTable.parent_name);
|
|
353
|
+
if (table) {
|
|
354
|
+
changes.push(new AlterTableAttachPartition({ table, partition: branchTable }));
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
else if (mainIsPartition && !branchIsPartition) {
|
|
358
|
+
const table = resolveParent(main, mainTable.parent_schema, mainTable.parent_name);
|
|
359
|
+
if (table) {
|
|
360
|
+
changes.push(new AlterTableDetachPartition({ table, partition: mainTable }));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
else if (mainIsPartition && branchIsPartition) {
|
|
364
|
+
const parentChanged = mainTable.parent_schema !== branchTable.parent_schema ||
|
|
365
|
+
mainTable.parent_name !== branchTable.parent_name;
|
|
366
|
+
const boundChanged = mainTable.partition_bound !== branchTable.partition_bound;
|
|
367
|
+
if (parentChanged || boundChanged) {
|
|
368
|
+
const oldParent = resolveParent(main, mainTable.parent_schema, mainTable.parent_name);
|
|
369
|
+
if (oldParent) {
|
|
370
|
+
changes.push(new AlterTableDetachPartition({
|
|
371
|
+
table: oldParent,
|
|
372
|
+
partition: mainTable,
|
|
373
|
+
}));
|
|
374
|
+
}
|
|
375
|
+
const newParent = resolveParent(branch, branchTable.parent_schema, branchTable.parent_name);
|
|
376
|
+
if (newParent) {
|
|
377
|
+
changes.push(new AlterTableAttachPartition({
|
|
378
|
+
table: newParent,
|
|
379
|
+
partition: branchTable,
|
|
380
|
+
}));
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
changes.push(...createAlterConstraintChange(mainTable, branchTable));
|
|
385
|
+
// COLUMNS
|
|
386
|
+
const mainCols = new Map(mainTable.columns.map((c) => [c.name, c]));
|
|
387
|
+
const branchCols = new Map(branchTable.columns.map((c) => [c.name, c]));
|
|
388
|
+
// Helper to get parent tables if this is a partition
|
|
389
|
+
// PostgreSQL automatically propagates column changes from parent to partitions,
|
|
390
|
+
// so we should skip changes on partitions when the parent has the same change
|
|
391
|
+
const getParentTables = () => {
|
|
392
|
+
if (!branchIsPartition ||
|
|
393
|
+
!branchTable.parent_schema ||
|
|
394
|
+
!branchTable.parent_name) {
|
|
395
|
+
return { parentMain: null, parentBranch: null };
|
|
396
|
+
}
|
|
397
|
+
const parentBranch = resolveParent(branch, branchTable.parent_schema, branchTable.parent_name);
|
|
398
|
+
const parentMain = resolveParent(main, branchTable.parent_schema, branchTable.parent_name);
|
|
399
|
+
return {
|
|
400
|
+
parentMain: parentMain ?? null,
|
|
401
|
+
parentBranch: parentBranch ?? null,
|
|
402
|
+
};
|
|
403
|
+
};
|
|
404
|
+
// Helper to check if parent has the same column property change
|
|
405
|
+
const parentHasSameColumnPropertyChange = (columnName, property) => {
|
|
406
|
+
const { parentMain, parentBranch } = getParentTables();
|
|
407
|
+
if (!parentMain || !parentBranch) {
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
const parentMainCol = parentMain.columns.find((c) => c.name === columnName);
|
|
411
|
+
const parentBranchCol = parentBranch.columns.find((c) => c.name === columnName);
|
|
412
|
+
const branchCol = branchCols.get(columnName);
|
|
413
|
+
const mainCol = mainCols.get(columnName);
|
|
414
|
+
if (!parentMainCol || !parentBranchCol || !branchCol || !mainCol) {
|
|
415
|
+
return false;
|
|
416
|
+
}
|
|
417
|
+
switch (property) {
|
|
418
|
+
case "type": {
|
|
419
|
+
const parentTypeChanged = parentMainCol.data_type_str !== parentBranchCol.data_type_str ||
|
|
420
|
+
parentMainCol.collation !== parentBranchCol.collation;
|
|
421
|
+
const partitionTypeChanged = mainCol.data_type_str !== branchCol.data_type_str ||
|
|
422
|
+
mainCol.collation !== branchCol.collation;
|
|
423
|
+
return (parentTypeChanged &&
|
|
424
|
+
partitionTypeChanged &&
|
|
425
|
+
parentBranchCol.data_type_str === branchCol.data_type_str &&
|
|
426
|
+
parentBranchCol.collation === branchCol.collation);
|
|
427
|
+
}
|
|
428
|
+
case "default": {
|
|
429
|
+
const parentDefaultChanged = parentMainCol.default !== parentBranchCol.default;
|
|
430
|
+
const partitionDefaultChanged = mainCol.default !== branchCol.default;
|
|
431
|
+
return (parentDefaultChanged &&
|
|
432
|
+
partitionDefaultChanged &&
|
|
433
|
+
parentBranchCol.default === branchCol.default);
|
|
434
|
+
}
|
|
435
|
+
case "not_null": {
|
|
436
|
+
const parentNotNullChanged = parentMainCol.not_null !== parentBranchCol.not_null;
|
|
437
|
+
const partitionNotNullChanged = mainCol.not_null !== branchCol.not_null;
|
|
438
|
+
return (parentNotNullChanged &&
|
|
439
|
+
partitionNotNullChanged &&
|
|
440
|
+
parentBranchCol.not_null === branchCol.not_null);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
// Helper to check if parent has the same column add/drop
|
|
445
|
+
const shouldSkipColumnAddDropOnPartition = (columnName, changeType) => {
|
|
446
|
+
const { parentMain, parentBranch } = getParentTables();
|
|
447
|
+
if (!parentMain || !parentBranch) {
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
const parentMainHasCol = parentMain.columns.some((c) => c.name === columnName);
|
|
451
|
+
const parentBranchHasCol = parentBranch.columns.some((c) => c.name === columnName);
|
|
452
|
+
if (changeType === "add") {
|
|
453
|
+
// Check if parent also has this column added and final states match
|
|
454
|
+
if (!parentMainHasCol && parentBranchHasCol) {
|
|
455
|
+
const parentBranchCol = parentBranch.columns.find((c) => c.name === columnName);
|
|
456
|
+
const branchCol = branchCols.get(columnName);
|
|
457
|
+
return (parentBranchCol !== undefined &&
|
|
458
|
+
branchCol !== undefined &&
|
|
459
|
+
parentBranchCol.data_type_str === branchCol.data_type_str &&
|
|
460
|
+
parentBranchCol.collation === branchCol.collation &&
|
|
461
|
+
parentBranchCol.default === branchCol.default &&
|
|
462
|
+
parentBranchCol.not_null === branchCol.not_null);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
// changeType === "drop"
|
|
467
|
+
// If parent is dropping the column, skip on partition
|
|
468
|
+
return parentMainHasCol && !parentBranchHasCol;
|
|
469
|
+
}
|
|
470
|
+
return false;
|
|
471
|
+
};
|
|
472
|
+
// Added columns
|
|
473
|
+
for (const [name, col] of branchCols) {
|
|
474
|
+
if (!mainCols.has(name)) {
|
|
475
|
+
// Skip if this is a partition and parent has the same column added
|
|
476
|
+
if (shouldSkipColumnAddDropOnPartition(name, "add")) {
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
changes.push(new AlterTableAddColumn({ table: branchTable, column: col }));
|
|
480
|
+
if (col.comment !== null && col.comment !== undefined) {
|
|
481
|
+
changes.push(new CreateCommentOnColumn({ table: branchTable, column: col }));
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
// Dropped columns
|
|
486
|
+
for (const [name, col] of mainCols) {
|
|
487
|
+
if (!branchCols.has(name)) {
|
|
488
|
+
// Skip if this is a partition and parent has the same column dropped
|
|
489
|
+
if (shouldSkipColumnAddDropOnPartition(name, "drop")) {
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
changes.push(new AlterTableDropColumn({ table: mainTable, column: col }));
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
// Altered columns
|
|
496
|
+
for (const [name, mainCol] of mainCols) {
|
|
497
|
+
const branchCol = branchCols.get(name);
|
|
498
|
+
if (!branchCol)
|
|
499
|
+
continue;
|
|
500
|
+
// TYPE or COLLATION change
|
|
501
|
+
if (mainCol.data_type_str !== branchCol.data_type_str ||
|
|
502
|
+
mainCol.collation !== branchCol.collation) {
|
|
503
|
+
// Skip if parent has the same type/collation change
|
|
504
|
+
if (!parentHasSameColumnPropertyChange(name, "type")) {
|
|
505
|
+
changes.push(new AlterTableAlterColumnType({
|
|
506
|
+
table: branchTable,
|
|
507
|
+
column: branchCol,
|
|
508
|
+
}));
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
// DEFAULT change
|
|
512
|
+
if (mainCol.default !== branchCol.default) {
|
|
513
|
+
// Skip if parent has the same default change
|
|
514
|
+
if (!parentHasSameColumnPropertyChange(name, "default")) {
|
|
515
|
+
if (branchCol.default === null) {
|
|
516
|
+
// Drop default value
|
|
517
|
+
changes.push(new AlterTableAlterColumnDropDefault({
|
|
518
|
+
table: branchTable,
|
|
519
|
+
column: branchCol,
|
|
520
|
+
}));
|
|
521
|
+
}
|
|
522
|
+
else {
|
|
523
|
+
// Set new default value
|
|
524
|
+
const isGeneratedColumn = branchCol.is_generated;
|
|
525
|
+
const isPostgresLowerThan17 = ctx.version < 170000;
|
|
526
|
+
if (isGeneratedColumn && isPostgresLowerThan17) {
|
|
527
|
+
// For generated columns in < PostgreSQL 17, we need to drop and recreate
|
|
528
|
+
// instead of using SET EXPRESSION AS for computed columns
|
|
529
|
+
// cf: https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=5d06e99a3
|
|
530
|
+
// cf: https://www.postgresql.org/docs/release/17.0/
|
|
531
|
+
// > Allow ALTER TABLE to change a column's generation expression
|
|
532
|
+
changes.push(new AlterTableDropColumn({
|
|
533
|
+
table: mainTable,
|
|
534
|
+
column: mainCol,
|
|
535
|
+
}));
|
|
536
|
+
changes.push(new AlterTableAddColumn({
|
|
537
|
+
table: branchTable,
|
|
538
|
+
column: branchCol,
|
|
539
|
+
}));
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
// Use standard SET DEFAULT or SET EXPRESSION AS for newer PostgreSQL versions
|
|
543
|
+
changes.push(new AlterTableAlterColumnSetDefault({
|
|
544
|
+
table: branchTable,
|
|
545
|
+
column: branchCol,
|
|
546
|
+
}));
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
// NOT NULL change
|
|
552
|
+
if (mainCol.not_null !== branchCol.not_null) {
|
|
553
|
+
// Skip if parent has the same NOT NULL change
|
|
554
|
+
if (!parentHasSameColumnPropertyChange(name, "not_null")) {
|
|
555
|
+
if (branchCol.not_null) {
|
|
556
|
+
changes.push(new AlterTableAlterColumnSetNotNull({
|
|
557
|
+
table: branchTable,
|
|
558
|
+
column: branchCol,
|
|
559
|
+
}));
|
|
560
|
+
}
|
|
561
|
+
else {
|
|
562
|
+
changes.push(new AlterTableAlterColumnDropNotNull({
|
|
563
|
+
table: branchTable,
|
|
564
|
+
column: branchCol,
|
|
565
|
+
}));
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
// COMMENT change on column
|
|
570
|
+
// Note: Comments are NOT automatically propagated from parent to partitions,
|
|
571
|
+
// so we should NOT skip comment changes even if parent has the same change
|
|
572
|
+
if (mainCol.comment !== branchCol.comment) {
|
|
573
|
+
if (branchCol.comment === null) {
|
|
574
|
+
changes.push(new DropCommentOnColumn({ table: mainTable, column: mainCol }));
|
|
575
|
+
}
|
|
576
|
+
else {
|
|
577
|
+
changes.push(new CreateCommentOnColumn({
|
|
578
|
+
table: branchTable,
|
|
579
|
+
column: branchCol,
|
|
580
|
+
}));
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
// PRIVILEGES (unified object and column privileges)
|
|
585
|
+
// Filter out owner privileges - owner always has ALL privileges implicitly
|
|
586
|
+
// and shouldn't be compared. Use branch owner as the reference.
|
|
587
|
+
const privilegeResults = diffPrivileges(mainTable.privileges, branchTable.privileges, branchTable.owner, ctx.mainRoles);
|
|
588
|
+
for (const [grantee, result] of privilegeResults) {
|
|
589
|
+
// Generate grant changes
|
|
590
|
+
if (result.grants.length > 0) {
|
|
591
|
+
const grantGroups = groupPrivilegesByColumns(result.grants);
|
|
592
|
+
for (const [, group] of grantGroups) {
|
|
593
|
+
for (const [grantable, privSet] of group.byGrant) {
|
|
594
|
+
const privileges = Array.from(privSet).map((priv) => ({
|
|
595
|
+
privilege: priv,
|
|
596
|
+
grantable,
|
|
597
|
+
}));
|
|
598
|
+
changes.push(new GrantTablePrivileges({
|
|
599
|
+
table: branchTable,
|
|
600
|
+
grantee,
|
|
601
|
+
privileges,
|
|
602
|
+
columns: group.columns,
|
|
603
|
+
version: ctx.version,
|
|
604
|
+
}));
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
// Generate revoke changes
|
|
609
|
+
if (result.revokes.length > 0) {
|
|
610
|
+
const revokeGroups = groupPrivilegesByColumns(result.revokes);
|
|
611
|
+
for (const [, group] of revokeGroups) {
|
|
612
|
+
// Collapse all grantable groups into a single revoke (grantable: false)
|
|
613
|
+
const allPrivileges = new Set();
|
|
614
|
+
for (const [, privSet] of group.byGrant) {
|
|
615
|
+
for (const priv of privSet) {
|
|
616
|
+
allPrivileges.add(priv);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
const privileges = Array.from(allPrivileges).map((priv) => ({
|
|
620
|
+
privilege: priv,
|
|
621
|
+
grantable: false,
|
|
622
|
+
}));
|
|
623
|
+
changes.push(new RevokeTablePrivileges({
|
|
624
|
+
table: mainTable,
|
|
625
|
+
grantee,
|
|
626
|
+
privileges,
|
|
627
|
+
columns: group.columns,
|
|
628
|
+
version: ctx.version,
|
|
629
|
+
}));
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
// Generate revoke grant option changes
|
|
633
|
+
if (result.revokeGrantOption.length > 0) {
|
|
634
|
+
const revokeGrantGroups = new Map();
|
|
635
|
+
for (const r of result.revokeGrantOption) {
|
|
636
|
+
// For revoke grant option, we need to find the columns from the original privilege
|
|
637
|
+
const originalPriv = mainTable.privileges.find((p) => p.grantee === grantee && p.privilege === r);
|
|
638
|
+
const key = originalPriv?.columns
|
|
639
|
+
? originalPriv.columns.sort().join(",")
|
|
640
|
+
: "";
|
|
641
|
+
if (!revokeGrantGroups.has(key)) {
|
|
642
|
+
revokeGrantGroups.set(key, {
|
|
643
|
+
columns: originalPriv?.columns
|
|
644
|
+
? [...originalPriv.columns]
|
|
645
|
+
: undefined,
|
|
646
|
+
privileges: new Set(),
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
const group = revokeGrantGroups.get(key);
|
|
650
|
+
if (!group)
|
|
651
|
+
continue;
|
|
652
|
+
group.privileges.add(r);
|
|
653
|
+
}
|
|
654
|
+
for (const [, group] of revokeGrantGroups) {
|
|
655
|
+
const privilegeNames = Array.from(group.privileges);
|
|
656
|
+
changes.push(new RevokeGrantOptionTablePrivileges({
|
|
657
|
+
table: mainTable,
|
|
658
|
+
grantee,
|
|
659
|
+
privilegeNames,
|
|
660
|
+
columns: group.columns,
|
|
661
|
+
version: ctx.version,
|
|
662
|
+
}));
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
return changes;
|
|
668
|
+
}
|