@supabase/pg-delta 1.0.0-alpha.3 → 1.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (463) hide show
  1. package/README.md +22 -0
  2. package/dist/cli/bin/cli.js +0 -0
  3. package/dist/cli/commands/plan.js +21 -0
  4. package/dist/cli/utils.d.ts +2 -0
  5. package/dist/cli/utils.js +1 -1
  6. package/dist/core/objects/table/table.model.d.ts +4 -2
  7. package/dist/core/objects/table/table.model.js +3 -0
  8. package/dist/core/objects/trigger/changes/trigger.alter.js +23 -0
  9. package/dist/core/objects/trigger/changes/trigger.create.js +2 -1
  10. package/dist/core/objects/trigger/trigger.model.d.ts +1 -0
  11. package/dist/core/objects/trigger/trigger.model.js +3 -0
  12. package/dist/core/plan/apply.js +3 -3
  13. package/dist/core/plan/create.js +34 -15
  14. package/dist/core/plan/sql-format/constants.d.ts +2 -0
  15. package/dist/core/plan/sql-format/constants.js +11 -0
  16. package/dist/core/plan/sql-format/fixtures.d.ts +2 -0
  17. package/dist/core/plan/sql-format/fixtures.js +2449 -0
  18. package/dist/core/plan/sql-format/format-utils.d.ts +37 -0
  19. package/dist/core/plan/sql-format/format-utils.js +274 -0
  20. package/dist/core/plan/sql-format/formatters.d.ts +20 -0
  21. package/dist/core/plan/sql-format/formatters.js +737 -0
  22. package/dist/core/plan/sql-format/index.d.ts +2 -0
  23. package/dist/core/plan/sql-format/index.js +98 -0
  24. package/dist/core/plan/sql-format/keyword-case.d.ts +2 -0
  25. package/dist/core/plan/sql-format/keyword-case.js +868 -0
  26. package/dist/core/plan/sql-format/protect.d.ts +3 -0
  27. package/dist/core/plan/sql-format/protect.js +269 -0
  28. package/dist/core/plan/sql-format/sql-scanner.d.ts +59 -0
  29. package/dist/core/plan/sql-format/sql-scanner.js +202 -0
  30. package/dist/core/plan/sql-format/tokenizer.d.ts +22 -0
  31. package/dist/core/plan/sql-format/tokenizer.js +118 -0
  32. package/dist/core/plan/sql-format/types.d.ts +28 -0
  33. package/dist/core/plan/sql-format/types.js +1 -0
  34. package/dist/core/plan/sql-format/wrap.d.ts +2 -0
  35. package/dist/core/plan/sql-format/wrap.js +165 -0
  36. package/dist/core/plan/sql-format.d.ts +2 -0
  37. package/dist/core/plan/sql-format.js +1 -0
  38. package/dist/core/plan/statements.d.ts +2 -1
  39. package/dist/core/plan/statements.js +6 -2
  40. package/dist/core/postgres-config.d.ts +15 -0
  41. package/dist/core/postgres-config.js +30 -0
  42. package/dist/index.d.ts +2 -0
  43. package/dist/index.js +1 -0
  44. package/package.json +37 -22
  45. package/src/cli/app.ts +28 -0
  46. package/src/cli/bin/cli.ts +9 -0
  47. package/src/cli/commands/apply.ts +101 -0
  48. package/src/cli/commands/plan.ts +195 -0
  49. package/src/cli/commands/sync.ts +185 -0
  50. package/src/cli/formatters/index.ts +5 -0
  51. package/src/cli/formatters/tree/tree-builder.ts +380 -0
  52. package/src/cli/formatters/tree/tree-renderer.ts +372 -0
  53. package/src/cli/formatters/tree/tree.ts +237 -0
  54. package/src/cli/utils/integrations.ts +42 -0
  55. package/src/cli/utils.ts +231 -0
  56. package/src/core/catalog.diff.ts +246 -0
  57. package/src/core/catalog.model.ts +384 -0
  58. package/src/core/change.types.ts +44 -0
  59. package/src/core/context.ts +26 -0
  60. package/src/core/depend.ts +1870 -0
  61. package/src/core/expand-replace-dependencies.ts +380 -0
  62. package/src/core/fingerprint.ts +204 -0
  63. package/src/core/integrations/filter/dsl.ts +204 -0
  64. package/src/core/integrations/filter/extractors.ts +145 -0
  65. package/src/core/integrations/filter/filter.types.ts +3 -0
  66. package/src/core/integrations/integration-dsl.ts +24 -0
  67. package/src/core/integrations/integration.types.ts +7 -0
  68. package/src/core/integrations/serialize/dsl.ts +77 -0
  69. package/src/core/integrations/serialize/serialize.types.ts +3 -0
  70. package/src/core/integrations/supabase.ts +121 -0
  71. package/src/core/objects/aggregate/aggregate.diff.test.ts +215 -0
  72. package/src/core/objects/aggregate/aggregate.diff.ts +278 -0
  73. package/src/core/objects/aggregate/aggregate.model.ts +317 -0
  74. package/src/core/objects/aggregate/changes/aggregate.alter.test.ts +64 -0
  75. package/src/core/objects/aggregate/changes/aggregate.alter.ts +32 -0
  76. package/src/core/objects/aggregate/changes/aggregate.base.ts +20 -0
  77. package/src/core/objects/aggregate/changes/aggregate.comment.test.ts +86 -0
  78. package/src/core/objects/aggregate/changes/aggregate.comment.ts +62 -0
  79. package/src/core/objects/aggregate/changes/aggregate.create.test.ts +101 -0
  80. package/src/core/objects/aggregate/changes/aggregate.create.ts +329 -0
  81. package/src/core/objects/aggregate/changes/aggregate.drop.test.ts +78 -0
  82. package/src/core/objects/aggregate/changes/aggregate.drop.ts +32 -0
  83. package/src/core/objects/aggregate/changes/aggregate.privilege.test.ts +130 -0
  84. package/src/core/objects/aggregate/changes/aggregate.privilege.ts +146 -0
  85. package/src/core/objects/aggregate/changes/aggregate.types.ts +12 -0
  86. package/src/core/objects/base.change.ts +62 -0
  87. package/src/core/objects/base.default-privileges.ts +204 -0
  88. package/src/core/objects/base.diff.ts +20 -0
  89. package/src/core/objects/base.model.ts +82 -0
  90. package/src/core/objects/base.privilege-diff.ts +299 -0
  91. package/src/core/objects/base.privilege.ts +184 -0
  92. package/src/core/objects/collation/changes/collation.alter.test.ts +63 -0
  93. package/src/core/objects/collation/changes/collation.alter.ts +79 -0
  94. package/src/core/objects/collation/changes/collation.base.ts +20 -0
  95. package/src/core/objects/collation/changes/collation.comment.ts +68 -0
  96. package/src/core/objects/collation/changes/collation.create.test.ts +51 -0
  97. package/src/core/objects/collation/changes/collation.create.ts +106 -0
  98. package/src/core/objects/collation/changes/collation.drop.test.ts +28 -0
  99. package/src/core/objects/collation/changes/collation.drop.ts +37 -0
  100. package/src/core/objects/collation/changes/collation.types.ts +10 -0
  101. package/src/core/objects/collation/collation.diff.test.ts +100 -0
  102. package/src/core/objects/collation/collation.diff.ts +126 -0
  103. package/src/core/objects/collation/collation.model.ts +224 -0
  104. package/src/core/objects/domain/changes/domain.alter.test.ts +316 -0
  105. package/src/core/objects/domain/changes/domain.alter.ts +286 -0
  106. package/src/core/objects/domain/changes/domain.base.ts +20 -0
  107. package/src/core/objects/domain/changes/domain.comment.ts +59 -0
  108. package/src/core/objects/domain/changes/domain.create.test.ts +65 -0
  109. package/src/core/objects/domain/changes/domain.create.ts +118 -0
  110. package/src/core/objects/domain/changes/domain.drop.test.ts +30 -0
  111. package/src/core/objects/domain/changes/domain.drop.ts +34 -0
  112. package/src/core/objects/domain/changes/domain.privilege.ts +171 -0
  113. package/src/core/objects/domain/changes/domain.types.ts +12 -0
  114. package/src/core/objects/domain/domain.diff.test.ts +284 -0
  115. package/src/core/objects/domain/domain.diff.ts +358 -0
  116. package/src/core/objects/domain/domain.model.ts +190 -0
  117. package/src/core/objects/event-trigger/changes/event-trigger.alter.test.ts +50 -0
  118. package/src/core/objects/event-trigger/changes/event-trigger.alter.ts +82 -0
  119. package/src/core/objects/event-trigger/changes/event-trigger.base.ts +20 -0
  120. package/src/core/objects/event-trigger/changes/event-trigger.comment.ts +66 -0
  121. package/src/core/objects/event-trigger/changes/event-trigger.create.test.ts +24 -0
  122. package/src/core/objects/event-trigger/changes/event-trigger.create.ts +72 -0
  123. package/src/core/objects/event-trigger/changes/event-trigger.drop.test.ts +22 -0
  124. package/src/core/objects/event-trigger/changes/event-trigger.drop.ts +34 -0
  125. package/src/core/objects/event-trigger/changes/event-trigger.types.ts +10 -0
  126. package/src/core/objects/event-trigger/event-trigger.diff.test.ts +126 -0
  127. package/src/core/objects/event-trigger/event-trigger.diff.ts +126 -0
  128. package/src/core/objects/event-trigger/event-trigger.model.ts +106 -0
  129. package/src/core/objects/extension/changes/extension.alter.test.ts +58 -0
  130. package/src/core/objects/extension/changes/extension.alter.ts +78 -0
  131. package/src/core/objects/extension/changes/extension.base.ts +20 -0
  132. package/src/core/objects/extension/changes/extension.comment.ts +64 -0
  133. package/src/core/objects/extension/changes/extension.create.test.ts +25 -0
  134. package/src/core/objects/extension/changes/extension.create.ts +63 -0
  135. package/src/core/objects/extension/changes/extension.drop.test.ts +23 -0
  136. package/src/core/objects/extension/changes/extension.drop.ts +34 -0
  137. package/src/core/objects/extension/changes/extension.types.ts +10 -0
  138. package/src/core/objects/extension/extension.diff.test.ts +42 -0
  139. package/src/core/objects/extension/extension.diff.ts +90 -0
  140. package/src/core/objects/extension/extension.model.ts +280 -0
  141. package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.alter.test.ts +125 -0
  142. package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.alter.ts +101 -0
  143. package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.base.ts +20 -0
  144. package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.comment.ts +72 -0
  145. package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.create.test.ts +125 -0
  146. package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.create.ts +95 -0
  147. package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.drop.test.ts +23 -0
  148. package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.drop.ts +36 -0
  149. package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.privilege.ts +172 -0
  150. package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/changes/foreign-data-wrapper.types.ts +12 -0
  151. package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.diff.test.ts +179 -0
  152. package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.diff.ts +341 -0
  153. package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper/foreign-data-wrapper.model.ts +149 -0
  154. package/src/core/objects/foreign-data-wrapper/foreign-data-wrapper.types.ts +10 -0
  155. package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.alter.test.ts +309 -0
  156. package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.alter.ts +341 -0
  157. package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.base.ts +20 -0
  158. package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.comment.ts +72 -0
  159. package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.create.test.ts +201 -0
  160. package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.create.ts +81 -0
  161. package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.drop.test.ts +43 -0
  162. package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.drop.ts +37 -0
  163. package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.privilege.ts +181 -0
  164. package/src/core/objects/foreign-data-wrapper/foreign-table/changes/foreign-table.types.ts +12 -0
  165. package/src/core/objects/foreign-data-wrapper/foreign-table/foreign-table.diff.test.ts +813 -0
  166. package/src/core/objects/foreign-data-wrapper/foreign-table/foreign-table.diff.ts +406 -0
  167. package/src/core/objects/foreign-data-wrapper/foreign-table/foreign-table.model.ts +242 -0
  168. package/src/core/objects/foreign-data-wrapper/server/changes/server.alter.test.ts +168 -0
  169. package/src/core/objects/foreign-data-wrapper/server/changes/server.alter.ts +126 -0
  170. package/src/core/objects/foreign-data-wrapper/server/changes/server.base.ts +20 -0
  171. package/src/core/objects/foreign-data-wrapper/server/changes/server.comment.ts +60 -0
  172. package/src/core/objects/foreign-data-wrapper/server/changes/server.create.test.ts +131 -0
  173. package/src/core/objects/foreign-data-wrapper/server/changes/server.create.ts +81 -0
  174. package/src/core/objects/foreign-data-wrapper/server/changes/server.drop.test.ts +24 -0
  175. package/src/core/objects/foreign-data-wrapper/server/changes/server.drop.ts +34 -0
  176. package/src/core/objects/foreign-data-wrapper/server/changes/server.privilege.ts +164 -0
  177. package/src/core/objects/foreign-data-wrapper/server/changes/server.types.ts +12 -0
  178. package/src/core/objects/foreign-data-wrapper/server/server.diff.test.ts +167 -0
  179. package/src/core/objects/foreign-data-wrapper/server/server.diff.ts +317 -0
  180. package/src/core/objects/foreign-data-wrapper/server/server.model.ts +133 -0
  181. package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.alter.test.ts +82 -0
  182. package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.alter.ts +69 -0
  183. package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.base.ts +20 -0
  184. package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.create.test.ts +85 -0
  185. package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.create.ts +66 -0
  186. package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.drop.test.ts +53 -0
  187. package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.drop.ts +40 -0
  188. package/src/core/objects/foreign-data-wrapper/user-mapping/changes/user-mapping.types.ts +8 -0
  189. package/src/core/objects/foreign-data-wrapper/user-mapping/user-mapping.diff.test.ts +77 -0
  190. package/src/core/objects/foreign-data-wrapper/user-mapping/user-mapping.diff.ts +107 -0
  191. package/src/core/objects/foreign-data-wrapper/user-mapping/user-mapping.model.ts +96 -0
  192. package/src/core/objects/index/changes/index.alter.test.ts +200 -0
  193. package/src/core/objects/index/changes/index.alter.ts +144 -0
  194. package/src/core/objects/index/changes/index.base.ts +20 -0
  195. package/src/core/objects/index/changes/index.comment.ts +63 -0
  196. package/src/core/objects/index/changes/index.create.test.ts +66 -0
  197. package/src/core/objects/index/changes/index.create.ts +68 -0
  198. package/src/core/objects/index/changes/index.drop.test.ts +44 -0
  199. package/src/core/objects/index/changes/index.drop.ts +34 -0
  200. package/src/core/objects/index/changes/index.types.ts +6 -0
  201. package/src/core/objects/index/changes/utils.ts +16 -0
  202. package/src/core/objects/index/index.diff.test.ts +153 -0
  203. package/src/core/objects/index/index.diff.ts +243 -0
  204. package/src/core/objects/index/index.model.ts +370 -0
  205. package/src/core/objects/language/changes/language.alter.test.ts +33 -0
  206. package/src/core/objects/language/changes/language.alter.ts +53 -0
  207. package/src/core/objects/language/changes/language.base.ts +20 -0
  208. package/src/core/objects/language/changes/language.comment.ts +58 -0
  209. package/src/core/objects/language/changes/language.create.test.ts +27 -0
  210. package/src/core/objects/language/changes/language.create.ts +104 -0
  211. package/src/core/objects/language/changes/language.drop.test.ts +25 -0
  212. package/src/core/objects/language/changes/language.drop.ts +39 -0
  213. package/src/core/objects/language/changes/language.privilege.ts +172 -0
  214. package/src/core/objects/language/changes/language.types.ts +12 -0
  215. package/src/core/objects/language/language.diff.test.ts +53 -0
  216. package/src/core/objects/language/language.diff.ts +176 -0
  217. package/src/core/objects/language/language.model.ts +150 -0
  218. package/src/core/objects/materialized-view/changes/materialized-view.alter.test.ts +123 -0
  219. package/src/core/objects/materialized-view/changes/materialized-view.alter.ts +113 -0
  220. package/src/core/objects/materialized-view/changes/materialized-view.base.ts +20 -0
  221. package/src/core/objects/materialized-view/changes/materialized-view.comment.ts +176 -0
  222. package/src/core/objects/materialized-view/changes/materialized-view.create.test.ts +64 -0
  223. package/src/core/objects/materialized-view/changes/materialized-view.create.ts +93 -0
  224. package/src/core/objects/materialized-view/changes/materialized-view.drop.test.ts +34 -0
  225. package/src/core/objects/materialized-view/changes/materialized-view.drop.ts +60 -0
  226. package/src/core/objects/materialized-view/changes/materialized-view.privilege.ts +212 -0
  227. package/src/core/objects/materialized-view/changes/materialized-view.types.ts +12 -0
  228. package/src/core/objects/materialized-view/materialized-view.diff.test.ts +102 -0
  229. package/src/core/objects/materialized-view/materialized-view.diff.ts +451 -0
  230. package/src/core/objects/materialized-view/materialized-view.model.ts +258 -0
  231. package/src/core/objects/procedure/changes/procedure.alter.test.ts +1005 -0
  232. package/src/core/objects/procedure/changes/procedure.alter.ts +287 -0
  233. package/src/core/objects/procedure/changes/procedure.base.ts +20 -0
  234. package/src/core/objects/procedure/changes/procedure.comment.ts +70 -0
  235. package/src/core/objects/procedure/changes/procedure.create.test.ts +48 -0
  236. package/src/core/objects/procedure/changes/procedure.create.ts +92 -0
  237. package/src/core/objects/procedure/changes/procedure.drop.test.ts +85 -0
  238. package/src/core/objects/procedure/changes/procedure.drop.ts +49 -0
  239. package/src/core/objects/procedure/changes/procedure.privilege.ts +188 -0
  240. package/src/core/objects/procedure/changes/procedure.types.ts +12 -0
  241. package/src/core/objects/procedure/procedure.diff.test.ts +161 -0
  242. package/src/core/objects/procedure/procedure.diff.ts +404 -0
  243. package/src/core/objects/procedure/procedure.model.ts +264 -0
  244. package/src/core/objects/procedure/utils.ts +58 -0
  245. package/src/core/objects/publication/changes/publication.alter.test.ts +223 -0
  246. package/src/core/objects/publication/changes/publication.alter.ts +243 -0
  247. package/src/core/objects/publication/changes/publication.base.ts +20 -0
  248. package/src/core/objects/publication/changes/publication.comment.test.ts +70 -0
  249. package/src/core/objects/publication/changes/publication.comment.ts +64 -0
  250. package/src/core/objects/publication/changes/publication.create.test.ts +87 -0
  251. package/src/core/objects/publication/changes/publication.create.ts +82 -0
  252. package/src/core/objects/publication/changes/publication.drop.test.ts +46 -0
  253. package/src/core/objects/publication/changes/publication.drop.ts +29 -0
  254. package/src/core/objects/publication/changes/publication.types.ts +26 -0
  255. package/src/core/objects/publication/publication.diff.test.ts +292 -0
  256. package/src/core/objects/publication/publication.diff.ts +253 -0
  257. package/src/core/objects/publication/publication.model.ts +206 -0
  258. package/src/core/objects/publication/utils.ts +55 -0
  259. package/src/core/objects/rls-policy/changes/rls-policy.alter.test.ts +250 -0
  260. package/src/core/objects/rls-policy/changes/rls-policy.alter.ts +128 -0
  261. package/src/core/objects/rls-policy/changes/rls-policy.base.ts +20 -0
  262. package/src/core/objects/rls-policy/changes/rls-policy.comment.ts +69 -0
  263. package/src/core/objects/rls-policy/changes/rls-policy.create.test.ts +74 -0
  264. package/src/core/objects/rls-policy/changes/rls-policy.create.ts +100 -0
  265. package/src/core/objects/rls-policy/changes/rls-policy.drop.test.ts +28 -0
  266. package/src/core/objects/rls-policy/changes/rls-policy.drop.ts +39 -0
  267. package/src/core/objects/rls-policy/changes/rls-policy.types.ts +10 -0
  268. package/src/core/objects/rls-policy/rls-policy.diff.test.ts +79 -0
  269. package/src/core/objects/rls-policy/rls-policy.diff.ts +121 -0
  270. package/src/core/objects/rls-policy/rls-policy.model.ts +140 -0
  271. package/src/core/objects/role/changes/role.alter.test.ts +346 -0
  272. package/src/core/objects/role/changes/role.alter.ts +110 -0
  273. package/src/core/objects/role/changes/role.base.ts +24 -0
  274. package/src/core/objects/role/changes/role.comment.ts +55 -0
  275. package/src/core/objects/role/changes/role.create.test.ts +52 -0
  276. package/src/core/objects/role/changes/role.create.ts +102 -0
  277. package/src/core/objects/role/changes/role.drop.test.ts +29 -0
  278. package/src/core/objects/role/changes/role.drop.ts +34 -0
  279. package/src/core/objects/role/changes/role.privilege.ts +376 -0
  280. package/src/core/objects/role/changes/role.types.ts +12 -0
  281. package/src/core/objects/role/role.diff.test.ts +44 -0
  282. package/src/core/objects/role/role.diff.ts +479 -0
  283. package/src/core/objects/role/role.model.ts +344 -0
  284. package/src/core/objects/rule/changes/rule.alter.test.ts +78 -0
  285. package/src/core/objects/rule/changes/rule.alter.ts +72 -0
  286. package/src/core/objects/rule/changes/rule.base.ts +20 -0
  287. package/src/core/objects/rule/changes/rule.comment.test.ts +55 -0
  288. package/src/core/objects/rule/changes/rule.comment.ts +62 -0
  289. package/src/core/objects/rule/changes/rule.create.test.ts +59 -0
  290. package/src/core/objects/rule/changes/rule.create.ts +42 -0
  291. package/src/core/objects/rule/changes/rule.drop.test.ts +38 -0
  292. package/src/core/objects/rule/changes/rule.drop.ts +29 -0
  293. package/src/core/objects/rule/changes/rule.types.ts +12 -0
  294. package/src/core/objects/rule/rule.diff.test.ts +132 -0
  295. package/src/core/objects/rule/rule.diff.ts +79 -0
  296. package/src/core/objects/rule/rule.model.ts +173 -0
  297. package/src/core/objects/schema/changes/schema.alter.test.ts +28 -0
  298. package/src/core/objects/schema/changes/schema.alter.ts +45 -0
  299. package/src/core/objects/schema/changes/schema.base.ts +20 -0
  300. package/src/core/objects/schema/changes/schema.comment.ts +56 -0
  301. package/src/core/objects/schema/changes/schema.create.test.ts +22 -0
  302. package/src/core/objects/schema/changes/schema.create.ts +47 -0
  303. package/src/core/objects/schema/changes/schema.drop.test.ts +20 -0
  304. package/src/core/objects/schema/changes/schema.drop.ts +34 -0
  305. package/src/core/objects/schema/changes/schema.privilege.ts +175 -0
  306. package/src/core/objects/schema/changes/schema.types.ts +12 -0
  307. package/src/core/objects/schema/schema.diff.test.ts +42 -0
  308. package/src/core/objects/schema/schema.diff.ts +209 -0
  309. package/src/core/objects/schema/schema.model.ts +107 -0
  310. package/src/core/objects/sequence/changes/sequence.alter.test.ts +151 -0
  311. package/src/core/objects/sequence/changes/sequence.alter.ts +115 -0
  312. package/src/core/objects/sequence/changes/sequence.base.ts +20 -0
  313. package/src/core/objects/sequence/changes/sequence.comment.ts +60 -0
  314. package/src/core/objects/sequence/changes/sequence.create.test.ts +84 -0
  315. package/src/core/objects/sequence/changes/sequence.create.ts +111 -0
  316. package/src/core/objects/sequence/changes/sequence.drop.test.ts +32 -0
  317. package/src/core/objects/sequence/changes/sequence.drop.ts +37 -0
  318. package/src/core/objects/sequence/changes/sequence.privilege.ts +179 -0
  319. package/src/core/objects/sequence/changes/sequence.types.ts +12 -0
  320. package/src/core/objects/sequence/sequence.diff.test.ts +141 -0
  321. package/src/core/objects/sequence/sequence.diff.ts +359 -0
  322. package/src/core/objects/sequence/sequence.model.ts +185 -0
  323. package/src/core/objects/subscription/changes/subscription.alter.test.ts +124 -0
  324. package/src/core/objects/subscription/changes/subscription.alter.ts +110 -0
  325. package/src/core/objects/subscription/changes/subscription.base.ts +20 -0
  326. package/src/core/objects/subscription/changes/subscription.comment.test.ts +67 -0
  327. package/src/core/objects/subscription/changes/subscription.comment.ts +64 -0
  328. package/src/core/objects/subscription/changes/subscription.create.test.ts +77 -0
  329. package/src/core/objects/subscription/changes/subscription.create.ts +69 -0
  330. package/src/core/objects/subscription/changes/subscription.drop.test.ts +46 -0
  331. package/src/core/objects/subscription/changes/subscription.drop.ts +20 -0
  332. package/src/core/objects/subscription/changes/subscription.types.ts +22 -0
  333. package/src/core/objects/subscription/subscription.diff.test.ts +232 -0
  334. package/src/core/objects/subscription/subscription.diff.ts +241 -0
  335. package/src/core/objects/subscription/subscription.model.ts +190 -0
  336. package/src/core/objects/subscription/utils.ts +156 -0
  337. package/src/core/objects/table/changes/table.alter.test.ts +823 -0
  338. package/src/core/objects/table/changes/table.alter.ts +806 -0
  339. package/src/core/objects/table/changes/table.base.ts +20 -0
  340. package/src/core/objects/table/changes/table.comment.ts +266 -0
  341. package/src/core/objects/table/changes/table.create.test.ts +150 -0
  342. package/src/core/objects/table/changes/table.create.ts +188 -0
  343. package/src/core/objects/table/changes/table.drop.test.ts +34 -0
  344. package/src/core/objects/table/changes/table.drop.ts +45 -0
  345. package/src/core/objects/table/changes/table.privilege.ts +200 -0
  346. package/src/core/objects/table/changes/table.types.ts +12 -0
  347. package/src/core/objects/table/table.diff.test.ts +711 -0
  348. package/src/core/objects/table/table.diff.ts +953 -0
  349. package/src/core/objects/table/table.model.ts +460 -0
  350. package/src/core/objects/trigger/changes/trigger.alter.test.ts +46 -0
  351. package/src/core/objects/trigger/changes/trigger.alter.ts +76 -0
  352. package/src/core/objects/trigger/changes/trigger.base.ts +20 -0
  353. package/src/core/objects/trigger/changes/trigger.comment.ts +64 -0
  354. package/src/core/objects/trigger/changes/trigger.create.test.ts +43 -0
  355. package/src/core/objects/trigger/changes/trigger.create.ts +85 -0
  356. package/src/core/objects/trigger/changes/trigger.drop.test.ts +43 -0
  357. package/src/core/objects/trigger/changes/trigger.drop.ts +39 -0
  358. package/src/core/objects/trigger/changes/trigger.types.ts +10 -0
  359. package/src/core/objects/trigger/trigger.diff.test.ts +83 -0
  360. package/src/core/objects/trigger/trigger.diff.ts +116 -0
  361. package/src/core/objects/trigger/trigger.model.ts +252 -0
  362. package/src/core/objects/type/composite-type/changes/composite-type.alter.test.ts +202 -0
  363. package/src/core/objects/type/composite-type/changes/composite-type.alter.ts +174 -0
  364. package/src/core/objects/type/composite-type/changes/composite-type.base.ts +20 -0
  365. package/src/core/objects/type/composite-type/changes/composite-type.comment.ts +145 -0
  366. package/src/core/objects/type/composite-type/changes/composite-type.create.test.ts +101 -0
  367. package/src/core/objects/type/composite-type/changes/composite-type.create.ts +95 -0
  368. package/src/core/objects/type/composite-type/changes/composite-type.drop.test.ts +33 -0
  369. package/src/core/objects/type/composite-type/changes/composite-type.drop.ts +37 -0
  370. package/src/core/objects/type/composite-type/changes/composite-type.privilege.ts +175 -0
  371. package/src/core/objects/type/composite-type/changes/composite-type.types.ts +12 -0
  372. package/src/core/objects/type/composite-type/composite-type.diff.test.ts +191 -0
  373. package/src/core/objects/type/composite-type/composite-type.diff.ts +372 -0
  374. package/src/core/objects/type/composite-type/composite-type.model.ts +252 -0
  375. package/src/core/objects/type/enum/changes/enum.alter.test.ts +104 -0
  376. package/src/core/objects/type/enum/changes/enum.alter.ts +91 -0
  377. package/src/core/objects/type/enum/changes/enum.base.ts +20 -0
  378. package/src/core/objects/type/enum/changes/enum.comment.ts +64 -0
  379. package/src/core/objects/type/enum/changes/enum.create.test.ts +28 -0
  380. package/src/core/objects/type/enum/changes/enum.create.ts +56 -0
  381. package/src/core/objects/type/enum/changes/enum.drop.test.ts +25 -0
  382. package/src/core/objects/type/enum/changes/enum.drop.ts +34 -0
  383. package/src/core/objects/type/enum/changes/enum.privilege.ts +175 -0
  384. package/src/core/objects/type/enum/changes/enum.types.ts +12 -0
  385. package/src/core/objects/type/enum/enum.diff.test.ts +191 -0
  386. package/src/core/objects/type/enum/enum.diff.ts +396 -0
  387. package/src/core/objects/type/enum/enum.model.ts +194 -0
  388. package/src/core/objects/type/range/changes/range.alter.test.ts +27 -0
  389. package/src/core/objects/type/range/changes/range.alter.ts +51 -0
  390. package/src/core/objects/type/range/changes/range.base.ts +20 -0
  391. package/src/core/objects/type/range/changes/range.comment.ts +64 -0
  392. package/src/core/objects/type/range/changes/range.create.test.ts +51 -0
  393. package/src/core/objects/type/range/changes/range.create.ts +151 -0
  394. package/src/core/objects/type/range/changes/range.drop.test.ts +26 -0
  395. package/src/core/objects/type/range/changes/range.drop.ts +34 -0
  396. package/src/core/objects/type/range/changes/range.privilege.ts +175 -0
  397. package/src/core/objects/type/range/changes/range.types.ts +12 -0
  398. package/src/core/objects/type/range/range.diff.test.ts +70 -0
  399. package/src/core/objects/type/range/range.diff.ts +259 -0
  400. package/src/core/objects/type/range/range.model.ts +187 -0
  401. package/src/core/objects/type/type.types.ts +5 -0
  402. package/src/core/objects/utils.ts +171 -0
  403. package/src/core/objects/view/changes/view.alter.test.ts +110 -0
  404. package/src/core/objects/view/changes/view.alter.ts +112 -0
  405. package/src/core/objects/view/changes/view.base.ts +20 -0
  406. package/src/core/objects/view/changes/view.comment.ts +59 -0
  407. package/src/core/objects/view/changes/view.create.test.ts +65 -0
  408. package/src/core/objects/view/changes/view.create.ts +73 -0
  409. package/src/core/objects/view/changes/view.drop.test.ts +34 -0
  410. package/src/core/objects/view/changes/view.drop.ts +40 -0
  411. package/src/core/objects/view/changes/view.privilege.ts +200 -0
  412. package/src/core/objects/view/changes/view.types.ts +12 -0
  413. package/src/core/objects/view/view.diff.test.ts +91 -0
  414. package/src/core/objects/view/view.diff.ts +365 -0
  415. package/src/core/objects/view/view.model.ts +276 -0
  416. package/src/core/plan/apply.ts +190 -0
  417. package/src/core/plan/create.ts +432 -0
  418. package/src/core/plan/hierarchy.ts +574 -0
  419. package/src/core/plan/index.ts +29 -0
  420. package/src/core/plan/io.ts +20 -0
  421. package/src/core/plan/risk.ts +48 -0
  422. package/src/core/plan/serialize.ts +195 -0
  423. package/src/core/plan/sql-format/constants.ts +13 -0
  424. package/src/core/plan/sql-format/fixtures.ts +2806 -0
  425. package/src/core/plan/sql-format/format-comment-literals.test.ts +96 -0
  426. package/src/core/plan/sql-format/format-functions.test.ts +127 -0
  427. package/src/core/plan/sql-format/format-lowercase-coverage.test.ts +67 -0
  428. package/src/core/plan/sql-format/format-off.test.ts +809 -0
  429. package/src/core/plan/sql-format/format-pretty-lower-leading.test.ts +1056 -0
  430. package/src/core/plan/sql-format/format-pretty-narrow.test.ts +1283 -0
  431. package/src/core/plan/sql-format/format-pretty-preserve.test.ts +1052 -0
  432. package/src/core/plan/sql-format/format-pretty-upper.test.ts +1045 -0
  433. package/src/core/plan/sql-format/format-stress.test.ts +616 -0
  434. package/src/core/plan/sql-format/format-utils.test.ts +91 -0
  435. package/src/core/plan/sql-format/format-utils.ts +391 -0
  436. package/src/core/plan/sql-format/formatters.ts +921 -0
  437. package/src/core/plan/sql-format/index.ts +149 -0
  438. package/src/core/plan/sql-format/keyword-case.test.ts +118 -0
  439. package/src/core/plan/sql-format/keyword-case.ts +1085 -0
  440. package/src/core/plan/sql-format/protect.test.ts +127 -0
  441. package/src/core/plan/sql-format/protect.ts +337 -0
  442. package/src/core/plan/sql-format/sql-scanner.test.ts +240 -0
  443. package/src/core/plan/sql-format/sql-scanner.ts +252 -0
  444. package/src/core/plan/sql-format/tokenizer.test.ts +68 -0
  445. package/src/core/plan/sql-format/tokenizer.ts +152 -0
  446. package/src/core/plan/sql-format/types.ts +31 -0
  447. package/src/core/plan/sql-format/wrap.test.ts +119 -0
  448. package/src/core/plan/sql-format/wrap.ts +196 -0
  449. package/src/core/plan/sql-format.ts +2 -0
  450. package/src/core/plan/statements.ts +22 -0
  451. package/src/core/plan/types.ts +165 -0
  452. package/src/core/postgres-config.ts +169 -0
  453. package/src/core/sort/custom-constraints.ts +161 -0
  454. package/src/core/sort/debug-visualization.ts +239 -0
  455. package/src/core/sort/dependency-filter.ts +224 -0
  456. package/src/core/sort/graph-builder.ts +223 -0
  457. package/src/core/sort/graph-utils.ts +51 -0
  458. package/src/core/sort/logical-sort.ts +590 -0
  459. package/src/core/sort/sort-changes.ts +234 -0
  460. package/src/core/sort/topological-sort.ts +184 -0
  461. package/src/core/sort/types.ts +112 -0
  462. package/src/core/sort/utils.ts +69 -0
  463. package/src/index.ts +14 -0
