@supabase/pg-delta 1.0.0-alpha.4 → 1.0.0-alpha.6
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 +40 -23
- package/dist/cli/app.js +26 -3
- package/dist/cli/bin/cli.js +5 -0
- package/dist/cli/commands/catalog-export.d.ts +5 -0
- package/dist/cli/commands/catalog-export.js +64 -0
- package/dist/cli/commands/declarative-apply.d.ts +6 -0
- package/dist/cli/commands/declarative-apply.js +288 -0
- package/dist/cli/commands/declarative-export.d.ts +5 -0
- package/dist/cli/commands/declarative-export.js +245 -0
- package/dist/cli/commands/plan.js +19 -6
- package/dist/cli/exit-code.d.ts +2 -0
- package/dist/cli/exit-code.js +7 -0
- package/dist/cli/formatters/tree/tree.js +3 -2
- package/dist/cli/utils/apply-display.d.ts +52 -0
- package/dist/cli/utils/apply-display.js +183 -0
- package/dist/cli/utils/export-display.d.ts +43 -0
- package/dist/cli/utils/export-display.js +202 -0
- package/dist/cli/utils/resolve-input.d.ts +7 -0
- package/dist/cli/utils/resolve-input.js +13 -0
- package/dist/core/catalog-export/index.d.ts +11 -0
- package/dist/core/catalog-export/index.js +10 -0
- package/dist/core/catalog.diff.d.ts +1 -0
- package/dist/core/catalog.diff.js +64 -48
- package/dist/core/catalog.model.d.ts +14 -1
- package/dist/core/catalog.model.js +103 -1
- package/dist/core/catalog.snapshot.d.ts +66 -0
- package/dist/core/catalog.snapshot.js +206 -0
- package/dist/core/declarative-apply/discover-sql.d.ts +18 -0
- package/dist/core/declarative-apply/discover-sql.js +86 -0
- package/dist/core/declarative-apply/extract-catalog-providers.d.ts +23 -0
- package/dist/core/declarative-apply/extract-catalog-providers.js +159 -0
- package/dist/core/declarative-apply/index.d.ts +49 -0
- package/dist/core/declarative-apply/index.js +134 -0
- package/dist/core/declarative-apply/round-apply.d.ts +100 -0
- package/dist/core/declarative-apply/round-apply.js +378 -0
- package/dist/core/export/file-mapper.d.ts +71 -0
- package/dist/core/export/file-mapper.js +474 -0
- package/dist/core/export/grouper.d.ts +13 -0
- package/dist/core/export/grouper.js +76 -0
- package/dist/core/export/index.d.ts +45 -0
- package/dist/core/export/index.js +63 -0
- package/dist/core/export/types.d.ts +84 -0
- package/dist/core/export/types.js +25 -0
- package/dist/core/fixtures/empty-catalogs/postgres-15-16-baseline.json +287 -0
- package/dist/core/integrations/filter/dsl.d.ts +38 -1
- package/dist/core/integrations/filter/dsl.js +20 -2
- package/dist/core/integrations/filter/extractors.js +42 -0
- package/dist/core/integrations/integration-dsl.d.ts +10 -0
- package/dist/core/integrations/supabase.d.ts +8 -0
- package/dist/core/integrations/supabase.js +9 -0
- package/dist/core/objects/aggregate/aggregate.diff.d.ts +2 -8
- package/dist/core/objects/aggregate/aggregate.diff.js +16 -70
- package/dist/core/objects/aggregate/aggregate.model.d.ts +8 -8
- package/dist/core/objects/aggregate/aggregate.model.js +1 -1
- package/dist/core/objects/aggregate/changes/aggregate.create.js +1 -1
- package/dist/core/objects/aggregate/changes/aggregate.drop.js +1 -1
- package/dist/core/objects/base.privilege-diff.d.ts +38 -13
- package/dist/core/objects/base.privilege-diff.js +104 -22
- package/dist/core/objects/base.privilege.d.ts +1 -0
- package/dist/core/objects/base.privilege.js +9 -2
- package/dist/core/objects/collation/collation.diff.d.ts +2 -3
- package/dist/core/objects/diff-context.d.ts +15 -0
- package/dist/core/objects/diff-context.js +1 -0
- package/dist/core/objects/domain/changes/domain.create.js +4 -2
- package/dist/core/objects/domain/domain.diff.d.ts +2 -8
- package/dist/core/objects/domain/domain.diff.js +16 -77
- package/dist/core/objects/domain/domain.model.js +1 -1
- package/dist/core/objects/event-trigger/event-trigger.diff.d.ts +2 -3
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.diff.d.ts +2 -8
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.diff.js +13 -77
- package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.model.js +2 -2
- package/dist/core/objects/foreign-data-wrapper/foreign-table/foreign-table.diff.d.ts +2 -8
- package/dist/core/objects/foreign-data-wrapper/foreign-table/foreign-table.diff.js +16 -77
- package/dist/core/objects/foreign-data-wrapper/foreign-table/foreign-table.model.js +1 -1
- package/dist/core/objects/foreign-data-wrapper/server/server.diff.d.ts +2 -8
- package/dist/core/objects/foreign-data-wrapper/server/server.diff.js +13 -77
- package/dist/core/objects/language/language.diff.d.ts +2 -5
- package/dist/core/objects/language/language.diff.js +7 -39
- package/dist/core/objects/materialized-view/materialized-view.diff.d.ts +2 -8
- package/dist/core/objects/materialized-view/materialized-view.diff.js +16 -158
- package/dist/core/objects/materialized-view/materialized-view.model.d.ts +3 -3
- package/dist/core/objects/materialized-view/materialized-view.model.js +1 -1
- package/dist/core/objects/procedure/changes/procedure.alter.js +12 -12
- package/dist/core/objects/procedure/procedure.diff.d.ts +2 -8
- package/dist/core/objects/procedure/procedure.diff.js +16 -77
- package/dist/core/objects/procedure/procedure.model.d.ts +9 -9
- package/dist/core/objects/procedure/procedure.model.js +1 -1
- package/dist/core/objects/publication/changes/publication.alter.d.ts +0 -9
- package/dist/core/objects/publication/changes/publication.alter.js +0 -14
- package/dist/core/objects/publication/changes/publication.types.d.ts +2 -2
- package/dist/core/objects/publication/publication.diff.d.ts +2 -3
- package/dist/core/objects/publication/publication.diff.js +8 -13
- package/dist/core/objects/rls-policy/changes/rls-policy.alter.js +3 -3
- package/dist/core/objects/rls-policy/rls-policy.model.d.ts +2 -2
- package/dist/core/objects/role/role.diff.js +22 -1
- package/dist/core/objects/role/role.model.d.ts +4 -3
- package/dist/core/objects/role/role.model.js +118 -12
- package/dist/core/objects/rule/rule.model.d.ts +1 -1
- package/dist/core/objects/schema/schema.diff.d.ts +2 -8
- package/dist/core/objects/schema/schema.diff.js +16 -77
- package/dist/core/objects/schema/schema.model.js +1 -1
- package/dist/core/objects/sequence/sequence.diff.d.ts +2 -8
- package/dist/core/objects/sequence/sequence.diff.js +16 -79
- package/dist/core/objects/sequence/sequence.model.js +1 -1
- package/dist/core/objects/subscription/subscription.diff.d.ts +2 -3
- package/dist/core/objects/table/changes/table.create.js +3 -0
- package/dist/core/objects/table/table.diff.d.ts +2 -8
- package/dist/core/objects/table/table.diff.js +26 -157
- package/dist/core/objects/table/table.model.d.ts +23 -22
- package/dist/core/objects/table/table.model.js +1 -1
- package/dist/core/objects/trigger/changes/trigger.create.js +2 -4
- package/dist/core/objects/trigger/trigger.model.d.ts +8 -0
- package/dist/core/objects/trigger/trigger.model.js +11 -0
- package/dist/core/objects/type/composite-type/composite-type.diff.d.ts +2 -8
- package/dist/core/objects/type/composite-type/composite-type.diff.js +16 -77
- package/dist/core/objects/type/composite-type/composite-type.model.d.ts +3 -3
- package/dist/core/objects/type/composite-type/composite-type.model.js +2 -1
- package/dist/core/objects/type/enum/enum.diff.d.ts +2 -8
- package/dist/core/objects/type/enum/enum.diff.js +25 -112
- package/dist/core/objects/type/enum/enum.model.js +1 -1
- package/dist/core/objects/type/range/changes/range.create.js +6 -3
- package/dist/core/objects/type/range/range.diff.d.ts +2 -8
- package/dist/core/objects/type/range/range.diff.js +16 -77
- package/dist/core/objects/type/range/range.model.js +1 -1
- package/dist/core/objects/view/view.diff.d.ts +2 -8
- package/dist/core/objects/view/view.diff.js +16 -158
- package/dist/core/objects/view/view.model.d.ts +18 -4
- package/dist/core/objects/view/view.model.js +3 -13
- package/dist/core/plan/apply.js +9 -26
- package/dist/core/plan/create.d.ts +19 -6
- package/dist/core/plan/create.js +134 -174
- package/dist/core/plan/serialize.js +16 -4
- package/dist/core/plan/sql-format/fixtures.js +3 -5
- package/dist/core/plan/sql-format/keyword-case.js +26 -1
- package/dist/core/plan/ssl-config.d.ts +32 -0
- package/dist/core/plan/ssl-config.js +115 -0
- package/dist/core/plan/types.d.ts +6 -0
- package/dist/core/postgres-config.d.ts +14 -0
- package/dist/core/postgres-config.js +53 -2
- package/dist/core/sort/graph-builder.js +10 -0
- package/dist/core/sort/logical-sort.js +31 -23
- package/dist/core/test-utils/assert-valid-sql.d.ts +10 -0
- package/dist/core/test-utils/assert-valid-sql.js +19 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -1
- package/package.json +21 -4
- package/src/cli/app.ts +27 -3
- package/src/cli/bin/cli.ts +6 -0
- package/src/cli/commands/catalog-export.ts +78 -0
- package/src/cli/commands/declarative-apply.diagnostics.test.ts +77 -0
- package/src/cli/commands/declarative-apply.ts +380 -0
- package/src/cli/commands/declarative-export.ts +330 -0
- package/src/cli/commands/plan.ts +28 -7
- package/src/cli/exit-code.test.ts +19 -0
- package/src/cli/exit-code.ts +7 -0
- package/src/cli/formatters/tree/tree.ts +3 -2
- package/src/cli/utils/apply-display.test.ts +348 -0
- package/src/cli/utils/apply-display.ts +238 -0
- package/src/cli/utils/export-display.test.ts +103 -0
- package/src/cli/utils/export-display.ts +275 -0
- package/src/cli/utils/integrations.test.ts +44 -0
- package/src/cli/utils/resolve-input.test.ts +38 -0
- package/src/cli/utils/resolve-input.ts +17 -0
- package/src/core/catalog-export/index.ts +20 -0
- package/src/core/catalog.diff.ts +79 -78
- package/src/core/catalog.model.test.ts +122 -0
- package/src/core/catalog.model.ts +127 -1
- package/src/core/catalog.snapshot.test.ts +464 -0
- package/src/core/catalog.snapshot.ts +289 -0
- package/src/core/declarative-apply/discover-sql.test.ts +103 -0
- package/src/core/declarative-apply/discover-sql.ts +107 -0
- package/src/core/declarative-apply/extract-catalog-providers.ts +220 -0
- package/src/core/declarative-apply/index.test.ts +67 -0
- package/src/core/declarative-apply/index.ts +205 -0
- package/src/core/declarative-apply/round-apply.test.ts +504 -0
- package/src/core/declarative-apply/round-apply.ts +562 -0
- package/src/core/expand-replace-dependencies.test.ts +70 -0
- package/src/core/export/file-mapper.test.ts +816 -0
- package/src/core/export/file-mapper.ts +574 -0
- package/src/core/export/grouper.ts +108 -0
- package/src/core/export/index.ts +129 -0
- package/src/core/export/types.ts +104 -0
- package/src/core/fixtures/empty-catalogs/postgres-15-16-baseline.json +287 -0
- package/src/core/integrations/filter/dsl.test.ts +211 -0
- package/src/core/integrations/filter/dsl.ts +65 -3
- package/src/core/integrations/filter/extractors.test.ts +244 -0
- package/src/core/integrations/filter/extractors.ts +42 -0
- package/src/core/integrations/integration-dsl.ts +10 -0
- package/src/core/integrations/serialize/dsl.test.ts +91 -0
- package/src/core/integrations/supabase.ts +9 -0
- package/src/core/objects/aggregate/aggregate.diff.ts +39 -95
- package/src/core/objects/aggregate/aggregate.model.ts +1 -1
- package/src/core/objects/aggregate/changes/aggregate.alter.test.ts +3 -1
- package/src/core/objects/aggregate/changes/aggregate.comment.test.ts +5 -2
- package/src/core/objects/aggregate/changes/aggregate.create.test.ts +6 -3
- package/src/core/objects/aggregate/changes/aggregate.create.ts +1 -1
- package/src/core/objects/aggregate/changes/aggregate.drop.test.ts +7 -3
- package/src/core/objects/aggregate/changes/aggregate.drop.ts +1 -1
- package/src/core/objects/aggregate/changes/aggregate.privilege.test.ts +9 -3
- package/src/core/objects/base.privilege-diff.ts +178 -30
- package/src/core/objects/base.privilege.ts +9 -2
- package/src/core/objects/collation/changes/collation.alter.test.ts +7 -2
- package/src/core/objects/collation/changes/collation.create.test.ts +7 -2
- package/src/core/objects/collation/changes/collation.drop.test.ts +4 -1
- package/src/core/objects/collation/collation.diff.test.ts +9 -12
- package/src/core/objects/collation/collation.diff.ts +2 -1
- package/src/core/objects/diff-context.ts +16 -0
- package/src/core/objects/domain/changes/domain.alter.test.ts +28 -9
- package/src/core/objects/domain/changes/domain.create.test.ts +32 -2
- package/src/core/objects/domain/changes/domain.create.ts +7 -1
- package/src/core/objects/domain/changes/domain.drop.test.ts +4 -1
- package/src/core/objects/domain/domain.diff.ts +39 -102
- package/src/core/objects/domain/domain.model.ts +1 -1
- package/src/core/objects/event-trigger/changes/event-trigger.alter.test.ts +10 -3
- package/src/core/objects/event-trigger/changes/event-trigger.create.test.ts +4 -1
- package/src/core/objects/event-trigger/changes/event-trigger.drop.test.ts +4 -1
- package/src/core/objects/event-trigger/event-trigger.diff.test.ts +12 -7
- package/src/core/objects/event-trigger/event-trigger.diff.ts +2 -1
- package/src/core/objects/extension/changes/extension.alter.test.ts +7 -2
- package/src/core/objects/extension/changes/extension.create.test.ts +4 -1
- package/src/core/objects/extension/changes/extension.drop.test.ts +4 -1
- package/src/core/objects/extension/extension.model.test.ts +98 -0
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.alter.test.ts +16 -5
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.create.test.ts +51 -16
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.drop.test.ts +4 -1
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.diff.test.ts +111 -4
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.diff.ts +31 -101
- package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.model.ts +2 -2
- package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.alter.test.ts +46 -15
- package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.create.test.ts +13 -4
- package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.drop.test.ts +4 -1
- package/src/core/objects/foreign-data-wrapper/foreign-table/foreign-table.diff.ts +39 -102
- package/src/core/objects/foreign-data-wrapper/foreign-table/foreign-table.model.ts +1 -1
- package/src/core/objects/foreign-data-wrapper/server/changes/server.alter.test.ts +22 -7
- package/src/core/objects/foreign-data-wrapper/server/changes/server.create.test.ts +19 -6
- package/src/core/objects/foreign-data-wrapper/server/changes/server.drop.test.ts +4 -1
- package/src/core/objects/foreign-data-wrapper/server/server.diff.test.ts +95 -0
- package/src/core/objects/foreign-data-wrapper/server/server.diff.ts +31 -101
- package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.alter.test.ts +13 -4
- package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.create.test.ts +16 -5
- package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.drop.test.ts +10 -3
- package/src/core/objects/index/changes/index.alter.test.ts +13 -4
- package/src/core/objects/index/changes/index.create.test.ts +4 -1
- package/src/core/objects/index/changes/index.drop.test.ts +4 -1
- package/src/core/objects/language/changes/language.alter.test.ts +4 -1
- package/src/core/objects/language/changes/language.create.test.ts +4 -1
- package/src/core/objects/language/changes/language.drop.test.ts +4 -1
- package/src/core/objects/language/language.diff.test.ts +86 -4
- package/src/core/objects/language/language.diff.ts +17 -49
- package/src/core/objects/materialized-view/changes/materialized-view.alter.test.ts +10 -3
- package/src/core/objects/materialized-view/changes/materialized-view.create.test.ts +7 -2
- package/src/core/objects/materialized-view/changes/materialized-view.drop.test.ts +4 -1
- package/src/core/objects/materialized-view/materialized-view.diff.test.ts +162 -0
- package/src/core/objects/materialized-view/materialized-view.diff.ts +41 -191
- package/src/core/objects/materialized-view/materialized-view.model.ts +1 -1
- package/src/core/objects/procedure/changes/procedure.alter.test.ts +121 -49
- package/src/core/objects/procedure/changes/procedure.alter.ts +15 -12
- package/src/core/objects/procedure/changes/procedure.create.test.ts +4 -1
- package/src/core/objects/procedure/changes/procedure.drop.test.ts +7 -2
- package/src/core/objects/procedure/procedure.diff.ts +39 -102
- package/src/core/objects/procedure/procedure.model.ts +1 -1
- package/src/core/objects/publication/changes/publication.alter.test.ts +15 -21
- package/src/core/objects/publication/changes/publication.alter.ts +0 -18
- package/src/core/objects/publication/changes/publication.comment.test.ts +5 -2
- package/src/core/objects/publication/changes/publication.create.test.ts +5 -2
- package/src/core/objects/publication/changes/publication.drop.test.ts +3 -1
- package/src/core/objects/publication/changes/publication.types.ts +0 -2
- package/src/core/objects/publication/publication.diff.test.ts +24 -19
- package/src/core/objects/publication/publication.diff.ts +9 -15
- package/src/core/objects/rls-policy/changes/rls-policy.alter.test.ts +31 -14
- package/src/core/objects/rls-policy/changes/rls-policy.alter.ts +3 -3
- package/src/core/objects/rls-policy/changes/rls-policy.create.test.ts +10 -3
- package/src/core/objects/rls-policy/changes/rls-policy.drop.test.ts +4 -1
- package/src/core/objects/role/changes/role.alter.test.ts +31 -15
- package/src/core/objects/role/changes/role.create.test.ts +6 -2
- package/src/core/objects/role/changes/role.drop.test.ts +4 -1
- package/src/core/objects/role/role.diff.test.ts +235 -0
- package/src/core/objects/role/role.diff.ts +21 -1
- package/src/core/objects/role/role.model.ts +122 -14
- package/src/core/objects/rule/changes/rule.alter.test.ts +7 -3
- package/src/core/objects/rule/changes/rule.comment.test.ts +5 -2
- package/src/core/objects/rule/changes/rule.create.test.ts +6 -2
- package/src/core/objects/rule/changes/rule.drop.test.ts +3 -1
- package/src/core/objects/schema/changes/schema.alter.test.ts +4 -1
- package/src/core/objects/schema/changes/schema.create.test.ts +4 -1
- package/src/core/objects/schema/changes/schema.drop.test.ts +4 -1
- package/src/core/objects/schema/schema.diff.ts +39 -102
- package/src/core/objects/schema/schema.model.ts +1 -1
- package/src/core/objects/sequence/changes/sequence.alter.test.ts +11 -5
- package/src/core/objects/sequence/changes/sequence.create.test.ts +8 -3
- package/src/core/objects/sequence/changes/sequence.drop.test.ts +4 -1
- package/src/core/objects/sequence/sequence.diff.test.ts +114 -0
- package/src/core/objects/sequence/sequence.diff.ts +39 -104
- package/src/core/objects/sequence/sequence.model.ts +1 -1
- package/src/core/objects/subscription/changes/subscription.alter.test.ts +15 -5
- package/src/core/objects/subscription/changes/subscription.comment.test.ts +5 -2
- package/src/core/objects/subscription/changes/subscription.create.test.ts +5 -2
- package/src/core/objects/subscription/changes/subscription.drop.test.ts +3 -1
- package/src/core/objects/subscription/subscription.diff.test.ts +16 -11
- package/src/core/objects/subscription/subscription.diff.ts +2 -1
- package/src/core/objects/table/changes/table.alter.test.ts +38 -15
- package/src/core/objects/table/changes/table.create.test.ts +41 -3
- package/src/core/objects/table/changes/table.create.ts +4 -0
- package/src/core/objects/table/changes/table.drop.test.ts +3 -1
- package/src/core/objects/table/table.diff.test.ts +157 -0
- package/src/core/objects/table/table.diff.ts +54 -190
- package/src/core/objects/table/table.model.ts +1 -1
- package/src/core/objects/trigger/changes/trigger.alter.test.ts +8 -4
- package/src/core/objects/trigger/changes/trigger.create.test.ts +5 -1
- package/src/core/objects/trigger/changes/trigger.create.ts +7 -4
- package/src/core/objects/trigger/changes/trigger.drop.test.ts +5 -1
- package/src/core/objects/trigger/trigger.diff.test.ts +1 -0
- package/src/core/objects/trigger/trigger.model.ts +12 -0
- package/src/core/objects/type/composite-type/changes/composite-type.alter.test.ts +10 -4
- package/src/core/objects/type/composite-type/changes/composite-type.create.test.ts +7 -2
- package/src/core/objects/type/composite-type/changes/composite-type.drop.test.ts +4 -1
- package/src/core/objects/type/composite-type/composite-type.diff.test.ts +78 -0
- package/src/core/objects/type/composite-type/composite-type.diff.ts +39 -101
- package/src/core/objects/type/composite-type/composite-type.model.ts +2 -1
- package/src/core/objects/type/enum/changes/enum.alter.test.ts +14 -5
- package/src/core/objects/type/enum/changes/enum.create.test.ts +4 -1
- package/src/core/objects/type/enum/changes/enum.drop.test.ts +4 -1
- package/src/core/objects/type/enum/enum.diff.test.ts +181 -0
- package/src/core/objects/type/enum/enum.diff.ts +58 -146
- package/src/core/objects/type/enum/enum.model.ts +1 -1
- package/src/core/objects/type/range/changes/range.alter.test.ts +3 -1
- package/src/core/objects/type/range/changes/range.create.test.ts +5 -2
- package/src/core/objects/type/range/changes/range.create.ts +6 -2
- package/src/core/objects/type/range/changes/range.drop.test.ts +3 -1
- package/src/core/objects/type/range/range.diff.test.ts +77 -0
- package/src/core/objects/type/range/range.diff.ts +39 -101
- package/src/core/objects/type/range/range.model.ts +1 -1
- package/src/core/objects/view/changes/view.alter.test.ts +8 -3
- package/src/core/objects/view/changes/view.create.test.ts +7 -2
- package/src/core/objects/view/changes/view.drop.test.ts +4 -1
- package/src/core/objects/view/view.diff.test.ts +82 -0
- package/src/core/objects/view/view.diff.ts +41 -191
- package/src/core/objects/view/view.model.ts +3 -17
- package/src/core/plan/apply.ts +9 -27
- package/src/core/plan/create.ts +173 -237
- package/src/core/plan/serialize.test.ts +317 -0
- package/src/core/plan/serialize.ts +18 -4
- package/src/core/plan/sql-format/fixtures.ts +2 -5
- package/src/core/plan/sql-format/format-lowercase-coverage.test.ts +52 -0
- package/src/core/plan/sql-format/format-off.test.ts +14 -17
- package/src/core/plan/sql-format/format-pretty-lower-leading.test.ts +27 -22
- package/src/core/plan/sql-format/format-pretty-narrow.test.ts +17 -21
- package/src/core/plan/sql-format/format-pretty-preserve.test.ts +25 -20
- package/src/core/plan/sql-format/format-pretty-upper.test.ts +23 -20
- package/src/core/plan/sql-format/keyword-case.ts +36 -1
- package/src/core/plan/ssl-config.ts +172 -0
- package/src/core/plan/types.ts +6 -0
- package/src/core/postgres-config.ts +71 -2
- package/src/core/sort/graph-builder.ts +12 -0
- package/src/core/sort/logical-sort.test.ts +371 -0
- package/src/core/sort/logical-sort.ts +32 -25
- package/src/core/sort/topological-sort.test.ts +275 -0
- package/src/core/test-utils/assert-valid-sql.ts +20 -0
- package/src/index.ts +26 -2
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type { DefaultPrivilegeState } from "../base.default-privileges.ts";
|
|
2
1
|
import { diffObjects } from "../base.diff.ts";
|
|
3
2
|
import {
|
|
4
3
|
diffPrivileges,
|
|
4
|
+
emitObjectPrivilegeChanges,
|
|
5
5
|
filterPublicBuiltInDefaults,
|
|
6
|
-
groupPrivilegesByGrantable,
|
|
7
6
|
} from "../base.privilege-diff.ts";
|
|
8
|
-
import type {
|
|
7
|
+
import type { ObjectDiffContext } from "../diff-context.ts";
|
|
9
8
|
import { deepEqual, hasNonAlterableChanges } from "../utils.ts";
|
|
10
9
|
import {
|
|
11
10
|
AlterProcedureChangeOwner,
|
|
@@ -39,12 +38,10 @@ import type { Procedure } from "./procedure.model.ts";
|
|
|
39
38
|
* @returns A list of changes to apply to main to make it match branch.
|
|
40
39
|
*/
|
|
41
40
|
export function diffProcedures(
|
|
42
|
-
ctx:
|
|
43
|
-
|
|
44
|
-
currentUser
|
|
45
|
-
|
|
46
|
-
mainRoles: Record<string, Role>;
|
|
47
|
-
},
|
|
41
|
+
ctx: Pick<
|
|
42
|
+
ObjectDiffContext,
|
|
43
|
+
"version" | "currentUser" | "defaultPrivilegeState"
|
|
44
|
+
>,
|
|
48
45
|
main: Record<string, Procedure>,
|
|
49
46
|
branch: Record<string, Procedure>,
|
|
50
47
|
): ProcedureChange[] {
|
|
@@ -81,6 +78,10 @@ export function diffProcedures(
|
|
|
81
78
|
"procedure",
|
|
82
79
|
proc.schema ?? "",
|
|
83
80
|
);
|
|
81
|
+
const creatorFilteredDefaults =
|
|
82
|
+
proc.owner !== ctx.currentUser
|
|
83
|
+
? effectiveDefaults.filter((p) => p.grantee !== ctx.currentUser)
|
|
84
|
+
: effectiveDefaults;
|
|
84
85
|
// Filter out PUBLIC's built-in default EXECUTE privilege (PostgreSQL grants it automatically)
|
|
85
86
|
// Reference: https://www.postgresql.org/docs/17/ddl-priv.html Table 5.2
|
|
86
87
|
// This prevents generating unnecessary "GRANT EXECUTE TO PUBLIC" statements
|
|
@@ -92,57 +93,25 @@ export function diffProcedures(
|
|
|
92
93
|
// and shouldn't be compared. Note: we use the final owner (proc.owner), not the
|
|
93
94
|
// current user, because ownership change happens before privilege diffing.
|
|
94
95
|
const privilegeResults = diffPrivileges(
|
|
95
|
-
|
|
96
|
+
filterPublicBuiltInDefaults("procedure", creatorFilteredDefaults),
|
|
96
97
|
desiredPrivileges,
|
|
97
98
|
proc.owner,
|
|
98
|
-
ctx.mainRoles,
|
|
99
99
|
);
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Generate revoke changes
|
|
119
|
-
if (result.revokes.length > 0) {
|
|
120
|
-
const revokeGroups = groupPrivilegesByGrantable(result.revokes);
|
|
121
|
-
for (const [grantable, list] of revokeGroups) {
|
|
122
|
-
void grantable;
|
|
123
|
-
changes.push(
|
|
124
|
-
new RevokeProcedurePrivileges({
|
|
125
|
-
procedure: proc,
|
|
126
|
-
grantee,
|
|
127
|
-
privileges: list,
|
|
128
|
-
version: ctx.version,
|
|
129
|
-
}),
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Generate revoke grant option changes
|
|
135
|
-
if (result.revokeGrantOption.length > 0) {
|
|
136
|
-
changes.push(
|
|
137
|
-
new RevokeGrantOptionProcedurePrivileges({
|
|
138
|
-
procedure: proc,
|
|
139
|
-
grantee,
|
|
140
|
-
privilegeNames: result.revokeGrantOption,
|
|
141
|
-
version: ctx.version,
|
|
142
|
-
}),
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
101
|
+
changes.push(
|
|
102
|
+
...(emitObjectPrivilegeChanges(
|
|
103
|
+
privilegeResults,
|
|
104
|
+
proc,
|
|
105
|
+
proc,
|
|
106
|
+
"procedure",
|
|
107
|
+
{
|
|
108
|
+
Grant: GrantProcedurePrivileges,
|
|
109
|
+
Revoke: RevokeProcedurePrivileges,
|
|
110
|
+
RevokeGrantOption: RevokeGrantOptionProcedurePrivileges,
|
|
111
|
+
},
|
|
112
|
+
ctx.version,
|
|
113
|
+
) as ProcedureChange[]),
|
|
114
|
+
);
|
|
146
115
|
}
|
|
147
116
|
|
|
148
117
|
for (const procedureId of dropped) {
|
|
@@ -349,54 +318,22 @@ export function diffProcedures(
|
|
|
349
318
|
mainPrivilegesFiltered,
|
|
350
319
|
branchPrivilegesFiltered,
|
|
351
320
|
branchProcedure.owner,
|
|
352
|
-
ctx.mainRoles,
|
|
353
321
|
);
|
|
354
322
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
// Generate revoke changes
|
|
373
|
-
if (result.revokes.length > 0) {
|
|
374
|
-
const revokeGroups = groupPrivilegesByGrantable(result.revokes);
|
|
375
|
-
for (const [grantable, list] of revokeGroups) {
|
|
376
|
-
void grantable;
|
|
377
|
-
changes.push(
|
|
378
|
-
new RevokeProcedurePrivileges({
|
|
379
|
-
procedure: mainProcedure,
|
|
380
|
-
grantee,
|
|
381
|
-
privileges: list,
|
|
382
|
-
version: ctx.version,
|
|
383
|
-
}),
|
|
384
|
-
);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
// Generate revoke grant option changes
|
|
389
|
-
if (result.revokeGrantOption.length > 0) {
|
|
390
|
-
changes.push(
|
|
391
|
-
new RevokeGrantOptionProcedurePrivileges({
|
|
392
|
-
procedure: mainProcedure,
|
|
393
|
-
grantee,
|
|
394
|
-
privilegeNames: result.revokeGrantOption,
|
|
395
|
-
version: ctx.version,
|
|
396
|
-
}),
|
|
397
|
-
);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
323
|
+
changes.push(
|
|
324
|
+
...(emitObjectPrivilegeChanges(
|
|
325
|
+
privilegeResults,
|
|
326
|
+
branchProcedure,
|
|
327
|
+
mainProcedure,
|
|
328
|
+
"procedure",
|
|
329
|
+
{
|
|
330
|
+
Grant: GrantProcedurePrivileges,
|
|
331
|
+
Revoke: RevokeProcedurePrivileges,
|
|
332
|
+
RevokeGrantOption: RevokeGrantOptionProcedurePrivileges,
|
|
333
|
+
},
|
|
334
|
+
ctx.version,
|
|
335
|
+
) as ProcedureChange[]),
|
|
336
|
+
);
|
|
400
337
|
}
|
|
401
338
|
}
|
|
402
339
|
|
|
@@ -242,7 +242,7 @@ select
|
|
|
242
242
|
)
|
|
243
243
|
order by x.grantee, x.privilege_type
|
|
244
244
|
)
|
|
245
|
-
from lateral aclexplode(p.proacl) as x(grantor, grantee, privilege_type, is_grantable)
|
|
245
|
+
from lateral aclexplode(COALESCE(p.proacl, acldefault('f', p.proowner))) as x(grantor, grantee, privilege_type, is_grantable)
|
|
246
246
|
), '[]'
|
|
247
247
|
) as privileges
|
|
248
248
|
from
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { assertValidSql } from "../../../test-utils/assert-valid-sql.ts";
|
|
2
3
|
import { stableId } from "../../utils.ts";
|
|
3
4
|
import type { PublicationTableProps } from "../publication.model.ts";
|
|
4
5
|
import { Publication } from "../publication.model.ts";
|
|
@@ -7,7 +8,6 @@ import {
|
|
|
7
8
|
AlterPublicationAddTables,
|
|
8
9
|
AlterPublicationDropSchemas,
|
|
9
10
|
AlterPublicationDropTables,
|
|
10
|
-
AlterPublicationSetForAllTables,
|
|
11
11
|
AlterPublicationSetList,
|
|
12
12
|
AlterPublicationSetOptions,
|
|
13
13
|
AlterPublicationSetOwner,
|
|
@@ -46,7 +46,7 @@ const makePublication = (override: Partial<PublicationProps> = {}) =>
|
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
describe("publication.alter", () => {
|
|
49
|
-
test("set options serializes assignments and requires publication", () => {
|
|
49
|
+
test("set options serializes assignments and requires publication", async () => {
|
|
50
50
|
const publication = makePublication({
|
|
51
51
|
name: "pub_options",
|
|
52
52
|
publish_delete: false,
|
|
@@ -60,25 +60,13 @@ describe("publication.alter", () => {
|
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
expect(change.requires).toEqual([publication.stableId]);
|
|
63
|
+
await assertValidSql(change.serialize());
|
|
63
64
|
expect(change.serialize()).toBe(
|
|
64
65
|
"ALTER PUBLICATION pub_options SET (publish = 'insert, update', publish_via_partition_root = true)",
|
|
65
66
|
);
|
|
66
67
|
});
|
|
67
68
|
|
|
68
|
-
test("set
|
|
69
|
-
const publication = makePublication({
|
|
70
|
-
name: "pub_all",
|
|
71
|
-
all_tables: false,
|
|
72
|
-
});
|
|
73
|
-
const change = new AlterPublicationSetForAllTables({ publication });
|
|
74
|
-
|
|
75
|
-
expect(change.requires).toEqual([publication.stableId]);
|
|
76
|
-
expect(change.serialize()).toBe(
|
|
77
|
-
"ALTER PUBLICATION pub_all SET FOR ALL TABLES",
|
|
78
|
-
);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test("set list serializes object selection and tracks dependencies", () => {
|
|
69
|
+
test("set list serializes object selection and tracks dependencies", async () => {
|
|
82
70
|
const publication = makePublication({
|
|
83
71
|
name: "pub_set_list",
|
|
84
72
|
all_tables: false,
|
|
@@ -108,12 +96,13 @@ describe("publication.alter", () => {
|
|
|
108
96
|
stableId.column("public", "authors", "name"),
|
|
109
97
|
stableId.schema("analytics"),
|
|
110
98
|
]);
|
|
99
|
+
await assertValidSql(change.serialize());
|
|
111
100
|
expect(change.serialize()).toBe(
|
|
112
101
|
"ALTER PUBLICATION pub_set_list SET TABLE public.articles WHERE (published = true), TABLE public.authors (id, name), TABLES IN SCHEMA analytics",
|
|
113
102
|
);
|
|
114
103
|
});
|
|
115
104
|
|
|
116
|
-
test("add tables serializes new tables and tracks dependencies", () => {
|
|
105
|
+
test("add tables serializes new tables and tracks dependencies", async () => {
|
|
117
106
|
const publication = makePublication({ name: "pub_add_tables" });
|
|
118
107
|
const tables: PublicationTableProps[] = [
|
|
119
108
|
{
|
|
@@ -138,12 +127,13 @@ describe("publication.alter", () => {
|
|
|
138
127
|
stableId.column("audit", "events", "created_at"),
|
|
139
128
|
stableId.column("audit", "events", "id"),
|
|
140
129
|
]);
|
|
130
|
+
await assertValidSql(change.serialize());
|
|
141
131
|
expect(change.serialize()).toBe(
|
|
142
132
|
"ALTER PUBLICATION pub_add_tables ADD TABLE public.logs, TABLE audit.events (created_at, id)",
|
|
143
133
|
);
|
|
144
134
|
});
|
|
145
135
|
|
|
146
|
-
test("drop tables serializes target list and tracks dependencies", () => {
|
|
136
|
+
test("drop tables serializes target list and tracks dependencies", async () => {
|
|
147
137
|
const publication = makePublication({ name: "pub_drop_tables" });
|
|
148
138
|
const tables: PublicationTableProps[] = [
|
|
149
139
|
{
|
|
@@ -166,12 +156,13 @@ describe("publication.alter", () => {
|
|
|
166
156
|
stableId.table("public", "logs"),
|
|
167
157
|
stableId.table("audit", "events"),
|
|
168
158
|
]);
|
|
159
|
+
await assertValidSql(change.serialize());
|
|
169
160
|
expect(change.serialize()).toBe(
|
|
170
161
|
"ALTER PUBLICATION pub_drop_tables DROP TABLE public.logs, audit.events",
|
|
171
162
|
);
|
|
172
163
|
});
|
|
173
164
|
|
|
174
|
-
test("add schemas serializes and tracks dependencies", () => {
|
|
165
|
+
test("add schemas serializes and tracks dependencies", async () => {
|
|
175
166
|
const publication = makePublication({ name: "pub_add_schemas" });
|
|
176
167
|
const change = new AlterPublicationAddSchemas({
|
|
177
168
|
publication,
|
|
@@ -183,12 +174,13 @@ describe("publication.alter", () => {
|
|
|
183
174
|
stableId.schema("analytics"),
|
|
184
175
|
stableId.schema("sales"),
|
|
185
176
|
]);
|
|
177
|
+
await assertValidSql(change.serialize());
|
|
186
178
|
expect(change.serialize()).toBe(
|
|
187
179
|
"ALTER PUBLICATION pub_add_schemas ADD TABLES IN SCHEMA analytics, TABLES IN SCHEMA sales",
|
|
188
180
|
);
|
|
189
181
|
});
|
|
190
182
|
|
|
191
|
-
test("drop schemas serializes and tracks dependencies", () => {
|
|
183
|
+
test("drop schemas serializes and tracks dependencies", async () => {
|
|
192
184
|
const publication = makePublication({ name: "pub_drop_schemas" });
|
|
193
185
|
const change = new AlterPublicationDropSchemas({
|
|
194
186
|
publication,
|
|
@@ -200,12 +192,13 @@ describe("publication.alter", () => {
|
|
|
200
192
|
stableId.schema("analytics"),
|
|
201
193
|
stableId.schema("sales"),
|
|
202
194
|
]);
|
|
195
|
+
await assertValidSql(change.serialize());
|
|
203
196
|
expect(change.serialize()).toBe(
|
|
204
197
|
"ALTER PUBLICATION pub_drop_schemas DROP TABLES IN SCHEMA analytics, TABLES IN SCHEMA sales",
|
|
205
198
|
);
|
|
206
199
|
});
|
|
207
200
|
|
|
208
|
-
test("set owner serializes and tracks dependencies", () => {
|
|
201
|
+
test("set owner serializes and tracks dependencies", async () => {
|
|
209
202
|
const publication = makePublication({ name: "pub_owner" });
|
|
210
203
|
const change = new AlterPublicationSetOwner({
|
|
211
204
|
publication,
|
|
@@ -216,6 +209,7 @@ describe("publication.alter", () => {
|
|
|
216
209
|
publication.stableId,
|
|
217
210
|
stableId.role("owner2"),
|
|
218
211
|
]);
|
|
212
|
+
await assertValidSql(change.serialize());
|
|
219
213
|
expect(change.serialize()).toBe(
|
|
220
214
|
"ALTER PUBLICATION pub_owner OWNER TO owner2",
|
|
221
215
|
);
|
|
@@ -49,24 +49,6 @@ export class AlterPublicationSetOptions extends AlterPublicationChange {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
export class AlterPublicationSetForAllTables extends AlterPublicationChange {
|
|
53
|
-
public readonly publication: Publication;
|
|
54
|
-
public readonly scope = "object" as const;
|
|
55
|
-
|
|
56
|
-
constructor(props: { publication: Publication }) {
|
|
57
|
-
super();
|
|
58
|
-
this.publication = props.publication;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
get requires() {
|
|
62
|
-
return [this.publication.stableId];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
serialize(): string {
|
|
66
|
-
return `ALTER PUBLICATION ${this.publication.name} SET FOR ALL TABLES`;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
52
|
export class AlterPublicationSetList extends AlterPublicationChange {
|
|
71
53
|
public readonly publication: Publication;
|
|
72
54
|
public readonly scope = "object" as const;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { assertValidSql } from "../../../test-utils/assert-valid-sql.ts";
|
|
2
3
|
import { stableId } from "../../utils.ts";
|
|
3
4
|
import { Publication } from "../publication.model.ts";
|
|
4
5
|
import {
|
|
@@ -39,7 +40,7 @@ const makePublication = (override: Partial<PublicationProps> = {}) =>
|
|
|
39
40
|
});
|
|
40
41
|
|
|
41
42
|
describe("publication.comment", () => {
|
|
42
|
-
test("create comment serializes and tracks dependencies", () => {
|
|
43
|
+
test("create comment serializes and tracks dependencies", async () => {
|
|
43
44
|
const publication = makePublication({
|
|
44
45
|
comment: "publication's overview",
|
|
45
46
|
});
|
|
@@ -47,12 +48,13 @@ describe("publication.comment", () => {
|
|
|
47
48
|
|
|
48
49
|
expect(change.creates).toEqual([stableId.comment(publication.stableId)]);
|
|
49
50
|
expect(change.requires).toEqual([publication.stableId]);
|
|
51
|
+
await assertValidSql(change.serialize());
|
|
50
52
|
expect(change.serialize()).toBe(
|
|
51
53
|
"COMMENT ON PUBLICATION pub_comment IS 'publication''s overview'",
|
|
52
54
|
);
|
|
53
55
|
});
|
|
54
56
|
|
|
55
|
-
test("drop comment serializes and tracks dependencies", () => {
|
|
57
|
+
test("drop comment serializes and tracks dependencies", async () => {
|
|
56
58
|
const publication = makePublication({
|
|
57
59
|
comment: "some comment",
|
|
58
60
|
});
|
|
@@ -63,6 +65,7 @@ describe("publication.comment", () => {
|
|
|
63
65
|
stableId.comment(publication.stableId),
|
|
64
66
|
publication.stableId,
|
|
65
67
|
]);
|
|
68
|
+
await assertValidSql(change.serialize());
|
|
66
69
|
expect(change.serialize()).toBe(
|
|
67
70
|
"COMMENT ON PUBLICATION pub_comment IS NULL",
|
|
68
71
|
);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { assertValidSql } from "../../../test-utils/assert-valid-sql.ts";
|
|
2
3
|
import { stableId } from "../../utils.ts";
|
|
3
4
|
import { Publication } from "../publication.model.ts";
|
|
4
5
|
import { CreatePublication } from "./publication.create.ts";
|
|
@@ -36,18 +37,19 @@ const makePublication = (override: Partial<PublicationProps> = {}) =>
|
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
describe("publication.create", () => {
|
|
39
|
-
test("serialize publication for all tables", () => {
|
|
40
|
+
test("serialize publication for all tables", async () => {
|
|
40
41
|
const publication = makePublication();
|
|
41
42
|
const change = new CreatePublication({ publication });
|
|
42
43
|
|
|
43
44
|
expect(change.creates).toEqual([publication.stableId]);
|
|
44
45
|
expect(change.requires).toEqual([stableId.role(publication.owner)]);
|
|
46
|
+
await assertValidSql(change.serialize());
|
|
45
47
|
expect(change.serialize()).toBe(
|
|
46
48
|
"CREATE PUBLICATION pub_all_tables FOR ALL TABLES",
|
|
47
49
|
);
|
|
48
50
|
});
|
|
49
51
|
|
|
50
|
-
test("serialize publication with explicit objects and options", () => {
|
|
52
|
+
test("serialize publication with explicit objects and options", async () => {
|
|
51
53
|
const publication = makePublication({
|
|
52
54
|
name: "pub_custom",
|
|
53
55
|
all_tables: false,
|
|
@@ -80,6 +82,7 @@ describe("publication.create", () => {
|
|
|
80
82
|
stableId.column("public", "authors", "name"),
|
|
81
83
|
stableId.schema("analytics"),
|
|
82
84
|
]);
|
|
85
|
+
await assertValidSql(change.serialize());
|
|
83
86
|
expect(change.serialize()).toBe(
|
|
84
87
|
"CREATE PUBLICATION pub_custom FOR TABLE public.articles WHERE (id > 1), TABLE public.authors (id, name), TABLES IN SCHEMA analytics WITH (publish = 'insert, update', publish_via_partition_root = true)",
|
|
85
88
|
);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { assertValidSql } from "../../../test-utils/assert-valid-sql.ts";
|
|
2
3
|
import { Publication } from "../publication.model.ts";
|
|
3
4
|
import { DropPublication } from "./publication.drop.ts";
|
|
4
5
|
|
|
@@ -35,12 +36,13 @@ const makePublication = (override: Partial<PublicationProps> = {}) =>
|
|
|
35
36
|
});
|
|
36
37
|
|
|
37
38
|
describe("publication.drop", () => {
|
|
38
|
-
test("serialize drop statement and track dependencies", () => {
|
|
39
|
+
test("serialize drop statement and track dependencies", async () => {
|
|
39
40
|
const publication = makePublication();
|
|
40
41
|
const change = new DropPublication({ publication });
|
|
41
42
|
|
|
42
43
|
expect(change.drops).toEqual([publication.stableId]);
|
|
43
44
|
expect(change.requires).toEqual([publication.stableId]);
|
|
45
|
+
await assertValidSql(change.serialize());
|
|
44
46
|
expect(change.serialize()).toBe("DROP PUBLICATION pub_drop_me");
|
|
45
47
|
});
|
|
46
48
|
});
|
|
@@ -3,7 +3,6 @@ import type {
|
|
|
3
3
|
AlterPublicationAddTables,
|
|
4
4
|
AlterPublicationDropSchemas,
|
|
5
5
|
AlterPublicationDropTables,
|
|
6
|
-
AlterPublicationSetForAllTables,
|
|
7
6
|
AlterPublicationSetList,
|
|
8
7
|
AlterPublicationSetOptions,
|
|
9
8
|
AlterPublicationSetOwner,
|
|
@@ -17,7 +16,6 @@ export type PublicationChange =
|
|
|
17
16
|
| AlterPublicationAddTables
|
|
18
17
|
| AlterPublicationDropSchemas
|
|
19
18
|
| AlterPublicationDropTables
|
|
20
|
-
| AlterPublicationSetForAllTables
|
|
21
19
|
| AlterPublicationSetList
|
|
22
20
|
| AlterPublicationSetOptions
|
|
23
21
|
| AlterPublicationSetOwner
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import type { ObjectDiffContext } from "../diff-context.ts";
|
|
2
3
|
import {
|
|
3
4
|
AlterPublicationAddSchemas,
|
|
4
5
|
AlterPublicationAddTables,
|
|
5
6
|
AlterPublicationDropSchemas,
|
|
6
7
|
AlterPublicationDropTables,
|
|
7
|
-
AlterPublicationSetForAllTables,
|
|
8
8
|
AlterPublicationSetOptions,
|
|
9
9
|
AlterPublicationSetOwner,
|
|
10
10
|
} from "./changes/publication.alter.ts";
|
|
@@ -17,6 +17,10 @@ import { DropPublication } from "./changes/publication.drop.ts";
|
|
|
17
17
|
import { diffPublications } from "./publication.diff.ts";
|
|
18
18
|
import { Publication, type PublicationProps } from "./publication.model.ts";
|
|
19
19
|
|
|
20
|
+
const ctx: Pick<ObjectDiffContext, "currentUser"> = {
|
|
21
|
+
currentUser: "postgres",
|
|
22
|
+
};
|
|
23
|
+
|
|
20
24
|
const base: PublicationProps = {
|
|
21
25
|
name: "mypub",
|
|
22
26
|
owner: "postgres",
|
|
@@ -35,7 +39,7 @@ describe.concurrent("publication.diff", () => {
|
|
|
35
39
|
test("create and drop publication", () => {
|
|
36
40
|
const publication = new Publication(base);
|
|
37
41
|
const created = diffPublications(
|
|
38
|
-
|
|
42
|
+
ctx,
|
|
39
43
|
{},
|
|
40
44
|
{ [publication.stableId]: publication },
|
|
41
45
|
);
|
|
@@ -44,7 +48,7 @@ describe.concurrent("publication.diff", () => {
|
|
|
44
48
|
);
|
|
45
49
|
|
|
46
50
|
const dropped = diffPublications(
|
|
47
|
-
|
|
51
|
+
ctx,
|
|
48
52
|
{ [publication.stableId]: publication },
|
|
49
53
|
{},
|
|
50
54
|
);
|
|
@@ -68,7 +72,7 @@ describe.concurrent("publication.diff", () => {
|
|
|
68
72
|
});
|
|
69
73
|
|
|
70
74
|
const changes = diffPublications(
|
|
71
|
-
|
|
75
|
+
ctx,
|
|
72
76
|
{},
|
|
73
77
|
{ [publication.stableId]: publication },
|
|
74
78
|
);
|
|
@@ -95,7 +99,7 @@ describe.concurrent("publication.diff", () => {
|
|
|
95
99
|
publish_delete: false,
|
|
96
100
|
});
|
|
97
101
|
const changes = diffPublications(
|
|
98
|
-
|
|
102
|
+
ctx,
|
|
99
103
|
{ [mainPublication.stableId]: mainPublication },
|
|
100
104
|
{ [branchPublication.stableId]: branchPublication },
|
|
101
105
|
);
|
|
@@ -111,15 +115,16 @@ describe.concurrent("publication.diff", () => {
|
|
|
111
115
|
all_tables: true,
|
|
112
116
|
});
|
|
113
117
|
const changes = diffPublications(
|
|
114
|
-
|
|
118
|
+
ctx,
|
|
115
119
|
{ [mainPublication.stableId]: mainPublication },
|
|
116
120
|
{ [branchPublication.stableId]: branchPublication },
|
|
117
121
|
);
|
|
118
|
-
expect(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
expect(changes.some((change) => change instanceof DropPublication)).toBe(
|
|
123
|
+
true,
|
|
124
|
+
);
|
|
125
|
+
expect(changes.some((change) => change instanceof CreatePublication)).toBe(
|
|
126
|
+
true,
|
|
127
|
+
);
|
|
123
128
|
});
|
|
124
129
|
|
|
125
130
|
test("switch from FOR ALL TABLES to explicit list", () => {
|
|
@@ -139,7 +144,7 @@ describe.concurrent("publication.diff", () => {
|
|
|
139
144
|
],
|
|
140
145
|
});
|
|
141
146
|
const changes = diffPublications(
|
|
142
|
-
|
|
147
|
+
ctx,
|
|
143
148
|
{ [mainPublication.stableId]: mainPublication },
|
|
144
149
|
{ [branchPublication.stableId]: branchPublication },
|
|
145
150
|
);
|
|
@@ -165,7 +170,7 @@ describe.concurrent("publication.diff", () => {
|
|
|
165
170
|
],
|
|
166
171
|
});
|
|
167
172
|
const addChanges = diffPublications(
|
|
168
|
-
|
|
173
|
+
ctx,
|
|
169
174
|
{ [mainPublication.stableId]: mainPublication },
|
|
170
175
|
{ [branchPublication.stableId]: branchPublication },
|
|
171
176
|
);
|
|
@@ -181,7 +186,7 @@ describe.concurrent("publication.diff", () => {
|
|
|
181
186
|
);
|
|
182
187
|
|
|
183
188
|
const dropChanges = diffPublications(
|
|
184
|
-
|
|
189
|
+
ctx,
|
|
185
190
|
{ [branchPublication.stableId]: branchPublication },
|
|
186
191
|
{ [mainPublication.stableId]: mainPublication },
|
|
187
192
|
);
|
|
@@ -216,7 +221,7 @@ describe.concurrent("publication.diff", () => {
|
|
|
216
221
|
],
|
|
217
222
|
});
|
|
218
223
|
const changes = diffPublications(
|
|
219
|
-
|
|
224
|
+
ctx,
|
|
220
225
|
{ [mainPublication.stableId]: mainPublication },
|
|
221
226
|
{ [branchPublication.stableId]: branchPublication },
|
|
222
227
|
);
|
|
@@ -235,7 +240,7 @@ describe.concurrent("publication.diff", () => {
|
|
|
235
240
|
schemas: ["public"],
|
|
236
241
|
});
|
|
237
242
|
const addChanges = diffPublications(
|
|
238
|
-
|
|
243
|
+
ctx,
|
|
239
244
|
{ [mainPublication.stableId]: mainPublication },
|
|
240
245
|
{ [branchPublication.stableId]: branchPublication },
|
|
241
246
|
);
|
|
@@ -244,7 +249,7 @@ describe.concurrent("publication.diff", () => {
|
|
|
244
249
|
).toBe(true);
|
|
245
250
|
|
|
246
251
|
const dropChanges = diffPublications(
|
|
247
|
-
|
|
252
|
+
ctx,
|
|
248
253
|
{ [branchPublication.stableId]: branchPublication },
|
|
249
254
|
{ [mainPublication.stableId]: mainPublication },
|
|
250
255
|
);
|
|
@@ -263,7 +268,7 @@ describe.concurrent("publication.diff", () => {
|
|
|
263
268
|
comment: "replication publication",
|
|
264
269
|
});
|
|
265
270
|
const changes = diffPublications(
|
|
266
|
-
|
|
271
|
+
ctx,
|
|
267
272
|
{ [mainPublication.stableId]: mainPublication },
|
|
268
273
|
{ [branchPublication.stableId]: branchPublication },
|
|
269
274
|
);
|
|
@@ -279,7 +284,7 @@ describe.concurrent("publication.diff", () => {
|
|
|
279
284
|
comment: null,
|
|
280
285
|
});
|
|
281
286
|
const dropCommentChanges = diffPublications(
|
|
282
|
-
|
|
287
|
+
ctx,
|
|
283
288
|
{ [branchPublication.stableId]: branchPublication },
|
|
284
289
|
{ [removeCommentPublication.stableId]: removeCommentPublication },
|
|
285
290
|
);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { diffObjects } from "../base.diff.ts";
|
|
2
|
+
import type { ObjectDiffContext } from "../diff-context.ts";
|
|
2
3
|
import { deepEqual } from "../utils.ts";
|
|
3
4
|
import {
|
|
4
5
|
AlterPublicationAddSchemas,
|
|
5
6
|
AlterPublicationAddTables,
|
|
6
7
|
AlterPublicationDropSchemas,
|
|
7
8
|
AlterPublicationDropTables,
|
|
8
|
-
AlterPublicationSetForAllTables,
|
|
9
9
|
AlterPublicationSetOptions,
|
|
10
10
|
AlterPublicationSetOwner,
|
|
11
11
|
} from "./changes/publication.alter.ts";
|
|
@@ -22,7 +22,7 @@ import type {
|
|
|
22
22
|
} from "./publication.model.ts";
|
|
23
23
|
|
|
24
24
|
export function diffPublications(
|
|
25
|
-
ctx:
|
|
25
|
+
ctx: Pick<ObjectDiffContext, "currentUser">,
|
|
26
26
|
main: Record<string, Publication>,
|
|
27
27
|
branch: Record<string, Publication>,
|
|
28
28
|
): PublicationChange[] {
|
|
@@ -92,24 +92,18 @@ export function diffPublications(
|
|
|
92
92
|
|
|
93
93
|
if (mainPublication.all_tables !== branchPublication.all_tables) {
|
|
94
94
|
handledObjectLists = true;
|
|
95
|
-
|
|
95
|
+
// Changing the all_tables mode requires DROP + CREATE because
|
|
96
|
+
// ALTER PUBLICATION does not support SET ALL TABLES.
|
|
97
|
+
changes.push(new DropPublication({ publication: mainPublication }));
|
|
98
|
+
changes.push(new CreatePublication({ publication: branchPublication }));
|
|
99
|
+
if (branchPublication.comment !== null) {
|
|
96
100
|
changes.push(
|
|
97
|
-
new
|
|
101
|
+
new CreateCommentOnPublication({
|
|
98
102
|
publication: branchPublication,
|
|
99
103
|
}),
|
|
100
104
|
);
|
|
101
|
-
} else {
|
|
102
|
-
changes.push(new DropPublication({ publication: mainPublication }));
|
|
103
|
-
changes.push(new CreatePublication({ publication: branchPublication }));
|
|
104
|
-
if (branchPublication.comment !== null) {
|
|
105
|
-
changes.push(
|
|
106
|
-
new CreateCommentOnPublication({
|
|
107
|
-
publication: branchPublication,
|
|
108
|
-
}),
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
continue;
|
|
112
105
|
}
|
|
106
|
+
continue;
|
|
113
107
|
}
|
|
114
108
|
|
|
115
109
|
if (!handledObjectLists && !branchPublication.all_tables) {
|