@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.
Files changed (359) hide show
  1. package/README.md +40 -23
  2. package/dist/cli/app.js +26 -3
  3. package/dist/cli/bin/cli.js +5 -0
  4. package/dist/cli/commands/catalog-export.d.ts +5 -0
  5. package/dist/cli/commands/catalog-export.js +64 -0
  6. package/dist/cli/commands/declarative-apply.d.ts +6 -0
  7. package/dist/cli/commands/declarative-apply.js +288 -0
  8. package/dist/cli/commands/declarative-export.d.ts +5 -0
  9. package/dist/cli/commands/declarative-export.js +245 -0
  10. package/dist/cli/commands/plan.js +19 -6
  11. package/dist/cli/exit-code.d.ts +2 -0
  12. package/dist/cli/exit-code.js +7 -0
  13. package/dist/cli/formatters/tree/tree.js +3 -2
  14. package/dist/cli/utils/apply-display.d.ts +52 -0
  15. package/dist/cli/utils/apply-display.js +183 -0
  16. package/dist/cli/utils/export-display.d.ts +43 -0
  17. package/dist/cli/utils/export-display.js +202 -0
  18. package/dist/cli/utils/resolve-input.d.ts +7 -0
  19. package/dist/cli/utils/resolve-input.js +13 -0
  20. package/dist/core/catalog-export/index.d.ts +11 -0
  21. package/dist/core/catalog-export/index.js +10 -0
  22. package/dist/core/catalog.diff.d.ts +1 -0
  23. package/dist/core/catalog.diff.js +64 -48
  24. package/dist/core/catalog.model.d.ts +14 -1
  25. package/dist/core/catalog.model.js +103 -1
  26. package/dist/core/catalog.snapshot.d.ts +66 -0
  27. package/dist/core/catalog.snapshot.js +206 -0
  28. package/dist/core/declarative-apply/discover-sql.d.ts +18 -0
  29. package/dist/core/declarative-apply/discover-sql.js +86 -0
  30. package/dist/core/declarative-apply/extract-catalog-providers.d.ts +23 -0
  31. package/dist/core/declarative-apply/extract-catalog-providers.js +159 -0
  32. package/dist/core/declarative-apply/index.d.ts +49 -0
  33. package/dist/core/declarative-apply/index.js +134 -0
  34. package/dist/core/declarative-apply/round-apply.d.ts +100 -0
  35. package/dist/core/declarative-apply/round-apply.js +378 -0
  36. package/dist/core/export/file-mapper.d.ts +71 -0
  37. package/dist/core/export/file-mapper.js +474 -0
  38. package/dist/core/export/grouper.d.ts +13 -0
  39. package/dist/core/export/grouper.js +76 -0
  40. package/dist/core/export/index.d.ts +45 -0
  41. package/dist/core/export/index.js +63 -0
  42. package/dist/core/export/types.d.ts +84 -0
  43. package/dist/core/export/types.js +25 -0
  44. package/dist/core/fixtures/empty-catalogs/postgres-15-16-baseline.json +287 -0
  45. package/dist/core/integrations/filter/dsl.d.ts +38 -1
  46. package/dist/core/integrations/filter/dsl.js +20 -2
  47. package/dist/core/integrations/filter/extractors.js +42 -0
  48. package/dist/core/integrations/integration-dsl.d.ts +10 -0
  49. package/dist/core/integrations/supabase.d.ts +8 -0
  50. package/dist/core/integrations/supabase.js +9 -0
  51. package/dist/core/objects/aggregate/aggregate.diff.d.ts +2 -8
  52. package/dist/core/objects/aggregate/aggregate.diff.js +16 -70
  53. package/dist/core/objects/aggregate/aggregate.model.d.ts +8 -8
  54. package/dist/core/objects/aggregate/aggregate.model.js +1 -1
  55. package/dist/core/objects/aggregate/changes/aggregate.create.js +1 -1
  56. package/dist/core/objects/aggregate/changes/aggregate.drop.js +1 -1
  57. package/dist/core/objects/base.privilege-diff.d.ts +38 -13
  58. package/dist/core/objects/base.privilege-diff.js +104 -22
  59. package/dist/core/objects/base.privilege.d.ts +1 -0
  60. package/dist/core/objects/base.privilege.js +9 -2
  61. package/dist/core/objects/collation/collation.diff.d.ts +2 -3
  62. package/dist/core/objects/diff-context.d.ts +15 -0
  63. package/dist/core/objects/diff-context.js +1 -0
  64. package/dist/core/objects/domain/changes/domain.create.js +4 -2
  65. package/dist/core/objects/domain/domain.diff.d.ts +2 -8
  66. package/dist/core/objects/domain/domain.diff.js +16 -77
  67. package/dist/core/objects/domain/domain.model.js +1 -1
  68. package/dist/core/objects/event-trigger/event-trigger.diff.d.ts +2 -3
  69. package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.diff.d.ts +2 -8
  70. package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.diff.js +13 -77
  71. package/dist/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.model.js +2 -2
  72. package/dist/core/objects/foreign-data-wrapper/foreign-table/foreign-table.diff.d.ts +2 -8
  73. package/dist/core/objects/foreign-data-wrapper/foreign-table/foreign-table.diff.js +16 -77
  74. package/dist/core/objects/foreign-data-wrapper/foreign-table/foreign-table.model.js +1 -1
  75. package/dist/core/objects/foreign-data-wrapper/server/server.diff.d.ts +2 -8
  76. package/dist/core/objects/foreign-data-wrapper/server/server.diff.js +13 -77
  77. package/dist/core/objects/language/language.diff.d.ts +2 -5
  78. package/dist/core/objects/language/language.diff.js +7 -39
  79. package/dist/core/objects/materialized-view/materialized-view.diff.d.ts +2 -8
  80. package/dist/core/objects/materialized-view/materialized-view.diff.js +16 -158
  81. package/dist/core/objects/materialized-view/materialized-view.model.d.ts +3 -3
  82. package/dist/core/objects/materialized-view/materialized-view.model.js +1 -1
  83. package/dist/core/objects/procedure/changes/procedure.alter.js +12 -12
  84. package/dist/core/objects/procedure/procedure.diff.d.ts +2 -8
  85. package/dist/core/objects/procedure/procedure.diff.js +16 -77
  86. package/dist/core/objects/procedure/procedure.model.d.ts +9 -9
  87. package/dist/core/objects/procedure/procedure.model.js +1 -1
  88. package/dist/core/objects/publication/changes/publication.alter.d.ts +0 -9
  89. package/dist/core/objects/publication/changes/publication.alter.js +0 -14
  90. package/dist/core/objects/publication/changes/publication.types.d.ts +2 -2
  91. package/dist/core/objects/publication/publication.diff.d.ts +2 -3
  92. package/dist/core/objects/publication/publication.diff.js +8 -13
  93. package/dist/core/objects/rls-policy/changes/rls-policy.alter.js +3 -3
  94. package/dist/core/objects/rls-policy/rls-policy.model.d.ts +2 -2
  95. package/dist/core/objects/role/role.diff.js +22 -1
  96. package/dist/core/objects/role/role.model.d.ts +4 -3
  97. package/dist/core/objects/role/role.model.js +118 -12
  98. package/dist/core/objects/rule/rule.model.d.ts +1 -1
  99. package/dist/core/objects/schema/schema.diff.d.ts +2 -8
  100. package/dist/core/objects/schema/schema.diff.js +16 -77
  101. package/dist/core/objects/schema/schema.model.js +1 -1
  102. package/dist/core/objects/sequence/sequence.diff.d.ts +2 -8
  103. package/dist/core/objects/sequence/sequence.diff.js +16 -79
  104. package/dist/core/objects/sequence/sequence.model.js +1 -1
  105. package/dist/core/objects/subscription/subscription.diff.d.ts +2 -3
  106. package/dist/core/objects/table/changes/table.create.js +3 -0
  107. package/dist/core/objects/table/table.diff.d.ts +2 -8
  108. package/dist/core/objects/table/table.diff.js +26 -157
  109. package/dist/core/objects/table/table.model.d.ts +23 -22
  110. package/dist/core/objects/table/table.model.js +1 -1
  111. package/dist/core/objects/trigger/changes/trigger.create.js +2 -4
  112. package/dist/core/objects/trigger/trigger.model.d.ts +8 -0
  113. package/dist/core/objects/trigger/trigger.model.js +11 -0
  114. package/dist/core/objects/type/composite-type/composite-type.diff.d.ts +2 -8
  115. package/dist/core/objects/type/composite-type/composite-type.diff.js +16 -77
  116. package/dist/core/objects/type/composite-type/composite-type.model.d.ts +3 -3
  117. package/dist/core/objects/type/composite-type/composite-type.model.js +2 -1
  118. package/dist/core/objects/type/enum/enum.diff.d.ts +2 -8
  119. package/dist/core/objects/type/enum/enum.diff.js +25 -112
  120. package/dist/core/objects/type/enum/enum.model.js +1 -1
  121. package/dist/core/objects/type/range/changes/range.create.js +6 -3
  122. package/dist/core/objects/type/range/range.diff.d.ts +2 -8
  123. package/dist/core/objects/type/range/range.diff.js +16 -77
  124. package/dist/core/objects/type/range/range.model.js +1 -1
  125. package/dist/core/objects/view/view.diff.d.ts +2 -8
  126. package/dist/core/objects/view/view.diff.js +16 -158
  127. package/dist/core/objects/view/view.model.d.ts +18 -4
  128. package/dist/core/objects/view/view.model.js +3 -13
  129. package/dist/core/plan/apply.js +9 -26
  130. package/dist/core/plan/create.d.ts +19 -6
  131. package/dist/core/plan/create.js +134 -174
  132. package/dist/core/plan/serialize.js +16 -4
  133. package/dist/core/plan/sql-format/fixtures.js +3 -5
  134. package/dist/core/plan/sql-format/keyword-case.js +26 -1
  135. package/dist/core/plan/ssl-config.d.ts +32 -0
  136. package/dist/core/plan/ssl-config.js +115 -0
  137. package/dist/core/plan/types.d.ts +6 -0
  138. package/dist/core/postgres-config.d.ts +14 -0
  139. package/dist/core/postgres-config.js +53 -2
  140. package/dist/core/sort/graph-builder.js +10 -0
  141. package/dist/core/sort/logical-sort.js +31 -23
  142. package/dist/core/test-utils/assert-valid-sql.d.ts +10 -0
  143. package/dist/core/test-utils/assert-valid-sql.js +19 -0
  144. package/dist/index.d.ts +6 -0
  145. package/dist/index.js +6 -1
  146. package/package.json +21 -4
  147. package/src/cli/app.ts +27 -3
  148. package/src/cli/bin/cli.ts +6 -0
  149. package/src/cli/commands/catalog-export.ts +78 -0
  150. package/src/cli/commands/declarative-apply.diagnostics.test.ts +77 -0
  151. package/src/cli/commands/declarative-apply.ts +380 -0
  152. package/src/cli/commands/declarative-export.ts +330 -0
  153. package/src/cli/commands/plan.ts +28 -7
  154. package/src/cli/exit-code.test.ts +19 -0
  155. package/src/cli/exit-code.ts +7 -0
  156. package/src/cli/formatters/tree/tree.ts +3 -2
  157. package/src/cli/utils/apply-display.test.ts +348 -0
  158. package/src/cli/utils/apply-display.ts +238 -0
  159. package/src/cli/utils/export-display.test.ts +103 -0
  160. package/src/cli/utils/export-display.ts +275 -0
  161. package/src/cli/utils/integrations.test.ts +44 -0
  162. package/src/cli/utils/resolve-input.test.ts +38 -0
  163. package/src/cli/utils/resolve-input.ts +17 -0
  164. package/src/core/catalog-export/index.ts +20 -0
  165. package/src/core/catalog.diff.ts +79 -78
  166. package/src/core/catalog.model.test.ts +122 -0
  167. package/src/core/catalog.model.ts +127 -1
  168. package/src/core/catalog.snapshot.test.ts +464 -0
  169. package/src/core/catalog.snapshot.ts +289 -0
  170. package/src/core/declarative-apply/discover-sql.test.ts +103 -0
  171. package/src/core/declarative-apply/discover-sql.ts +107 -0
  172. package/src/core/declarative-apply/extract-catalog-providers.ts +220 -0
  173. package/src/core/declarative-apply/index.test.ts +67 -0
  174. package/src/core/declarative-apply/index.ts +205 -0
  175. package/src/core/declarative-apply/round-apply.test.ts +504 -0
  176. package/src/core/declarative-apply/round-apply.ts +562 -0
  177. package/src/core/expand-replace-dependencies.test.ts +70 -0
  178. package/src/core/export/file-mapper.test.ts +816 -0
  179. package/src/core/export/file-mapper.ts +574 -0
  180. package/src/core/export/grouper.ts +108 -0
  181. package/src/core/export/index.ts +129 -0
  182. package/src/core/export/types.ts +104 -0
  183. package/src/core/fixtures/empty-catalogs/postgres-15-16-baseline.json +287 -0
  184. package/src/core/integrations/filter/dsl.test.ts +211 -0
  185. package/src/core/integrations/filter/dsl.ts +65 -3
  186. package/src/core/integrations/filter/extractors.test.ts +244 -0
  187. package/src/core/integrations/filter/extractors.ts +42 -0
  188. package/src/core/integrations/integration-dsl.ts +10 -0
  189. package/src/core/integrations/serialize/dsl.test.ts +91 -0
  190. package/src/core/integrations/supabase.ts +9 -0
  191. package/src/core/objects/aggregate/aggregate.diff.ts +39 -95
  192. package/src/core/objects/aggregate/aggregate.model.ts +1 -1
  193. package/src/core/objects/aggregate/changes/aggregate.alter.test.ts +3 -1
  194. package/src/core/objects/aggregate/changes/aggregate.comment.test.ts +5 -2
  195. package/src/core/objects/aggregate/changes/aggregate.create.test.ts +6 -3
  196. package/src/core/objects/aggregate/changes/aggregate.create.ts +1 -1
  197. package/src/core/objects/aggregate/changes/aggregate.drop.test.ts +7 -3
  198. package/src/core/objects/aggregate/changes/aggregate.drop.ts +1 -1
  199. package/src/core/objects/aggregate/changes/aggregate.privilege.test.ts +9 -3
  200. package/src/core/objects/base.privilege-diff.ts +178 -30
  201. package/src/core/objects/base.privilege.ts +9 -2
  202. package/src/core/objects/collation/changes/collation.alter.test.ts +7 -2
  203. package/src/core/objects/collation/changes/collation.create.test.ts +7 -2
  204. package/src/core/objects/collation/changes/collation.drop.test.ts +4 -1
  205. package/src/core/objects/collation/collation.diff.test.ts +9 -12
  206. package/src/core/objects/collation/collation.diff.ts +2 -1
  207. package/src/core/objects/diff-context.ts +16 -0
  208. package/src/core/objects/domain/changes/domain.alter.test.ts +28 -9
  209. package/src/core/objects/domain/changes/domain.create.test.ts +32 -2
  210. package/src/core/objects/domain/changes/domain.create.ts +7 -1
  211. package/src/core/objects/domain/changes/domain.drop.test.ts +4 -1
  212. package/src/core/objects/domain/domain.diff.ts +39 -102
  213. package/src/core/objects/domain/domain.model.ts +1 -1
  214. package/src/core/objects/event-trigger/changes/event-trigger.alter.test.ts +10 -3
  215. package/src/core/objects/event-trigger/changes/event-trigger.create.test.ts +4 -1
  216. package/src/core/objects/event-trigger/changes/event-trigger.drop.test.ts +4 -1
  217. package/src/core/objects/event-trigger/event-trigger.diff.test.ts +12 -7
  218. package/src/core/objects/event-trigger/event-trigger.diff.ts +2 -1
  219. package/src/core/objects/extension/changes/extension.alter.test.ts +7 -2
  220. package/src/core/objects/extension/changes/extension.create.test.ts +4 -1
  221. package/src/core/objects/extension/changes/extension.drop.test.ts +4 -1
  222. package/src/core/objects/extension/extension.model.test.ts +98 -0
  223. package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.alter.test.ts +16 -5
  224. package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.create.test.ts +51 -16
  225. package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.drop.test.ts +4 -1
  226. package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.diff.test.ts +111 -4
  227. package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.diff.ts +31 -101
  228. package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.model.ts +2 -2
  229. package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.alter.test.ts +46 -15
  230. package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.create.test.ts +13 -4
  231. package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.drop.test.ts +4 -1
  232. package/src/core/objects/foreign-data-wrapper/foreign-table/foreign-table.diff.ts +39 -102
  233. package/src/core/objects/foreign-data-wrapper/foreign-table/foreign-table.model.ts +1 -1
  234. package/src/core/objects/foreign-data-wrapper/server/changes/server.alter.test.ts +22 -7
  235. package/src/core/objects/foreign-data-wrapper/server/changes/server.create.test.ts +19 -6
  236. package/src/core/objects/foreign-data-wrapper/server/changes/server.drop.test.ts +4 -1
  237. package/src/core/objects/foreign-data-wrapper/server/server.diff.test.ts +95 -0
  238. package/src/core/objects/foreign-data-wrapper/server/server.diff.ts +31 -101
  239. package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.alter.test.ts +13 -4
  240. package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.create.test.ts +16 -5
  241. package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.drop.test.ts +10 -3
  242. package/src/core/objects/index/changes/index.alter.test.ts +13 -4
  243. package/src/core/objects/index/changes/index.create.test.ts +4 -1
  244. package/src/core/objects/index/changes/index.drop.test.ts +4 -1
  245. package/src/core/objects/language/changes/language.alter.test.ts +4 -1
  246. package/src/core/objects/language/changes/language.create.test.ts +4 -1
  247. package/src/core/objects/language/changes/language.drop.test.ts +4 -1
  248. package/src/core/objects/language/language.diff.test.ts +86 -4
  249. package/src/core/objects/language/language.diff.ts +17 -49
  250. package/src/core/objects/materialized-view/changes/materialized-view.alter.test.ts +10 -3
  251. package/src/core/objects/materialized-view/changes/materialized-view.create.test.ts +7 -2
  252. package/src/core/objects/materialized-view/changes/materialized-view.drop.test.ts +4 -1
  253. package/src/core/objects/materialized-view/materialized-view.diff.test.ts +162 -0
  254. package/src/core/objects/materialized-view/materialized-view.diff.ts +41 -191
  255. package/src/core/objects/materialized-view/materialized-view.model.ts +1 -1
  256. package/src/core/objects/procedure/changes/procedure.alter.test.ts +121 -49
  257. package/src/core/objects/procedure/changes/procedure.alter.ts +15 -12
  258. package/src/core/objects/procedure/changes/procedure.create.test.ts +4 -1
  259. package/src/core/objects/procedure/changes/procedure.drop.test.ts +7 -2
  260. package/src/core/objects/procedure/procedure.diff.ts +39 -102
  261. package/src/core/objects/procedure/procedure.model.ts +1 -1
  262. package/src/core/objects/publication/changes/publication.alter.test.ts +15 -21
  263. package/src/core/objects/publication/changes/publication.alter.ts +0 -18
  264. package/src/core/objects/publication/changes/publication.comment.test.ts +5 -2
  265. package/src/core/objects/publication/changes/publication.create.test.ts +5 -2
  266. package/src/core/objects/publication/changes/publication.drop.test.ts +3 -1
  267. package/src/core/objects/publication/changes/publication.types.ts +0 -2
  268. package/src/core/objects/publication/publication.diff.test.ts +24 -19
  269. package/src/core/objects/publication/publication.diff.ts +9 -15
  270. package/src/core/objects/rls-policy/changes/rls-policy.alter.test.ts +31 -14
  271. package/src/core/objects/rls-policy/changes/rls-policy.alter.ts +3 -3
  272. package/src/core/objects/rls-policy/changes/rls-policy.create.test.ts +10 -3
  273. package/src/core/objects/rls-policy/changes/rls-policy.drop.test.ts +4 -1
  274. package/src/core/objects/role/changes/role.alter.test.ts +31 -15
  275. package/src/core/objects/role/changes/role.create.test.ts +6 -2
  276. package/src/core/objects/role/changes/role.drop.test.ts +4 -1
  277. package/src/core/objects/role/role.diff.test.ts +235 -0
  278. package/src/core/objects/role/role.diff.ts +21 -1
  279. package/src/core/objects/role/role.model.ts +122 -14
  280. package/src/core/objects/rule/changes/rule.alter.test.ts +7 -3
  281. package/src/core/objects/rule/changes/rule.comment.test.ts +5 -2
  282. package/src/core/objects/rule/changes/rule.create.test.ts +6 -2
  283. package/src/core/objects/rule/changes/rule.drop.test.ts +3 -1
  284. package/src/core/objects/schema/changes/schema.alter.test.ts +4 -1
  285. package/src/core/objects/schema/changes/schema.create.test.ts +4 -1
  286. package/src/core/objects/schema/changes/schema.drop.test.ts +4 -1
  287. package/src/core/objects/schema/schema.diff.ts +39 -102
  288. package/src/core/objects/schema/schema.model.ts +1 -1
  289. package/src/core/objects/sequence/changes/sequence.alter.test.ts +11 -5
  290. package/src/core/objects/sequence/changes/sequence.create.test.ts +8 -3
  291. package/src/core/objects/sequence/changes/sequence.drop.test.ts +4 -1
  292. package/src/core/objects/sequence/sequence.diff.test.ts +114 -0
  293. package/src/core/objects/sequence/sequence.diff.ts +39 -104
  294. package/src/core/objects/sequence/sequence.model.ts +1 -1
  295. package/src/core/objects/subscription/changes/subscription.alter.test.ts +15 -5
  296. package/src/core/objects/subscription/changes/subscription.comment.test.ts +5 -2
  297. package/src/core/objects/subscription/changes/subscription.create.test.ts +5 -2
  298. package/src/core/objects/subscription/changes/subscription.drop.test.ts +3 -1
  299. package/src/core/objects/subscription/subscription.diff.test.ts +16 -11
  300. package/src/core/objects/subscription/subscription.diff.ts +2 -1
  301. package/src/core/objects/table/changes/table.alter.test.ts +38 -15
  302. package/src/core/objects/table/changes/table.create.test.ts +41 -3
  303. package/src/core/objects/table/changes/table.create.ts +4 -0
  304. package/src/core/objects/table/changes/table.drop.test.ts +3 -1
  305. package/src/core/objects/table/table.diff.test.ts +157 -0
  306. package/src/core/objects/table/table.diff.ts +54 -190
  307. package/src/core/objects/table/table.model.ts +1 -1
  308. package/src/core/objects/trigger/changes/trigger.alter.test.ts +8 -4
  309. package/src/core/objects/trigger/changes/trigger.create.test.ts +5 -1
  310. package/src/core/objects/trigger/changes/trigger.create.ts +7 -4
  311. package/src/core/objects/trigger/changes/trigger.drop.test.ts +5 -1
  312. package/src/core/objects/trigger/trigger.diff.test.ts +1 -0
  313. package/src/core/objects/trigger/trigger.model.ts +12 -0
  314. package/src/core/objects/type/composite-type/changes/composite-type.alter.test.ts +10 -4
  315. package/src/core/objects/type/composite-type/changes/composite-type.create.test.ts +7 -2
  316. package/src/core/objects/type/composite-type/changes/composite-type.drop.test.ts +4 -1
  317. package/src/core/objects/type/composite-type/composite-type.diff.test.ts +78 -0
  318. package/src/core/objects/type/composite-type/composite-type.diff.ts +39 -101
  319. package/src/core/objects/type/composite-type/composite-type.model.ts +2 -1
  320. package/src/core/objects/type/enum/changes/enum.alter.test.ts +14 -5
  321. package/src/core/objects/type/enum/changes/enum.create.test.ts +4 -1
  322. package/src/core/objects/type/enum/changes/enum.drop.test.ts +4 -1
  323. package/src/core/objects/type/enum/enum.diff.test.ts +181 -0
  324. package/src/core/objects/type/enum/enum.diff.ts +58 -146
  325. package/src/core/objects/type/enum/enum.model.ts +1 -1
  326. package/src/core/objects/type/range/changes/range.alter.test.ts +3 -1
  327. package/src/core/objects/type/range/changes/range.create.test.ts +5 -2
  328. package/src/core/objects/type/range/changes/range.create.ts +6 -2
  329. package/src/core/objects/type/range/changes/range.drop.test.ts +3 -1
  330. package/src/core/objects/type/range/range.diff.test.ts +77 -0
  331. package/src/core/objects/type/range/range.diff.ts +39 -101
  332. package/src/core/objects/type/range/range.model.ts +1 -1
  333. package/src/core/objects/view/changes/view.alter.test.ts +8 -3
  334. package/src/core/objects/view/changes/view.create.test.ts +7 -2
  335. package/src/core/objects/view/changes/view.drop.test.ts +4 -1
  336. package/src/core/objects/view/view.diff.test.ts +82 -0
  337. package/src/core/objects/view/view.diff.ts +41 -191
  338. package/src/core/objects/view/view.model.ts +3 -17
  339. package/src/core/plan/apply.ts +9 -27
  340. package/src/core/plan/create.ts +173 -237
  341. package/src/core/plan/serialize.test.ts +317 -0
  342. package/src/core/plan/serialize.ts +18 -4
  343. package/src/core/plan/sql-format/fixtures.ts +2 -5
  344. package/src/core/plan/sql-format/format-lowercase-coverage.test.ts +52 -0
  345. package/src/core/plan/sql-format/format-off.test.ts +14 -17
  346. package/src/core/plan/sql-format/format-pretty-lower-leading.test.ts +27 -22
  347. package/src/core/plan/sql-format/format-pretty-narrow.test.ts +17 -21
  348. package/src/core/plan/sql-format/format-pretty-preserve.test.ts +25 -20
  349. package/src/core/plan/sql-format/format-pretty-upper.test.ts +23 -20
  350. package/src/core/plan/sql-format/keyword-case.ts +36 -1
  351. package/src/core/plan/ssl-config.ts +172 -0
  352. package/src/core/plan/types.ts +6 -0
  353. package/src/core/postgres-config.ts +71 -2
  354. package/src/core/sort/graph-builder.ts +12 -0
  355. package/src/core/sort/logical-sort.test.ts +371 -0
  356. package/src/core/sort/logical-sort.ts +32 -25
  357. package/src/core/sort/topological-sort.test.ts +275 -0
  358. package/src/core/test-utils/assert-valid-sql.ts +20 -0
  359. 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 { Role } from "../role/role.model.ts";
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
- version: number;
44
- currentUser: string;
45
- defaultPrivilegeState: DefaultPrivilegeState;
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
- effectiveDefaults,
96
+ filterPublicBuiltInDefaults("procedure", creatorFilteredDefaults),
96
97
  desiredPrivileges,