@@ -0,0 +1,1052 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { renderScript } from "./fixtures.ts";
3
+
4
+ describe("sql formatting snapshots", () => {
5
+ test("format-pretty-preserve", () => {
6
+ const output = [
7
+ "-- format: { keywordCase: 'preserve', alignColumns: false, alignKeyValues: false, indent: 3 }",
8
+ renderScript({
9
+ keywordCase: "preserve",
10
+ alignColumns: false,
11
+ alignKeyValues: false,
12
+ indent: 3,
13
+ }),
14
+ ]
15
+ .filter(Boolean)
16
+ .join("\n");
17
+ expect(output).toMatchInlineSnapshot(`
18
+ "-- format: { keywordCase: 'preserve', alignColumns: false, alignKeyValues: false, indent: 3 }
19
+ -- schema.create
20
+ CREATE SCHEMA application_schema_with_very_long_name_for_wrapping_tests AUTHORIZATION admin;
21
+
22
+ -- schema.drop
23
+ DROP SCHEMA application_schema_with_very_long_name_for_wrapping_tests;
24
+
25
+ -- schema.alter.change_owner
26
+ ALTER SCHEMA application_schema_with_very_long_name_for_wrapping_tests OWNER TO new_admin;
27
+
28
+ -- schema.comment
29
+ COMMENT ON SCHEMA application_schema_with_very_long_name_for_wrapping_tests IS
30
+ 'application schema';
31
+
32
+ -- schema.drop_comment
33
+ COMMENT ON SCHEMA application_schema_with_very_long_name_for_wrapping_tests IS NULL;
34
+
35
+ -- schema.grant
36
+ GRANT ALL ON SCHEMA application_schema_with_very_long_name_for_wrapping_tests TO app_user
37
+ WITH GRANT OPTION;
38
+
39
+ -- schema.revoke
40
+ REVOKE CREATE ON SCHEMA application_schema_with_very_long_name_for_wrapping_tests FROM app_user;
41
+
42
+ -- schema.revoke_grant_option
43
+ REVOKE GRANT OPTION FOR USAGE
44
+ ON SCHEMA application_schema_with_very_long_name_for_wrapping_tests FROM app_user;
45
+
46
+ -- extension.create
47
+ CREATE EXTENSION pgcrypto WITH SCHEMA extensions;
48
+
49
+ -- extension.drop
50
+ DROP EXTENSION pgcrypto;
51
+
52
+ -- extension.alter.update_version
53
+ ALTER EXTENSION pgcrypto UPDATE TO '1.4';
54
+
55
+ -- extension.alter.set_schema
56
+ ALTER EXTENSION pgcrypto SET SCHEMA public;
57
+
58
+ -- extension.comment
59
+ COMMENT ON EXTENSION pgcrypto IS 'cryptographic functions';
60
+
61
+ -- extension.drop_comment
62
+ COMMENT ON EXTENSION pgcrypto IS NULL;
63
+
64
+ -- domain.create
65
+ CREATE DOMAIN public.test_domain_all AS custom.text[][]
66
+ COLLATE mycoll
67
+ DEFAULT 'hello'
68
+ NOT NULL
69
+ CHECK (VALUE <> '');
70
+
71
+ -- domain.drop
72
+ DROP DOMAIN public.test_domain_all;
73
+
74
+ -- domain.alter.set_default
75
+ ALTER DOMAIN public.test_domain_all
76
+ SET DEFAULT 'world';
77
+
78
+ -- domain.alter.drop_default
79
+ ALTER DOMAIN public.test_domain_all
80
+ DROP DEFAULT;
81
+
82
+ -- domain.alter.set_not_null
83
+ ALTER DOMAIN public.test_domain_all
84
+ SET NOT NULL;
85
+
86
+ -- domain.alter.drop_not_null
87
+ ALTER DOMAIN public.test_domain_all
88
+ DROP NOT NULL;
89
+
90
+ -- domain.alter.change_owner
91
+ ALTER DOMAIN public.test_domain_all
92
+ OWNER TO new_owner;
93
+
94
+ -- domain.alter.add_constraint
95
+ ALTER DOMAIN public.test_domain_all
96
+ ADD CONSTRAINT domain_len_chk CHECK (char_length(VALUE) <= 255) NOT VALID;
97
+
98
+ -- domain.alter.drop_constraint
99
+ ALTER DOMAIN public.test_domain_all
100
+ DROP CONSTRAINT domain_chk;
101
+
102
+ -- domain.alter.validate_constraint
103
+ ALTER DOMAIN public.test_domain_all
104
+ VALIDATE CONSTRAINT domain_len_chk;
105
+
106
+ -- domain.comment
107
+ COMMENT ON DOMAIN public.test_domain_all IS 'domain comment';
108
+
109
+ -- domain.drop_comment
110
+ COMMENT ON DOMAIN public.test_domain_all IS NULL;
111
+
112
+ -- domain.grant
113
+ GRANT ALL ON DOMAIN public.test_domain_all TO app_user;
114
+
115
+ -- domain.revoke
116
+ REVOKE ALL ON DOMAIN public.test_domain_all FROM app_user;
117
+
118
+ -- domain.revoke_grant_option
119
+ REVOKE GRANT OPTION FOR ALL ON DOMAIN public.test_domain_all FROM app_user;
120
+
121
+ -- type.enum.create
122
+ CREATE TYPE public.test_enum AS ENUM (
123
+ 'value1',
124
+ 'value2',
125
+ 'value3'
126
+ );
127
+
128
+ -- type.enum.drop
129
+ DROP TYPE public.test_enum;
130
+
131
+ -- type.enum.alter.change_owner
132
+ ALTER TYPE public.test_enum OWNER TO new_owner;
133
+
134
+ -- type.enum.alter.add_value
135
+ ALTER TYPE public.test_enum ADD VALUE 'value4' AFTER 'value2';
136
+
137
+ -- type.enum.comment
138
+ COMMENT ON TYPE public.test_enum IS 'enum comment';
139
+
140
+ -- type.enum.drop_comment
141
+ COMMENT ON TYPE public.test_enum IS NULL;
142
+
143
+ -- type.enum.grant
144
+ GRANT ALL ON TYPE public.test_enum TO app_user;
145
+
146
+ -- type.enum.revoke
147
+ REVOKE ALL ON TYPE public.test_enum FROM app_user;
148
+
149
+ -- type.enum.revoke_grant_option
150
+ REVOKE GRANT OPTION FOR ALL ON TYPE public.test_enum FROM app_user;
151
+
152
+ -- type.composite.create
153
+ CREATE TYPE public.test_type AS (
154
+ id integer,
155
+ name text COLLATE "en_US"
156
+ );
157
+
158
+ -- type.composite.drop
159
+ DROP TYPE public.test_type;
160
+
161
+ -- type.composite.alter.change_owner
162
+ ALTER TYPE public.test_type OWNER TO new_owner;
163
+
164
+ -- type.composite.alter.add_attribute
165
+ ALTER TYPE public.test_type ADD ATTRIBUTE age integer;
166
+
167
+ -- type.composite.alter.drop_attribute
168
+ ALTER TYPE public.test_type DROP ATTRIBUTE name;
169
+
170
+ -- type.composite.alter.alter_attr_type
171
+ ALTER TYPE public.test_type ALTER ATTRIBUTE name TYPE varchar(255) COLLATE "C";
172
+
173
+ -- type.composite.comment
174
+ COMMENT ON TYPE public.test_type IS 'composite comment';
175
+
176
+ -- type.composite.drop_comment
177
+ COMMENT ON TYPE public.test_type IS NULL;
178
+
179
+ -- type.composite.attr_comment
180
+ COMMENT ON COLUMN public.test_type.id IS 'attr comment';
181
+
182
+ -- type.composite.drop_attr_comment
183
+ COMMENT ON COLUMN public.test_type.id IS NULL;
184
+
185
+ -- type.composite.grant
186
+ GRANT ALL ON TYPE public.test_type TO app_user;
187
+
188
+ -- type.composite.revoke
189
+ REVOKE ALL ON TYPE public.test_type FROM app_user;
190
+
191
+ -- type.composite.revoke_grant_option
192
+ REVOKE GRANT OPTION FOR ALL ON TYPE public.test_type FROM app_user;
193
+
194
+ -- type.range.create
195
+ CREATE TYPE public.daterange_custom AS RANGE (
196
+ SUBTYPE = date,
197
+ SUBTYPE_OPCLASS = public.date_ops,
198
+ COLLATION = "en_US",
199
+ CANONICAL = public.canon_fn,
200
+ SUBTYPE_DIFF = public.diff_fn
201
+ );
202
+
203
+ -- type.range.drop
204
+ DROP TYPE public.daterange_custom;
205
+
206
+ -- type.range.alter.change_owner
207
+ ALTER TYPE public.daterange_custom OWNER TO new_owner;
208
+
209
+ -- type.range.comment
210
+ COMMENT ON TYPE public.daterange_custom IS 'range comment';
211
+
212
+ -- type.range.drop_comment
213
+ COMMENT ON TYPE public.daterange_custom IS NULL;
214
+
215
+ -- type.range.grant
216
+ GRANT ALL ON TYPE public.daterange_custom TO app_user;
217
+
218
+ -- type.range.revoke
219
+ REVOKE ALL ON TYPE public.daterange_custom FROM app_user;
220
+
221
+ -- type.range.revoke_grant_option
222
+ REVOKE GRANT OPTION FOR ALL ON TYPE public.daterange_custom FROM app_user;
223
+
224
+ -- collation.create
225
+ CREATE COLLATION public.test (
226
+ LOCALE = 'en_US',
227
+ LC_COLLATE = 'en_US',
228
+ LC_CTYPE = 'en_US',
229
+ PROVIDER = icu,
230
+ DETERMINISTIC = false,
231
+ RULES = '& A < a <<< à',
232
+ VERSION = '1.0'
233
+ );
234
+
235
+ -- collation.drop
236
+ DROP COLLATION public.test;
237
+
238
+ -- collation.alter.change_owner
239
+ ALTER COLLATION public.test OWNER TO new_owner;
240
+
241
+ -- collation.alter.refresh_version
242
+ ALTER COLLATION public.test REFRESH VERSION;
243
+
244
+ -- collation.comment
245
+ COMMENT ON COLLATION public.test IS 'collation comment';
246
+
247
+ -- collation.drop_comment
248
+ COMMENT ON COLLATION public.test IS NULL;
249
+
250
+ -- table.create
251
+ CREATE TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test (
252
+ id bigint GENERATED ALWAYS AS IDENTITY NOT NULL,
253
+ status text COLLATE "en_US" DEFAULT 'pending',
254
+ created_at timestamptz DEFAULT now(),
255
+ ref_id bigint,
256
+ computed bigint GENERATED ALWAYS AS (id * 2) STORED
257
+ ) WITH (fillfactor=70, autovacuum_enabled=false);
258
+
259
+ -- table.drop
260
+ DROP TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test;
261
+
262
+ -- table.alter.add_column
263
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
264
+ ADD COLUMN email text COLLATE "en_US" DEFAULT 'user@example.com' NOT NULL;
265
+
266
+ -- table.alter.drop_column
267
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
268
+ DROP COLUMN computed;
269
+
270
+ -- table.alter.column_type
271
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
272
+ ALTER COLUMN status TYPE character varying(255) COLLATE "C";
273
+
274
+ -- table.alter.column_set_default
275
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
276
+ ALTER COLUMN status SET DEFAULT 'active';
277
+
278
+ -- table.alter.column_drop_default
279
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
280
+ ALTER COLUMN status DROP DEFAULT;
281
+
282
+ -- table.alter.column_set_not_null
283
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
284
+ ALTER COLUMN status SET NOT NULL;
285
+
286
+ -- table.alter.column_drop_not_null
287
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
288
+ ALTER COLUMN status DROP NOT NULL;
289
+
290
+ -- table.alter.add_constraint
291
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
292
+ ADD CONSTRAINT uq_t_fmt_status UNIQUE (status);
293
+
294
+ -- table.alter.add_fk_constraint
295
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
296
+ ADD CONSTRAINT fk_t_fmt_ref FOREIGN KEY (ref_id) REFERENCES public.other_table(id) MATCH FULL
297
+ ON UPDATE SET NULL ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
298
+
299
+ -- table.alter.drop_constraint
300
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
301
+ DROP CONSTRAINT uq_t_fmt_status;
302
+
303
+ -- table.alter.validate_constraint
304
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
305
+ VALIDATE CONSTRAINT chk_t_fmt_status;
306
+
307
+ -- table.alter.change_owner
308
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
309
+ OWNER TO new_owner;
310
+
311
+ -- table.alter.set_logged
312
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
313
+ SET LOGGED;
314
+
315
+ -- table.alter.set_unlogged
316
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
317
+ SET UNLOGGED;
318
+
319
+ -- table.alter.enable_rls
320
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
321
+ ENABLE ROW LEVEL SECURITY;
322
+
323
+ -- table.alter.disable_rls
324
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
325
+ DISABLE ROW LEVEL SECURITY;
326
+
327
+ -- table.alter.force_rls
328
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
329
+ FORCE ROW LEVEL SECURITY;
330
+
331
+ -- table.alter.no_force_rls
332
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
333
+ NO FORCE ROW LEVEL SECURITY;
334
+
335
+ -- table.alter.set_storage_params
336
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
337
+ SET (fillfactor=80, autovacuum_enabled=true);
338
+
339
+ -- table.alter.reset_storage_params
340
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
341
+ RESET (fillfactor, autovacuum_enabled);
342
+
343
+ -- table.alter.replica_identity
344
+ ALTER TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test
345
+ REPLICA IDENTITY FULL;
346
+
347
+ -- table.alter.attach_partition
348
+ ALTER TABLE public.events
349
+ ATTACH PARTITION public.events_2024 FOR VALUES FROM ('2024-01-01') TO ('2025-01-01');
350
+
351
+ -- table.alter.detach_partition
352
+ ALTER TABLE public.events
353
+ DETACH PARTITION public.events_2024;
354
+
355
+ -- table.comment
356
+ COMMENT ON TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test IS
357
+ 'table comment';
358
+
359
+ -- table.drop_comment
360
+ COMMENT ON TABLE public.table_with_very_long_name_for_formatting_and_wrapping_test IS NULL;
361
+
362
+ -- table.column_comment
363
+ COMMENT ON COLUMN public.table_with_very_long_name_for_formatting_and_wrapping_test.id IS
364
+ 'id column';
365
+
366
+ -- table.drop_column_comment
367
+ COMMENT ON COLUMN public.table_with_very_long_name_for_formatting_and_wrapping_test.id IS NULL;
368
+
369
+ -- table.constraint_comment
370
+ COMMENT ON CONSTRAINT pk_t_fmt
371
+ ON public.table_with_very_long_name_for_formatting_and_wrapping_test IS 'primary key';
372
+
373
+ -- table.drop_constraint_comment
374
+ COMMENT ON CONSTRAINT chk_t_fmt_status
375
+ ON public.table_with_very_long_name_for_formatting_and_wrapping_test IS NULL;
376
+
377
+ -- table.grant
378
+ GRANT INSERT,
379
+ SELECT ON public.table_with_very_long_name_for_formatting_and_wrapping_test TO app_reader;
380
+
381
+ -- table.revoke
382
+ REVOKE DELETE,
383
+ UPDATE ON public.table_with_very_long_name_for_formatting_and_wrapping_test FROM app_reader;
384
+
385
+ -- table.revoke_grant_option
386
+ REVOKE GRANT OPTION FOR INSERT,
387
+ SELECT ON public.table_with_very_long_name_for_formatting_and_wrapping_test FROM app_reader;
388
+
389
+ -- publication.create
390
+ CREATE PUBLICATION pub_custom FOR TABLE
391
+ public.articles_with_a_very_long_name_very_very_long_name_that_will_go_above_the_wrapping_limit (
392
+ id,
393
+ title
394
+ ) WHERE (published = true),
395
+ TABLE public.comments_a_little_smaller_name_than_the_previous_one, TABLES IN SCHEMA analytics;
396
+
397
+ -- publication.drop
398
+ DROP PUBLICATION pub_custom;
399
+
400
+ -- publication.alter.set_options
401
+ ALTER PUBLICATION pub_custom
402
+ SET (publish = 'insert, update, delete, truncate', publish_via_partition_root = false);
403
+
404
+ -- publication.alter.set_all_tables
405
+ ALTER PUBLICATION pub_custom SET FOR ALL TABLES;
406
+
407
+ -- publication.alter.set_list
408
+ ALTER PUBLICATION pub_custom
409
+ SET TABLE
410
+ public.articles_with_a_very_long_name_very_very_long_name_that_will_go_above_the_wrapping_limit
411
+ (id, title) WHERE (published = true),
412
+ TABLE public.comments_a_little_smaller_name_than_the_previous_one, TABLES IN SCHEMA analytics;
413
+
414
+ -- publication.alter.add_tables
415
+ ALTER PUBLICATION pub_custom
416
+ ADD TABLE public.new_table_with_very_long_name_for_formatting_and_wrapping_test;
417
+
418
+ -- publication.alter.drop_tables
419
+ ALTER PUBLICATION pub_custom DROP TABLE public.comments_a_little_smaller_name_than_the_previous_one;
420
+
421
+ -- publication.alter.add_schemas
422
+ ALTER PUBLICATION pub_custom ADD TABLES IN SCHEMA staging;
423
+
424
+ -- publication.alter.drop_schemas
425
+ ALTER PUBLICATION pub_custom DROP TABLES IN SCHEMA analytics;
426
+
427
+ -- publication.alter.set_owner
428
+ ALTER PUBLICATION pub_custom OWNER TO new_owner;
429
+
430
+ -- publication.comment
431
+ COMMENT ON PUBLICATION pub_custom IS 'publication comment';
432
+
433
+ -- publication.drop_comment
434
+ COMMENT ON PUBLICATION pub_custom IS NULL;
435
+
436
+ -- view.create
437
+ CREATE VIEW public.test_view WITH (security_barrier=true, check_option=local) AS SELECT *
438
+ FROM test_table;
439
+
440
+ -- view.drop
441
+ DROP VIEW public.test_view;
442
+
443
+ -- view.alter.change_owner
444
+ ALTER VIEW public.test_view OWNER TO new_owner;
445
+
446
+ -- view.alter.set_options
447
+ ALTER VIEW public.test_view SET (security_barrier=true, check_option=cascaded);
448
+
449
+ -- view.alter.reset_options
450
+ ALTER VIEW public.test_view RESET (security_barrier);
451
+
452
+ -- view.comment
453
+ COMMENT ON VIEW public.test_view IS 'view comment';
454
+
455
+ -- view.drop_comment
456
+ COMMENT ON VIEW public.test_view IS NULL;
457
+
458
+ -- view.grant
459
+ GRANT SELECT ON public.test_view TO app_reader WITH GRANT OPTION;
460
+
461
+ -- view.revoke
462
+ REVOKE SELECT ON public.test_view FROM app_reader;
463
+
464
+ -- view.revoke_grant_option
465
+ REVOKE GRANT OPTION FOR SELECT ON public.test_view FROM app_reader;
466
+
467
+ -- rule.create
468
+ CREATE RULE test_rule AS ON INSERT TO public.test_table DO INSTEAD NOTHING;
469
+
470
+ -- rule.drop
471
+ DROP RULE test_rule ON public.test_table;
472
+
473
+ -- rule.replace
474
+ CREATE OR REPLACE RULE test_rule AS ON INSERT TO public.test_table DO INSTEAD NOTHING;
475
+
476
+ -- rule.alter.set_enabled
477
+ ALTER TABLE public.test_table
478
+ DISABLE RULE test_rule;
479
+
480
+ -- rule.comment
481
+ COMMENT ON RULE test_rule ON public.test_table IS 'rule comment';
482
+
483
+ -- rule.drop_comment
484
+ COMMENT ON RULE test_rule ON public.test_table IS NULL;
485
+
486
+ -- procedure.create
487
+ CREATE PROCEDURE public.test_procedure()
488
+ LANGUAGE plpgsql
489
+ AS $$ begin null; end; $$;
490
+
491
+ -- procedure.drop
492
+ DROP PROCEDURE public.test_procedure();
493
+
494
+ -- function.create
495
+ CREATE FUNCTION public.calculate_metrics_for_analytics_dashboard_with_extended_name (
496
+ "p_schema_name_for_analytics" text,
497
+ "p_table_name_for_metrics" text,
498
+ "p_limit_count_default" integer DEFAULT 100
499
+ )
500
+ RETURNS TABLE (
501
+ total bigint,
502
+ average numeric
503
+ )
504
+ LANGUAGE plpgsql
505
+ STABLE
506
+ SECURITY DEFINER
507
+ PARALLEL SAFE
508
+ COST 100
509
+ ROWS 10
510
+ STRICT
511
+ SET search_path TO 'pg_catalog', 'public'
512
+ AS $function$ BEGIN RETURN QUERY SELECT count(*)::bigint, avg(value)::numeric FROM generate_series(1, p_limit_count_default); END; $function$;
513
+
514
+ -- function.drop
515
+ DROP FUNCTION
516
+ public.calculate_metrics_for_analytics_dashboard_with_extended_name(IN
517
+ "p_schema_name_for_analytics" text,
518
+ IN "p_table_name_for_metrics" text, IN "p_limit_count_default" integer);
519
+
520
+ -- function.alter.change_owner
521
+ ALTER FUNCTION public.calculate_metrics_for_analytics_dashboard_with_extended_name OWNER TO
522
+ new_admin;
523
+
524
+ -- function.alter.set_security
525
+ ALTER FUNCTION public.calculate_metrics_for_analytics_dashboard_with_extended_name SECURITY INVOKER;
526
+
527
+ -- function.alter.set_config
528
+ ALTER FUNCTION public.calculate_metrics_for_analytics_dashboard_with_extended_name
529
+ SET work_mem TO '256MB';
530
+
531
+ -- function.alter.set_volatility
532
+ ALTER FUNCTION public.calculate_metrics_for_analytics_dashboard_with_extended_name IMMUTABLE;
533
+
534
+ -- function.alter.set_strictness
535
+ ALTER FUNCTION public.calculate_metrics_for_analytics_dashboard_with_extended_name CALLED
536
+ ON NULL INPUT;
537
+
538
+ -- function.alter.set_leakproof
539
+ ALTER FUNCTION public.calculate_metrics_for_analytics_dashboard_with_extended_name LEAKPROOF;
540
+
541
+ -- function.alter.set_parallel
542
+ ALTER FUNCTION public.calculate_metrics_for_analytics_dashboard_with_extended_name PARALLEL
543
+ RESTRICTED;
544
+
545
+ -- function.comment
546
+ COMMENT ON FUNCTION
547
+ public.calculate_metrics_for_analytics_dashboard_with_extended_name(text,text,integer) IS
548
+ 'Calculate metrics for a given table';
549
+
550
+ -- function.drop_comment
551
+ COMMENT ON FUNCTION
552
+ public.calculate_metrics_for_analytics_dashboard_with_extended_name(text,text,integer) IS NULL;
553
+
554
+ -- function.grant
555
+ GRANT ALL ON FUNCTION
556
+ public.calculate_metrics_for_analytics_dashboard_with_extended_name(text, text, integer) TO
557
+ app_user WITH GRANT OPTION;
558
+
559
+ -- function.revoke
560
+ REVOKE ALL ON FUNCTION
561
+ public.calculate_metrics_for_analytics_dashboard_with_extended_name(text, text, integer) FROM
562
+ app_user;
563
+
564
+ -- function.revoke_grant_option
565
+ REVOKE GRANT OPTION FOR ALL ON FUNCTION
566
+ public.calculate_metrics_for_analytics_dashboard_with_extended_name(text, text, integer) FROM
567
+ app_user;
568
+
569
+ -- sequence.create
570
+ CREATE SEQUENCE public.table_with_very_long_name_for_formatting_and_wrapping_test_id_seq;
571
+
572
+ -- sequence.drop
573
+ DROP SEQUENCE public.table_with_very_long_name_for_formatting_and_wrapping_test_id_seq;
574
+
575
+ -- sequence.alter.set_owned_by
576
+ ALTER SEQUENCE public.table_with_very_long_name_for_formatting_and_wrapping_test_id_seq OWNED BY
577
+ public.table_with_very_long_name_for_formatting_and_wrapping_test.id;
578
+
579
+ -- sequence.alter.set_options
580
+ ALTER SEQUENCE public.table_with_very_long_name_for_formatting_and_wrapping_test_id_seq INCREMENT BY
581
+ 10 MINVALUE 1 MAXVALUE 1000000 CACHE 5 CYCLE;
582
+
583
+ -- sequence.comment
584
+ COMMENT ON SEQUENCE public.table_with_very_long_name_for_formatting_and_wrapping_test_id_seq IS
585
+ 'sequence for table_with_very_long_name_for_formatting_and_wrapping_test.id';
586
+
587
+ -- sequence.drop_comment
588
+ COMMENT ON SEQUENCE public.table_with_very_long_name_for_formatting_and_wrapping_test_id_seq IS NULL;
589
+
590
+ -- sequence.grant
591
+ GRANT SELECT,
592
+ USAGE
593
+ ON SEQUENCE public.table_with_very_long_name_for_formatting_and_wrapping_test_id_seq TO app_user;
594
+
595
+ -- sequence.revoke
596
+ REVOKE USAGE
597
+ ON SEQUENCE public.table_with_very_long_name_for_formatting_and_wrapping_test_id_seq FROM
598
+ app_user;
599
+
600
+ -- sequence.revoke_grant_option
601
+ REVOKE GRANT OPTION FOR USAGE
602
+ ON SEQUENCE public.table_with_very_long_name_for_formatting_and_wrapping_test_id_seq FROM
603
+ app_user;
604
+
605
+ -- policy.create
606
+ CREATE POLICY allow_select_own ON public.table_with_very_long_name_for_formatting_and_wrapping_test
607
+ FOR SELECT
608
+ TO authenticated
609
+ USING (auth.uid() = user_id);
610
+
611
+ -- policy.create_restrictive
612
+ CREATE POLICY restrict_delete ON public.table_with_very_long_name_for_formatting_and_wrapping_test
613
+ AS RESTRICTIVE
614
+ FOR DELETE
615
+ TO authenticated, service_role
616
+ USING (auth.uid() = owner_id)
617
+ WITH CHECK (status <> 'locked');
618
+
619
+ -- policy.drop
620
+ DROP POLICY allow_select_own ON public.table_with_very_long_name_for_formatting_and_wrapping_test;
621
+
622
+ -- policy.alter.set_roles
623
+ ALTER POLICY public.allow_select_own
624
+ ON public.table_with_very_long_name_for_formatting_and_wrapping_test TO authenticated, anon;
625
+
626
+ -- policy.alter.set_using
627
+ ALTER POLICY public.allow_select_own
628
+ ON public.table_with_very_long_name_for_formatting_and_wrapping_test
629
+ USING (auth.uid() = user_id AND status = 'active');
630
+
631
+ -- policy.alter.set_with_check
632
+ ALTER POLICY public.allow_select_own
633
+ ON public.table_with_very_long_name_for_formatting_and_wrapping_test WITH
634
+ CHECK (auth.uid() = user_id);
635
+
636
+ -- policy.comment
637
+ COMMENT ON POLICY allow_select_own
638
+ ON public.table_with_very_long_name_for_formatting_and_wrapping_test IS 'rls policy comment';
639
+
640
+ -- policy.drop_comment
641
+ COMMENT ON POLICY allow_select_own
642
+ ON public.table_with_very_long_name_for_formatting_and_wrapping_test IS NULL;
643
+
644
+ -- index.create
645
+ CREATE UNIQUE INDEX idx_t_fmt_status
646
+ ON public.table_with_very_long_name_for_formatting_and_wrapping_test (status)
647
+ WITH (fillfactor='90')
648
+ WHERE (status <> 'archived'::text);
649
+
650
+ -- index.create_gin
651
+ CREATE INDEX idx_t_fmt_search ON public.table_with_very_long_name_for_formatting_and_wrapping_test
652
+ USING gin (to_tsvector('english'::regconfig, status));
653
+
654
+ -- index.drop
655
+ DROP INDEX public.idx_t_fmt_status;
656
+
657
+ -- index.alter.set_storage_params
658
+ ALTER INDEX public.idx_t_fmt_status RESET (deduplicate_items);
659
+
660
+ ALTER INDEX public.idx_t_fmt_status SET (fillfactor=80);
661
+
662
+ -- index.alter.set_statistics
663
+ ALTER INDEX public.idx_t_fmt_status ALTER COLUMN 1 SET STATISTICS 500;
664
+
665
+ -- index.comment
666
+ COMMENT ON INDEX public.idx_t_fmt_status IS 'index comment';
667
+
668
+ -- index.drop_comment
669
+ COMMENT ON INDEX public.idx_t_fmt_status IS NULL;
670
+
671
+ -- trigger.create
672
+ CREATE TRIGGER trg_audit AFTER INSERT OR UPDATE
673
+ ON public.table_with_very_long_name_for_formatting_and_wrapping_test
674
+ REFERENCING OLD TABLE AS old_rows NEW TABLE AS new_rows FOR EACH ROW WHEN (
675
+ (NEW.status IS DISTINCT FROM OLD.status)
676
+ ) EXECUTE FUNCTION public.audit_trigger_fn('arg1', 'arg2');
677
+
678
+ -- trigger.drop
679
+ DROP TRIGGER trg_audit ON public.table_with_very_long_name_for_formatting_and_wrapping_test;
680
+
681
+ -- trigger.replace
682
+ CREATE OR REPLACE TRIGGER trg_audit AFTER INSERT OR UPDATE
683
+ ON public.table_with_very_long_name_for_formatting_and_wrapping_test
684
+ REFERENCING OLD TABLE AS old_rows NEW TABLE AS new_rows FOR EACH ROW WHEN (
685
+ (NEW.status IS DISTINCT FROM OLD.status)
686
+ ) EXECUTE FUNCTION public.audit_trigger_fn('arg1', 'arg2');
687
+
688
+ -- trigger.comment
689
+ COMMENT ON TRIGGER trg_audit
690
+ ON public.table_with_very_long_name_for_formatting_and_wrapping_test IS 'trigger comment';
691
+
692
+ -- trigger.drop_comment
693
+ COMMENT ON TRIGGER trg_audit
694
+ ON public.table_with_very_long_name_for_formatting_and_wrapping_test IS NULL;
695
+
696
+ -- matview.create
697
+ CREATE MATERIALIZED VIEW analytics.daily_stats
698
+ WITH (fillfactor=70)
699
+ AS SELECT date_trunc('day', created_at) AS day, count(*) AS total
700
+ FROM public.events
701
+ GROUP BY 1 WITH DATA;
702
+
703
+ -- matview.drop
704
+ DROP MATERIALIZED VIEW analytics.daily_stats;
705
+
706
+ -- matview.alter.change_owner
707
+ ALTER MATERIALIZED VIEW analytics.daily_stats
708
+ OWNER TO new_owner;
709
+
710
+ -- matview.alter.set_storage
711
+ ALTER MATERIALIZED VIEW analytics.daily_stats
712
+ RESET (autovacuum_enabled);
713
+
714
+ ALTER MATERIALIZED VIEW analytics.daily_stats
715
+ SET (fillfactor=80);
716
+
717
+ -- matview.comment
718
+ COMMENT ON MATERIALIZED VIEW analytics.daily_stats IS 'daily aggregation';
719
+
720
+ -- matview.drop_comment
721
+ COMMENT ON MATERIALIZED VIEW analytics.daily_stats IS NULL;
722
+
723
+ -- matview.column_comment
724
+ COMMENT ON COLUMN analytics.daily_stats.day IS 'day bucket';
725
+
726
+ -- matview.drop_column_comment
727
+ COMMENT ON COLUMN analytics.daily_stats.day IS NULL;
728
+
729
+ -- matview.grant
730
+ GRANT SELECT ON analytics.daily_stats TO app_reader;
731
+
732
+ -- matview.revoke
733
+ REVOKE SELECT ON analytics.daily_stats FROM app_reader;
734
+
735
+ -- matview.revoke_grant_option
736
+ REVOKE GRANT OPTION FOR SELECT ON analytics.daily_stats FROM app_reader;
737
+
738
+ -- aggregate.create
739
+ CREATE AGGREGATE public.array_cat_agg(anycompatiblearray) (
740
+ SFUNC = array_cat,
741
+ STYPE = anycompatiblearray,
742
+ COMBINEFUNC = array_cat,
743
+ INITCOND = '{}',
744
+ PARALLEL SAFE,
745
+ STRICT
746
+ );
747
+
748
+ -- aggregate.drop
749
+ DROP AGGREGATE public.array_cat_agg(anycompatiblearray);
750
+
751
+ -- aggregate.alter.change_owner
752
+ ALTER AGGREGATE public.array_cat_agg(anycompatiblearray) OWNER TO new_owner;
753
+
754
+ -- aggregate.comment
755
+ COMMENT ON AGGREGATE public.array_cat_agg(anycompatiblearray) IS 'concatenate arrays aggregate';
756
+
757
+ -- aggregate.drop_comment
758
+ COMMENT ON AGGREGATE public.array_cat_agg(anycompatiblearray) IS NULL;
759
+
760
+ -- aggregate.grant
761
+ GRANT ALL ON FUNCTION public.array_cat_agg(anycompatiblearray) TO app_user;
762
+
763
+ -- aggregate.revoke
764
+ REVOKE ALL ON FUNCTION public.array_cat_agg(anycompatiblearray) FROM app_user;
765
+
766
+ -- aggregate.revoke_grant_option
767
+ REVOKE GRANT OPTION FOR ALL ON FUNCTION public.array_cat_agg(anycompatiblearray) FROM app_user;
768
+
769
+ -- event_trigger.create
770
+ CREATE EVENT TRIGGER prevent_drop
771
+ ON sql_drop
772
+ WHEN TAG IN ('DROP TABLE', 'DROP SCHEMA')
773
+ EXECUTE FUNCTION public.prevent_drop_fn();
774
+
775
+ -- event_trigger.drop
776
+ DROP EVENT TRIGGER prevent_drop;
777
+
778
+ -- event_trigger.alter.change_owner
779
+ ALTER EVENT TRIGGER prevent_drop
780
+ OWNER TO new_owner;
781
+
782
+ -- event_trigger.alter.set_enabled
783
+ ALTER EVENT TRIGGER prevent_drop
784
+ DISABLE;
785
+
786
+ -- event_trigger.comment
787
+ COMMENT ON EVENT TRIGGER prevent_drop IS 'prevent accidental drops';
788
+
789
+ -- event_trigger.drop_comment
790
+ COMMENT ON EVENT TRIGGER prevent_drop IS NULL;
791
+
792
+ -- language.create
793
+ CREATE TRUSTED LANGUAGE plv8
794
+ HANDLER plv8_call_handler
795
+ INLINE plv8_inline_handler
796
+ VALIDATOR plv8_call_validator;
797
+
798
+ -- language.drop
799
+ DROP LANGUAGE plv8;
800
+
801
+ -- language.alter.change_owner
802
+ ALTER LANGUAGE plv8 OWNER TO new_owner;
803
+
804
+ -- language.comment
805
+ COMMENT ON LANGUAGE plv8 IS 'PL/V8 trusted procedural language';
806
+
807
+ -- language.drop_comment
808
+ COMMENT ON LANGUAGE plv8 IS NULL;
809
+
810
+ -- language.grant
811
+ GRANT ALL ON LANGUAGE plv8 TO app_user WITH GRANT OPTION;
812
+
813
+ -- language.revoke
814
+ REVOKE ALL ON LANGUAGE plv8 FROM app_user;
815
+
816
+ -- language.revoke_grant_option
817
+ REVOKE GRANT OPTION FOR ALL ON LANGUAGE plv8 FROM app_user;
818
+
819
+ -- role.create
820
+ CREATE ROLE app_user WITH LOGIN CONNECTION LIMIT 100;
821
+
822
+ -- role.drop
823
+ DROP ROLE app_user;
824
+
825
+ -- role.alter.set_options
826
+ ALTER ROLE app_user WITH NOSUPERUSER CREATEDB;
827
+
828
+ -- role.alter.set_config
829
+ ALTER ROLE app_user SET statement_timeout TO '60000';
830
+
831
+ -- role.comment
832
+ COMMENT ON ROLE app_user IS 'application user role';
833
+
834
+ -- role.drop_comment
835
+ COMMENT ON ROLE app_user IS NULL;
836
+
837
+ -- role.grant_membership
838
+ GRANT app_user TO dev_user WITH ADMIN OPTION;
839
+
840
+ -- role.revoke_membership
841
+ REVOKE app_user FROM dev_user;
842
+
843
+ -- role.revoke_membership_options
844
+ REVOKE ADMIN OPTION FOR app_user FROM dev_user;
845
+
846
+ -- role.grant_default_privileges
847
+ ALTER DEFAULT PRIVILEGES FOR ROLE app_user IN SCHEMA public GRANT SELECT ON TABLES TO app_reader;
848
+
849
+ -- role.revoke_default_privileges
850
+ ALTER DEFAULT PRIVILEGES FOR ROLE app_user IN SCHEMA public REVOKE SELECT ON TABLES FROM app_reader;
851
+
852
+ -- subscription.create
853
+ CREATE SUBSCRIPTION sub_replica
854
+ CONNECTION 'host=primary.db port=5432 dbname=mydb'
855
+ PUBLICATION pub_custom
856
+ WITH (
857
+ slot_name = 'sub_replica_slot',
858
+ binary = true,
859
+ streaming = 'parallel',
860
+ synchronous_commit = 'remote_apply',
861
+ disable_on_error = true,
862
+ failover = true
863
+ );
864
+
865
+ -- subscription.drop
866
+ DROP SUBSCRIPTION sub_replica;
867
+
868
+ -- subscription.alter.set_connection
869
+ ALTER SUBSCRIPTION sub_replica
870
+ CONNECTION 'host=primary.db port=5432 dbname=mydb';
871
+
872
+ -- subscription.alter.set_publication
873
+ ALTER SUBSCRIPTION sub_replica
874
+ SET PUBLICATION pub_custom;
875
+
876
+ -- subscription.alter.enable
877
+ ALTER SUBSCRIPTION sub_replica
878
+ ENABLE;
879
+
880
+ -- subscription.alter.disable
881
+ ALTER SUBSCRIPTION sub_replica
882
+ DISABLE;
883
+
884
+ -- subscription.alter.set_options
885
+ ALTER SUBSCRIPTION sub_replica
886
+ SET (
887
+ binary = true,
888
+ streaming = 'parallel',
889
+ synchronous_commit = 'remote_apply'
890
+ );
891
+
892
+ -- subscription.alter.set_owner
893
+ ALTER SUBSCRIPTION sub_replica
894
+ OWNER TO new_owner;
895
+
896
+ -- subscription.comment
897
+ COMMENT ON SUBSCRIPTION sub_replica IS 'replication subscription';
898
+
899
+ -- subscription.drop_comment
900
+ COMMENT ON SUBSCRIPTION sub_replica IS NULL;
901
+
902
+ -- fdw.create
903
+ CREATE FOREIGN DATA WRAPPER postgres_fdw
904
+ HANDLER postgres_fdw_handler
905
+ VALIDATOR postgres_fdw_validator
906
+ OPTIONS (debug 'true');
907
+
908
+ -- fdw.drop
909
+ DROP FOREIGN DATA WRAPPER postgres_fdw;
910
+
911
+ -- fdw.alter.change_owner
912
+ ALTER FOREIGN DATA WRAPPER postgres_fdw
913
+ OWNER TO new_owner;
914
+
915
+ -- fdw.alter.set_options
916
+ ALTER FOREIGN DATA WRAPPER postgres_fdw
917
+ OPTIONS (
918
+ SET debug 'false',
919
+ ADD use_remote_estimate ''
920
+ );
921
+
922
+ -- fdw.comment
923
+ COMMENT ON FOREIGN DATA WRAPPER postgres_fdw IS 'PostgreSQL foreign data wrapper';
924
+
925
+ -- fdw.drop_comment
926
+ COMMENT ON FOREIGN DATA WRAPPER postgres_fdw IS NULL;
927
+
928
+ -- fdw.grant
929
+ GRANT ALL ON FOREIGN DATA WRAPPER postgres_fdw TO app_user;
930
+
931
+ -- fdw.revoke
932
+ REVOKE ALL ON FOREIGN DATA WRAPPER postgres_fdw FROM app_user;
933
+
934
+ -- fdw.revoke_grant_option
935
+ REVOKE GRANT OPTION FOR ALL ON FOREIGN DATA WRAPPER postgres_fdw FROM app_user;
936
+
937
+ -- foreign_table.create
938
+ CREATE FOREIGN TABLE public.remote_users (
939
+ id integer,
940
+ email text
941
+ ) SERVER remote_server OPTIONS (schema_name 'public', table_name 'users');
942
+
943
+ -- foreign_table.drop
944
+ DROP FOREIGN TABLE public.remote_users;
945
+
946
+ -- foreign_table.alter.change_owner
947
+ ALTER FOREIGN TABLE public.remote_users
948
+ OWNER TO new_owner;
949
+
950
+ -- foreign_table.alter.add_column
951
+ ALTER FOREIGN TABLE public.remote_users
952
+ ADD COLUMN name text NOT NULL DEFAULT 'unknown';
953
+
954
+ -- foreign_table.alter.drop_column
955
+ ALTER FOREIGN TABLE public.remote_users
956
+ DROP COLUMN email;
957
+
958
+ -- foreign_table.alter.column_type
959
+ ALTER FOREIGN TABLE public.remote_users
960
+ ALTER COLUMN id TYPE bigint;
961
+
962
+ -- foreign_table.alter.column_set_default
963
+ ALTER FOREIGN TABLE public.remote_users
964
+ ALTER COLUMN email SET DEFAULT 'nobody@example.com';
965
+
966
+ -- foreign_table.alter.column_drop_default
967
+ ALTER FOREIGN TABLE public.remote_users
968
+ ALTER COLUMN email DROP DEFAULT;
969
+
970
+ -- foreign_table.alter.column_set_not_null
971
+ ALTER FOREIGN TABLE public.remote_users
972
+ ALTER COLUMN email SET NOT NULL;
973
+
974
+ -- foreign_table.alter.column_drop_not_null
975
+ ALTER FOREIGN TABLE public.remote_users
976
+ ALTER COLUMN email DROP NOT NULL;
977
+
978
+ -- foreign_table.alter.set_options
979
+ ALTER FOREIGN TABLE public.remote_users
980
+ OPTIONS (SET fetch_size '1000');
981
+
982
+ -- foreign_table.comment
983
+ COMMENT ON FOREIGN TABLE public.remote_users IS 'remote users table';
984
+
985
+ -- foreign_table.drop_comment
986
+ COMMENT ON FOREIGN TABLE public.remote_users IS NULL;
987
+
988
+ -- foreign_table.grant
989
+ GRANT SELECT ON FOREIGN TABLE public.remote_users TO app_reader;
990
+
991
+ -- foreign_table.revoke
992
+ REVOKE SELECT ON FOREIGN TABLE public.remote_users FROM app_reader;
993
+
994
+ -- foreign_table.revoke_grant_option
995
+ REVOKE GRANT OPTION FOR SELECT ON FOREIGN TABLE public.remote_users FROM app_reader;
996
+
997
+ -- server.create
998
+ CREATE SERVER remote_server
999
+ TYPE 'postgresql'
1000
+ VERSION '16.0'
1001
+ FOREIGN DATA WRAPPER postgres_fdw
1002
+ OPTIONS (
1003
+ host 'remote.host',
1004
+ port '5432',
1005
+ dbname 'remote_db'
1006
+ );
1007
+
1008
+ -- server.drop
1009
+ DROP SERVER remote_server;
1010
+
1011
+ -- server.alter.change_owner
1012
+ ALTER SERVER remote_server
1013
+ OWNER TO new_owner;
1014
+
1015
+ -- server.alter.set_version
1016
+ ALTER SERVER remote_server
1017
+ VERSION '17.0';
1018
+
1019
+ -- server.alter.set_options
1020
+ ALTER SERVER remote_server
1021
+ OPTIONS (
1022
+ SET host 'new.host',
1023
+ DROP port
1024
+ );
1025
+
1026
+ -- server.comment
1027
+ COMMENT ON SERVER remote_server IS 'remote PostgreSQL server';
1028
+
1029
+ -- server.drop_comment
1030
+ COMMENT ON SERVER remote_server IS NULL;
1031
+
1032
+ -- server.grant
1033
+ GRANT ALL ON SERVER remote_server TO app_user;
1034
+
1035
+ -- server.revoke
1036
+ REVOKE ALL ON SERVER remote_server FROM app_user;
1037
+
1038
+ -- server.revoke_grant_option
1039
+ REVOKE GRANT OPTION FOR ALL ON SERVER remote_server FROM app_user;
1040
+
1041
+ -- user_mapping.create
1042
+ CREATE USER MAPPING FOR app_user SERVER remote_server
1043
+ OPTIONS (user 'remote_app', password 'secret123');
1044
+
1045
+ -- user_mapping.drop
1046
+ DROP USER MAPPING FOR app_user SERVER remote_server;
1047
+
1048
+ -- user_mapping.alter.set_options
1049
+ ALTER USER MAPPING FOR app_user SERVER remote_server OPTIONS (SET password 'new_secret');"
1050
+ `);
1051
+ });
1052
+ });