97
98
  proc.owner,
98
- ctx.mainRoles,
99
99
  );
100
100
 
101
- // Generate grant changes
102
- for (const [grantee, result] of privilegeResults) {
103
- if (result.grants.length > 0) {
104
- const grantGroups = groupPrivilegesByGrantable(result.grants);
105
- for (const [grantable, list] of grantGroups) {
106
- void grantable;
107
- changes.push(
108
- new GrantProcedurePrivileges({
109
- procedure: proc,
110
- grantee,
111
- privileges: list,
112
- version: ctx.version,
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
- for (const [grantee, result] of privilegeResults) {
356
- // Generate grant changes
357
- if (result.grants.length > 0) {
358
- const grantGroups = groupPrivilegesByGrantable(result.grants);
359
- for (const [grantable, list] of grantGroups) {
360
- void grantable;
361
- changes.push(
362
- new GrantProcedurePrivileges({
363
- procedure: branchProcedure,
364
- grantee,
365
- privileges: list,
366
- version: ctx.version,
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 for all tables serializes and requires publication", () => {
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
- { currentUser: "postgres" },
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
- { currentUser: "postgres" },
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
- { currentUser: "postgres" },
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
- { currentUser: "postgres" },
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
- { currentUser: "postgres" },
118
+ ctx,
115
119
  { [mainPublication.stableId]: mainPublication },
116
120
  { [branchPublication.stableId]: branchPublication },
117
121
  );
118
- expect(
119
- changes.some(
120
- (change) => change instanceof AlterPublicationSetForAllTables,
121
- ),
122
- ).toBe(true);
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
- { currentUser: "postgres" },
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
- { currentUser: "postgres" },
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
- { currentUser: "postgres" },
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
- { currentUser: "postgres" },
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
- { currentUser: "postgres" },
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
- { currentUser: "postgres" },
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
- { currentUser: "postgres" },
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
- { currentUser: "postgres" },
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: { currentUser: string },
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
- if (branchPublication.all_tables) {
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 AlterPublicationSetForAllTables({
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) {