okmodel 0.8.0 → 0.9.1

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 (237) hide show
  1. package/README.md +23 -1
  2. package/dist/adapters/pg/bunsql-extra.d.ts +5 -5
  3. package/dist/adapters/pg/bunsql.d.ts +6 -2
  4. package/dist/adapters/pg/nodepostgres.d.ts +16 -1
  5. package/dist/adapters/pg/postgres-extra.d.ts +3 -17
  6. package/dist/adapters/pg/postgresjs.d.ts +2 -1
  7. package/dist/contracts/driver.d.ts +3 -2
  8. package/dist/contracts/error.d.ts +1 -1
  9. package/dist/dialects/pg/errors.d.ts +2 -0
  10. package/dist/dialects/pg/ext/btree-gin.d.ts +26 -0
  11. package/dist/dialects/pg/ext/btree-gin.js +20 -0
  12. package/dist/dialects/pg/ext/btree-gist.d.ts +26 -0
  13. package/dist/dialects/pg/ext/btree-gist.js +20 -0
  14. package/dist/dialects/pg/ext/call.d.ts +53 -0
  15. package/dist/dialects/pg/ext/citext.js +1 -1
  16. package/dist/dialects/pg/ext/feature.d.ts +26 -0
  17. package/dist/dialects/pg/ext/fuzzystrmatch.d.ts +34 -0
  18. package/dist/dialects/pg/ext/fuzzystrmatch.js +33 -0
  19. package/dist/dialects/pg/ext/hstore.d.ts +41 -0
  20. package/dist/dialects/pg/ext/hstore.js +29 -0
  21. package/dist/dialects/pg/ext/index.d.ts +56 -0
  22. package/dist/dialects/pg/ext/index.js +1 -1
  23. package/dist/dialects/pg/ext/ltree.d.ts +41 -0
  24. package/dist/dialects/pg/ext/ltree.js +29 -0
  25. package/dist/dialects/pg/ext/pg-trgm.js +4 -13
  26. package/dist/dialects/pg/ext/pgcrypto.d.ts +33 -0
  27. package/dist/dialects/pg/ext/pgcrypto.js +33 -0
  28. package/dist/dialects/pg/ext/unaccent.d.ts +26 -0
  29. package/dist/dialects/pg/ext/unaccent.js +21 -0
  30. package/dist/dialects/pg/ext/using.d.ts +23 -0
  31. package/dist/dialects/pg/ext/versions.d.ts +36 -0
  32. package/dist/dialects/pg/external.d.ts +19 -0
  33. package/dist/dialects/pg/filters.d.ts +2 -2
  34. package/dist/dialects/pg/fn/index.js +5 -5
  35. package/dist/dialects/pg/index.d.ts +1 -0
  36. package/dist/dialects/pg/index.js +19 -14
  37. package/dist/dialects/pg/introspect.d.ts +12 -0
  38. package/dist/dialects/pg/view/index.js +7 -7
  39. package/dist/dialects/pg/view/scratch.d.ts +4 -1
  40. package/dist/runtime/artifact-file.d.ts +22 -0
  41. package/dist/runtime/client.d.ts +10 -0
  42. package/dist/runtime/drift-detail.d.ts +2 -1
  43. package/dist/runtime/drift.d.ts +3 -10
  44. package/dist/runtime/param-limit.d.ts +20 -0
  45. package/dist/runtime/pg/bun.js +4 -4
  46. package/dist/runtime/pg/neon.js +4 -4
  47. package/dist/runtime/pg/pg.js +4 -4
  48. package/dist/runtime/pg/pglite.js +4 -4
  49. package/dist/runtime/pg/postgresjs.js +11 -11
  50. package/dist/runtime/server-check.d.ts +36 -6
  51. package/dist/runtime/tenancy/index.js +1 -1
  52. package/dist/runtime/traits/index.js +6 -6
  53. package/dist/runtime/validate/index.js +2 -2
  54. package/dist/runtime/write.d.ts +1 -1
  55. package/dist/shared/{4m6hskg8.js → 0j6qe91y.js} +4 -4
  56. package/dist/shared/{6m78c8ss.js → 1h5h1rf5.js} +1 -1
  57. package/dist/shared/{4vbf83xx.js → 2vcnpf0n.js} +1 -1
  58. package/dist/shared/{qd9hhd8f.js → 3ap5hxvj.js} +2 -1
  59. package/dist/shared/{v1wad97q.js → 3d7a80fq.js} +1 -1
  60. package/dist/shared/{wcrheftc.js → 3dr444ny.js} +58 -79
  61. package/dist/shared/{hm5f8jby.js → 3vvpcphd.js} +8 -7
  62. package/dist/shared/{760ppr76.js → 4a3mmhhe.js} +2 -2
  63. package/dist/shared/{mkrn359n.js → 4pkz5nvw.js} +222 -39
  64. package/dist/shared/{agsfb86s.js → 4te76xc5.js} +4 -4
  65. package/dist/shared/{63f4ksbz.js → 60y4ahmw.js} +1 -1
  66. package/dist/shared/61bmrmhr.js +35 -0
  67. package/dist/shared/{bxas03mq.js → 63qjmhnp.js} +100 -17
  68. package/dist/shared/{g5yc06ka.js → 67w3kn71.js} +1 -1
  69. package/dist/shared/{jgqj11w4.js → 6f0z3hzh.js} +4 -0
  70. package/dist/shared/{njga14v4.js → 6vfvsdkt.js} +10 -8
  71. package/dist/shared/{kj9d8maq.js → 6xqvesa5.js} +1 -1
  72. package/dist/shared/8gdbty5v.js +665 -0
  73. package/dist/shared/{pan0370z.js → 8ma6drzr.js} +211 -30
  74. package/dist/shared/{mnvjvqyp.js → 8p2bgye0.js} +124 -32
  75. package/dist/shared/{mfedzr74.js → 8qwqrxed.js} +14 -6
  76. package/dist/shared/{hfqmpasr.js → 8v7vzpgt.js} +11 -8
  77. package/dist/shared/{7ghwamrf.js → 99qp9vtg.js} +1 -1
  78. package/dist/shared/{zgex00fd.js → ak61ye1f.js} +5 -5
  79. package/dist/shared/{dpc2r7rb.js → bdekbvmt.js} +218 -95
  80. package/dist/shared/{jebgrkeq.js → bxjq6xqv.js} +2 -2
  81. package/dist/shared/c7dqd3gk.js +1806 -0
  82. package/dist/shared/ddh72ym5.js +20 -0
  83. package/dist/shared/e1c55v04.js +10 -0
  84. package/dist/shared/{mtw6jz76.js → e275q7sd.js} +1 -1
  85. package/dist/shared/{k86n8vq3.js → ekhq3ytz.js} +1 -1
  86. package/dist/shared/esy4dyxe.js +17 -0
  87. package/dist/shared/{gcefca6p.js → f9t9g54z.js} +22 -9
  88. package/dist/shared/{sjk86yrx.js → fk9vef30.js} +84 -73
  89. package/dist/shared/fkjne6gx.js +8 -0
  90. package/dist/shared/{e8zyaqvj.js → fne90dvz.js} +4 -1
  91. package/dist/shared/{needfe47.js → g89fmz5s.js} +1 -1
  92. package/dist/shared/{m4xff2a6.js → ghqzdp94.js} +2 -2
  93. package/dist/shared/{n0jmpgj1.js → gr9sn4za.js} +1 -1
  94. package/dist/shared/{5mtf6cj3.js → gzgfsspx.js} +5 -2
  95. package/dist/shared/h9811jjm.js +17 -0
  96. package/dist/shared/{z581d7ny.js → hgt69zjf.js} +2 -2
  97. package/dist/shared/{35q0n9tz.js → jvxcp1qk.js} +71 -87
  98. package/dist/shared/k73e8n9d.js +136 -0
  99. package/dist/shared/{195pzzzz.js → kzgrcy8s.js} +12 -8
  100. package/dist/shared/kzgrnckd.js +29 -0
  101. package/dist/shared/{p3xbdcvt.js → mz48rs74.js} +68 -8
  102. package/dist/shared/{zbqbmmrp.js → n6je5b28.js} +13 -26
  103. package/dist/shared/{b6d6p0zc.js → ns35jqz0.js} +75 -49
  104. package/dist/shared/{n05z9nwz.js → nstwgzn8.js} +1 -1
  105. package/dist/{tooling/shared/08kemxjd.js → shared/pgsak1yw.js} +1 -1
  106. package/dist/shared/py2zrrm6.js +451 -0
  107. package/dist/shared/{9dr2qnx7.js → qqm3ze6q.js} +1 -1
  108. package/dist/shared/{wvdjznah.js → rcjm0yn7.js} +31 -38
  109. package/dist/shared/rged92v6.js +17 -0
  110. package/dist/shared/{jp36k7dp.js → rw4tpcd0.js} +81 -51
  111. package/dist/shared/{bsek72fg.js → s5qe47a6.js} +3 -0
  112. package/dist/shared/{1d9q9cv2.js → smxzjz60.js} +2 -2
  113. package/dist/shared/{wz2a78mp.js → th5rnaxw.js} +1 -1
  114. package/dist/{tooling/shared/rs1jb051.js → shared/tr64w5p0.js} +1 -1
  115. package/dist/shared/{14x60fbf.js → tyqapcgk.js} +73 -10
  116. package/dist/shared/vsna85qf.js +8 -0
  117. package/dist/shared/{63qtkrca.js → vy47ryqa.js} +55 -5
  118. package/dist/shared/{jx2m62cs.js → wbdh9qbg.js} +7 -5
  119. package/dist/shared/{f4jy1j7x.js → wp7y8q3y.js} +946 -105
  120. package/dist/shared/{16kvjebh.js → xbd9xs6p.js} +7 -26
  121. package/dist/shared/{bah9nbg3.js → xbvz446k.js} +18 -23
  122. package/dist/shared/{p5nh3r8q.js → y6tfjk9q.js} +2 -2
  123. package/dist/shared/{3bb7wsqt.js → ycnft340.js} +1 -1
  124. package/dist/shared/{z7s6fpxv.js → ymenf259.js} +1 -1
  125. package/dist/shared/{0wrea3jq.js → ysdw2fg3.js} +10 -2
  126. package/dist/shared/zecrwdk9.js +61 -0
  127. package/dist/shared/{3t6kw83m.js → zm2rzqba.js} +2 -1
  128. package/dist/tooling/cli.js +200 -50
  129. package/dist/tooling/driver-run.js +109 -343
  130. package/dist/tooling/github/comment.d.ts +56 -0
  131. package/dist/tooling/github/post-comment.d.ts +17 -0
  132. package/dist/tooling/migrate/apply.d.ts +17 -2
  133. package/dist/tooling/migrate/commands.d.ts +2 -1
  134. package/dist/tooling/migrate/config.d.ts +13 -0
  135. package/dist/tooling/migrate/drift.d.ts +12 -0
  136. package/dist/tooling/migrate/driver-url.d.ts +17 -0
  137. package/dist/tooling/migrate/export.d.ts +165 -0
  138. package/dist/tooling/migrate/ext-surface.d.ts +80 -0
  139. package/dist/tooling/migrate/ext.d.ts +31 -4
  140. package/dist/tooling/migrate/import-drizzle.d.ts +40 -0
  141. package/dist/tooling/migrate/index.d.ts +3 -0
  142. package/dist/tooling/migrate/index.js +57 -10
  143. package/dist/tooling/migrate/lint-rules.d.ts +18 -1
  144. package/dist/tooling/migrate/lint.d.ts +14 -1
  145. package/dist/tooling/migrate/place.d.ts +18 -0
  146. package/dist/tooling/migrate/plan-json.d.ts +65 -0
  147. package/dist/tooling/migrate/policy.d.ts +17 -5
  148. package/dist/tooling/migrate/pooler-probe.d.ts +23 -0
  149. package/dist/tooling/migrate/project.d.ts +10 -1
  150. package/dist/tooling/migrate/pull-emit.d.ts +98 -0
  151. package/dist/tooling/migrate/pull-routines.d.ts +126 -0
  152. package/dist/tooling/migrate/pull-verify.d.ts +26 -0
  153. package/dist/tooling/migrate/pull.d.ts +65 -0
  154. package/dist/tooling/migrate/reprint.d.ts +32 -0
  155. package/dist/tooling/migrate/runner.d.ts +24 -1
  156. package/dist/tooling/migrate/sandbox.d.ts +8 -2
  157. package/dist/tooling/migrate/schema-api.d.ts +43 -0
  158. package/dist/tooling/migrate/sql-lex.d.ts +18 -0
  159. package/dist/tooling/shared/{ppnnnvj8.js → 09a6vsys.js} +1 -1
  160. package/dist/tooling/shared/{7ae7rjmn.js → 0v9ptnxp.js} +8 -8
  161. package/dist/tooling/shared/{fb9k2qwd.js → 0wtzps9p.js} +11 -30
  162. package/dist/tooling/shared/{a6pp9d12.js → 0yhf1db4.js} +6 -6
  163. package/dist/tooling/shared/{dy672fz6.js → 19msgrsc.js} +2 -2
  164. package/dist/{shared/q0cqt2sp.js → tooling/shared/1fwfm5m3.js} +1 -1
  165. package/dist/tooling/shared/{f9mphxej.js → 2jdn09e2.js} +401 -24
  166. package/dist/tooling/shared/{jne7b93p.js → 2qrte2ct.js} +5 -5
  167. package/dist/tooling/shared/{5bvw2nev.js → 2v4nwnkb.js} +1 -1
  168. package/dist/tooling/shared/{spk1jg3r.js → 33z39trp.js} +106 -23
  169. package/dist/tooling/shared/{z8d7ptht.js → 353vnw9z.js} +5 -5
  170. package/dist/tooling/shared/{dw08f3m8.js → 390kry9g.js} +2 -2
  171. package/dist/tooling/shared/{xjs6zqtc.js → 3f6etb9z.js} +18 -31
  172. package/dist/{shared/bnby0esn.js → tooling/shared/3t2cqmsx.js} +1 -1
  173. package/dist/tooling/shared/{wwnekq5n.js → 4dzvjtpy.js} +1 -1
  174. package/dist/tooling/shared/{y5656f0e.js → 4ec0nxvw.js} +10 -10
  175. package/dist/tooling/shared/{3m1hkg7z.js → 4tg2bn41.js} +59 -78
  176. package/dist/tooling/shared/{zvnhh1n0.js → 5rah55z0.js} +2 -2
  177. package/dist/tooling/shared/{pqy21k24.js → 804w1t69.js} +4 -4
  178. package/dist/tooling/shared/8g0m0rvd.js +134 -0
  179. package/dist/tooling/shared/8msbtw5s.js +8 -0
  180. package/dist/tooling/shared/{4d2w25vw.js → 8t22h3h7.js} +2 -2
  181. package/dist/tooling/shared/{smn6kz1p.js → 91c59b7b.js} +2 -2
  182. package/dist/tooling/shared/{aftb2mwr.js → adk9k6va.js} +1 -1
  183. package/dist/tooling/shared/{j9t5s12a.js → ajjd5cwz.js} +2 -2
  184. package/dist/tooling/shared/{cmptmb4f.js → angjck01.js} +1 -1
  185. package/dist/tooling/shared/{yw30vnq2.js → asnnc3v5.js} +1 -1
  186. package/dist/tooling/shared/{ma2340rx.js → bj1kyqc8.js} +2 -2
  187. package/dist/tooling/shared/{2wtvc7rw.js → bt3tjemb.js} +11 -3
  188. package/dist/tooling/shared/{ec71zqgt.js → chk2bh4f.js} +2 -2
  189. package/dist/tooling/shared/{gmcf9cxf.js → ckq4z5ax.js} +5 -2
  190. package/dist/tooling/shared/{w7qe8sj1.js → d3rhb24q.js} +1 -1
  191. package/dist/tooling/shared/{y031jct9.js → d8q00vxg.js} +4 -4
  192. package/dist/tooling/shared/{vs0t6qt8.js → dx188rxs.js} +2 -2
  193. package/dist/tooling/shared/{g9ad4n80.js → efq6p9df.js} +35 -42
  194. package/dist/tooling/shared/{ddjtfgnx.js → en6rwzq0.js} +3 -3
  195. package/dist/tooling/shared/{6nyfyw70.js → f2r5g0fs.js} +2 -2
  196. package/dist/tooling/shared/{03k6res6.js → f4gep0nk.js} +1 -1
  197. package/dist/tooling/shared/{gfvtj6d0.js → f8a010fm.js} +13 -11
  198. package/dist/tooling/shared/{3tq8pnb8.js → fdsek6pa.js} +1 -1
  199. package/dist/tooling/shared/fvmrxsd1.js +8 -0
  200. package/dist/tooling/shared/{733a1tq3.js → g3xybeqf.js} +4 -3
  201. package/dist/tooling/shared/{pwsytxm5.js → gefmpwsa.js} +1 -1
  202. package/dist/tooling/shared/{mtrqn2hn.js → gjj71hfh.js} +25 -30
  203. package/dist/tooling/shared/{8sqrsw3s.js → jgzt69pa.js} +5 -5
  204. package/dist/tooling/shared/{nf7jmhfa.js → jm30k2ca.js} +10 -8
  205. package/dist/tooling/shared/{vx86qjv8.js → kayqzpbk.js} +6 -3
  206. package/dist/tooling/shared/{zhwnfyb2.js → kvw1672d.js} +1 -1
  207. package/dist/tooling/shared/{rq5kk8j6.js → mr1kcgpw.js} +3 -3
  208. package/dist/tooling/shared/{72fyg4zv.js → mwbdf409.js} +1 -1
  209. package/dist/tooling/shared/{wt7j7nf6.js → ns9207v3.js} +1 -1
  210. package/dist/tooling/shared/{9xzm7hjg.js → p6tjv97k.js} +3 -3
  211. package/dist/tooling/shared/{yfr8hzhm.js → p73evwf0.js} +1 -1
  212. package/dist/tooling/shared/{dzx85q70.js → phc1nc4g.js} +1 -1
  213. package/dist/tooling/shared/{417zdsk7.js → ppybjw50.js} +79 -16
  214. package/dist/tooling/shared/{yk9mp7vb.js → qdrn8ghn.js} +5 -4
  215. package/dist/tooling/shared/rd8h01ta.js +20 -0
  216. package/dist/tooling/shared/{bz2dqhab.js → rwg8y90m.js} +3 -3
  217. package/dist/tooling/shared/{xhrnjch9.js → ry2f3w8p.js} +3 -3
  218. package/dist/tooling/shared/{a7q7t4n3.js → ryc5sa58.js} +8 -8
  219. package/dist/tooling/shared/{2revefqt.js → ss87qxwv.js} +2 -2
  220. package/dist/tooling/shared/{rf83gr2d.js → vg68k11z.js} +7 -3
  221. package/dist/tooling/shared/{p7f08ktn.js → vms9dta5.js} +73 -89
  222. package/dist/tooling/shared/{3rrw5w8f.js → xchpnbdv.js} +1 -1
  223. package/dist/tooling/shared/{djydjpqt.js → xn6p01fh.js} +5 -5
  224. package/dist/tooling/shared/{9kazs5p6.js → xwr6q618.js} +3 -3
  225. package/dist/tooling/shared/{ep8zh3bk.js → xx3gmq94.js} +1 -1
  226. package/dist/tooling/shared/{tn8gay14.js → y2bd7yfx.js} +21 -13
  227. package/dist/tooling/shared/{vraj6d74.js → y4gq9rbe.js} +11 -11
  228. package/dist/tooling/shared/y4vwft92.js +9 -0
  229. package/dist/tooling/shared/{345tbc2k.js → yz68xcmc.js} +1 -1
  230. package/dist/tooling/testing/factories.d.ts +1 -3
  231. package/dist/tooling/testing/index.js +2 -2
  232. package/package.json +39 -9
  233. package/dist/shared/3449rcae.js +0 -14
  234. package/dist/shared/fjpnhqan.js +0 -71
  235. package/dist/shared/n41w4fbz.js +0 -113
  236. package/dist/tooling/shared/pw8fgahx.js +0 -69
  237. /package/dist/shared/{ae4j5f42.js → mfvx6kjx.js} +0 -0
@@ -3,27 +3,32 @@ import {
3
3
  viewObject,
4
4
  materializedViewObject
5
5
  } from "./12z7aznj.js";
6
+ import {
7
+ quoteIdent2,
8
+ createObjectSql2
9
+ } from "./fk9vef30.js";
10
+ import {
11
+ probeStableBackend
12
+ } from "./e1c55v04.js";
6
13
  import {
7
14
  cellText,
8
15
  VIEW_DEPENDENCIES,
9
16
  viewDependencyEdges,
10
17
  PUBLIC,
11
18
  introspectSchema,
12
- atomicBody
13
- } from "./p3xbdcvt.js";
19
+ atomicBody,
20
+ reprintDomainCheck
21
+ } from "./mz48rs74.js";
14
22
  import {
23
+ driverUrl,
15
24
  planMigration,
16
25
  sessionFailure,
17
26
  finishQuiet,
18
- assertDirectConnection,
19
- assertStableBackend
20
- } from "./dpc2r7rb.js";
21
- import {
22
- quoteIdent,
23
- createObjectSql
24
- } from "./sjk86yrx.js";
27
+ assertDirectConnection
28
+ } from "./bdekbvmt.js";
25
29
  import {
26
- catalog
30
+ catalog,
31
+ isDomain
27
32
  } from "./ywspezzx.js";
28
33
  import {
29
34
  OkmError2
@@ -54,12 +59,14 @@ async function sealViews(runner, source) {
54
59
  if (views.length === 0 && !hasAtomic)
55
60
  return source;
56
61
  await dropScratch(runner);
57
- await runner.query(`create schema ${quoteIdent(SCRATCH)}`);
62
+ await runner.query(`create schema ${quoteIdent2(SCRATCH)}`);
58
63
  const previous = await runner.query(`select current_setting('search_path') as path`);
59
64
  const saved = cellText(previous[0]?.path);
60
65
  const path = await scratchSearchPath(runner, source);
66
+ let installed = [];
61
67
  try {
62
68
  await runner.query(`select set_config('search_path', $1, false)`, [path]);
69
+ installed = await createExtensions(runner, source);
63
70
  await createObjects(runner, source, "type");
64
71
  for (const object of source.objects) {
65
72
  if (object.kind !== "table")
@@ -116,6 +123,7 @@ async function sealViews(runner, source) {
116
123
  return;
117
124
  });
118
125
  await dropScratch(runner);
126
+ await dropInstalledExtensions(runner, installed);
119
127
  }
120
128
  }
121
129
  async function scratchSearchPath(runner, source) {
@@ -141,44 +149,79 @@ async function scratchSearchPath(runner, source) {
141
149
  }
142
150
  }
143
151
  extra.sort();
144
- return [SCRATCH, ...extra, "public"].map((name) => quoteIdent(name)).join(", ");
152
+ return [SCRATCH, ...extra, "public"].map((name) => quoteIdent2(name)).join(", ");
145
153
  }
146
154
  async function createObjects(runner, source, kind) {
147
155
  for (const object of source.objects) {
148
156
  if (object.kind !== kind)
149
157
  continue;
150
- const statement = createObjectSql(object, SCRATCH);
158
+ const statement = createObjectSql2(object, SCRATCH);
151
159
  if (statement !== undefined)
152
160
  await runner.query(statement);
153
161
  }
154
162
  }
163
+ async function createExtensions(runner, source) {
164
+ const installed = [];
165
+ for (const object of source.objects) {
166
+ if (object.kind !== "extension")
167
+ continue;
168
+ const name = object.identity.name;
169
+ const present = await runner.query(`select 1 as ok from pg_extension where extname = $1`, [
170
+ name
171
+ ]);
172
+ if (present.length > 0)
173
+ continue;
174
+ const statement = createObjectSql2(object, SCRATCH);
175
+ if (statement === undefined)
176
+ continue;
177
+ await runner.query(statement);
178
+ installed.push(name);
179
+ }
180
+ return installed;
181
+ }
182
+ async function dropInstalledExtensions(runner, names) {
183
+ for (const name of names) {
184
+ await runner.query(`drop extension if exists ${quoteIdent2(name)}`).catch(() => {
185
+ return;
186
+ });
187
+ }
188
+ }
155
189
  var FUNCTION_DEFS = `
156
- select pg_get_functiondef(p.oid) as definition
190
+ select p.proname as name,
191
+ pg_get_function_identity_arguments(p.oid) as args,
192
+ pg_get_functiondef(p.oid) as definition
157
193
  from pg_proc p
158
194
  join pg_namespace n on n.oid = p.pronamespace
159
195
  where n.nspname = $1 and p.prokind = 'f'
160
- order by p.oid
161
196
  `;
162
197
  async function reprintAtomicBodies(runner, source) {
163
198
  const created = source.objects.filter((object) => object.kind === "function");
164
199
  if (!created.some((object) => object.definition.atomic === true))
165
200
  return source;
166
201
  const rows = await runner.query(FUNCTION_DEFS, [SCRATCH]);
167
- if (rows.length !== created.length) {
168
- throw new OkmError2("OKM1020", `Expected ${String(created.length)} functions in the scratch schema and found ${String(rows.length)}.`, { fix: { summary: "The function body has to run against the tables in this schema." } });
169
- }
170
- const bodies = new Map;
171
- for (let index = 0;index < created.length; index += 1) {
172
- const object = created[index];
173
- if (object === undefined || object.definition.atomic !== true)
174
- continue;
175
- bodies.set(object, atomicBody(cellText(rows[index]?.definition)));
202
+ const printed = rows.map((row) => ({
203
+ name: cellText(row.name),
204
+ args: splitIdentityArguments(cellText(row.args)),
205
+ body: atomicBody(cellText(row.definition))
206
+ }));
207
+ const byName = new Map;
208
+ for (let index = 0;index < printed.length; index += 1) {
209
+ const name = printed[index]?.name ?? "";
210
+ const list = byName.get(name);
211
+ if (list === undefined)
212
+ byName.set(name, [index]);
213
+ else
214
+ list.push(index);
176
215
  }
216
+ const used = new Set;
177
217
  let changed = false;
178
218
  const objects = source.objects.map((object) => {
179
- if (object.kind !== "function")
219
+ if (object.kind !== "function" || object.definition.atomic !== true)
180
220
  return object;
181
- const body = bodies.get(object);
221
+ const named = byName.get(object.identity.name) ?? [];
222
+ const index = chooseReprint(object, printed, named, used);
223
+ used.add(index);
224
+ const body = printed[index]?.body;
182
225
  if (body === undefined || body === object.definition.body)
183
226
  return object;
184
227
  changed = true;
@@ -186,6 +229,111 @@ async function reprintAtomicBodies(runner, source) {
186
229
  });
187
230
  return changed ? catalog(objects) : source;
188
231
  }
232
+ function chooseReprint(object, printed, named, used) {
233
+ const only = named[0];
234
+ if (named.length === 1 && only !== undefined && !used.has(only))
235
+ return only;
236
+ const matches = named.filter((index) => {
237
+ const row = printed[index];
238
+ return row !== undefined && !used.has(index) && identityMatches(object, row.args);
239
+ });
240
+ const index = matches[0];
241
+ if (named.length > 1 && matches.length === 1 && index !== undefined)
242
+ return index;
243
+ throw reprintMiss(object, named.map((index) => printed[index]).filter((row) => row !== undefined));
244
+ }
245
+ function reprintMiss(object, rows) {
246
+ const catalog = object.identity.argTypes.join(", ");
247
+ const scratch = rows.length === 0 ? "(none)" : rows.map((row) => row.args.length === 0 ? "(no arguments)" : row.args.join(", ")).join("; ");
248
+ return new OkmError2("OKM1020", `Function ${object.identity.name}(${catalog}) was not created in the scratch schema. Catalog arguments: ${catalog}. Scratch arguments: ${scratch}.`, { fix: { summary: "The function body has to run against the tables in this schema." } });
249
+ }
250
+ function identityMatches(object, args) {
251
+ if (args.length !== object.identity.argTypes.length)
252
+ return false;
253
+ return args.every((printed, index) => printedHasType(object.identity.argTypes[index] ?? "", printed));
254
+ }
255
+ function splitIdentityArguments(args) {
256
+ const trimmed = args.trim();
257
+ if (trimmed.length === 0)
258
+ return [];
259
+ const parts = [];
260
+ let current = "";
261
+ let depth = 0;
262
+ for (const char of trimmed) {
263
+ if (char === "(")
264
+ depth += 1;
265
+ else if (char === ")" && depth > 0)
266
+ depth -= 1;
267
+ if (char === "," && depth === 0) {
268
+ parts.push(current.trim());
269
+ current = "";
270
+ continue;
271
+ }
272
+ current += char;
273
+ }
274
+ parts.push(current.trim());
275
+ return parts;
276
+ }
277
+ var ARG_TYPE_ALIASES = {
278
+ int: "integer",
279
+ int2: "smallint",
280
+ int4: "integer",
281
+ int8: "bigint",
282
+ bool: "boolean",
283
+ decimal: "numeric",
284
+ char: "character",
285
+ float4: "real",
286
+ float8: "double precision",
287
+ varchar: "character varying",
288
+ time: "time without time zone",
289
+ timetz: "time with time zone",
290
+ timestamp: "timestamp without time zone",
291
+ timestamptz: "timestamp with time zone"
292
+ };
293
+ function printedHasType(author, printed) {
294
+ const want = canonicalArgType(author);
295
+ const got = printed.trim().replaceAll(/\s+/g, " ").toLowerCase();
296
+ if (canonicalArgType(got) === want)
297
+ return true;
298
+ const space = got.indexOf(" ");
299
+ if (space < 0)
300
+ return false;
301
+ const name = got.slice(0, space);
302
+ if (!/^[a-z_][a-z0-9_]*$/.test(name))
303
+ return false;
304
+ return canonicalArgType(got.slice(space + 1)) === want;
305
+ }
306
+ function canonicalArgType(type) {
307
+ let compact = type.trim().replaceAll(/\s+/g, " ").toLowerCase();
308
+ const dot = compact.lastIndexOf(".");
309
+ if (dot >= 0)
310
+ compact = compact.slice(dot + 1);
311
+ compact = stripTypmods(compact).replaceAll(/\s+/g, " ").trim();
312
+ let arrays = 0;
313
+ while (compact.endsWith("[]")) {
314
+ arrays += 1;
315
+ compact = compact.slice(0, -2).trim();
316
+ }
317
+ const aliased = ARG_TYPE_ALIASES[compact] ?? compact;
318
+ return arrays === 0 ? aliased : `${aliased}${"[]".repeat(arrays)}`;
319
+ }
320
+ function stripTypmods(type) {
321
+ let out = "";
322
+ let depth = 0;
323
+ for (const char of type) {
324
+ if (char === "(") {
325
+ depth += 1;
326
+ continue;
327
+ }
328
+ if (char === ")" && depth > 0) {
329
+ depth -= 1;
330
+ continue;
331
+ }
332
+ if (depth === 0)
333
+ out += char;
334
+ }
335
+ return out;
336
+ }
189
337
  async function createViews(runner, views) {
190
338
  const pending = [...views];
191
339
  let last = "";
@@ -193,7 +341,7 @@ async function createViews(runner, views) {
193
341
  const failed = [];
194
342
  let created = 0;
195
343
  for (const object of pending) {
196
- const sql = object.kind === "materializedView" ? `create materialized view ${quoteIdent(object.identity.name)} as ${object.definition.query} with no data` : `create view ${quoteIdent(object.identity.name)} as ${object.definition.query}`;
344
+ const sql = object.kind === "materializedView" ? `create materialized view ${quoteIdent2(object.identity.name)} as ${object.definition.query} with no data` : `create view ${quoteIdent2(object.identity.name)} as ${object.definition.query}`;
197
345
  try {
198
346
  await runner.query(sql);
199
347
  created += 1;
@@ -213,8 +361,8 @@ async function createViews(runner, views) {
213
361
  }
214
362
  function stubTable(object, source) {
215
363
  const columns = source.objects.filter((item) => item.kind === "column" && item.identity.parent.name === object.identity.name);
216
- const lines = columns.map((column) => `${quoteIdent(column.identity.name)} ${column.definition.dataType}`);
217
- return `create table ${quoteIdent(object.identity.name)} (${lines.join(", ")})`;
364
+ const lines = columns.map((column) => `${quoteIdent2(column.identity.name)} ${column.definition.dataType}`);
365
+ return `create table ${quoteIdent2(object.identity.name)} (${lines.join(", ")})`;
218
366
  }
219
367
  function readColumns(object, printed) {
220
368
  const live = printed.length === 0 ? [] : printed.split(`
@@ -260,44 +408,45 @@ async function dropScratch(runner) {
260
408
  for (const row of views) {
261
409
  const kind = cellText(row.kind) === "m" ? "materialized view" : "view";
262
410
  try {
263
- await runner.query(`drop ${kind} if exists ${quoteIdent(SCRATCH)}.${quoteIdent(cellText(row.name))}`);
411
+ await runner.query(`drop ${kind} if exists ${quoteIdent2(SCRATCH)}.${quoteIdent2(cellText(row.name))}`);
264
412
  } catch {}
265
413
  }
266
414
  }
267
415
  for (const row of routines) {
268
416
  const args = cellText(row.args);
269
- await runner.query(`drop function if exists ${quoteIdent(SCRATCH)}.${quoteIdent(cellText(row.name))}(${args})`);
417
+ await runner.query(`drop function if exists ${quoteIdent2(SCRATCH)}.${quoteIdent2(cellText(row.name))}(${args})`);
270
418
  }
271
419
  for (const row of rows) {
272
420
  if (cellText(row.kind) !== "r")
273
421
  continue;
274
- await runner.query(`drop table if exists ${quoteIdent(SCRATCH)}.${quoteIdent(cellText(row.name))}`);
422
+ await runner.query(`drop table if exists ${quoteIdent2(SCRATCH)}.${quoteIdent2(cellText(row.name))}`);
275
423
  }
276
- await runner.query(`drop schema if exists ${quoteIdent(SCRATCH)} cascade`);
424
+ await runner.query(`drop schema if exists ${quoteIdent2(SCRATCH)} cascade`);
277
425
  }
278
426
 
279
427
  // src/tooling/migrate/drift.ts
280
428
  async function assertAuthorDrift2(url, author, roles, allowPooler = false) {
281
429
  assertDirectConnection(url, allowPooler);
282
- const sql = postgres(url, {
430
+ const sql = postgres(driverUrl(url), {
283
431
  max: 1,
284
432
  connect_timeout: 5,
285
433
  idle_timeout: 1,
286
434
  onnotice: () => {}
287
435
  });
288
436
  try {
289
- await assertStableBackend(async () => {
437
+ await probeStableBackend(url, async () => {
290
438
  const rows = await sql`select pg_backend_pid()::text as pid`;
291
439
  return rows[0]?.pid ?? "";
292
440
  }, allowPooler);
441
+ const schema = authorSchema(author);
293
442
  const present = await sql`
294
- select to_regclass('public.okm_meta')::text as reg
443
+ select to_regclass(${metaReg(schema)})::text as reg
295
444
  `;
296
445
  if (present[0]?.reg == null)
297
446
  return;
298
447
  const runner = catalogQuery2(sql);
299
- const authorOnServer = await sealViews(runner, author);
300
- const live = await introspectSchema(runner, "public", "public", managedRoleOptions2(roles));
448
+ const authorOnServer = await sealDomainChecks2(runner, await sealViews(runner, author));
449
+ const live = await introspectSchema(runner, schema, schema, managedRoleOptions2(roles));
301
450
  const plan = planMigration({ before: live, after: authorOnServer, name: "check" });
302
451
  if (plan.steps.length === 0)
303
452
  return;
@@ -314,6 +463,27 @@ ${plan.steps.map((step) => step.sql).join(`
314
463
  await finishQuiet(() => sql.end({ timeout: 5 }));
315
464
  }
316
465
  }
466
+ async function sealDomainChecks2(runner, source) {
467
+ const objects = [];
468
+ let changed = false;
469
+ for (const object of source.objects) {
470
+ if (object.kind !== "type" || !isDomain(object.definition)) {
471
+ objects.push(object);
472
+ continue;
473
+ }
474
+ const reprinted = await reprintDomainCheck(runner, object.definition.base, object.definition.check);
475
+ if (reprinted === object.definition.check) {
476
+ objects.push(object);
477
+ continue;
478
+ }
479
+ changed = true;
480
+ objects.push({
481
+ ...object,
482
+ definition: { ...object.definition, check: reprinted }
483
+ });
484
+ }
485
+ return changed ? { version: source.version, objects } : source;
486
+ }
317
487
  function catalogQuery2(sql) {
318
488
  return {
319
489
  async query(text, params) {
@@ -334,6 +504,19 @@ function managedRoleOptions2(roles) {
334
504
  ...roles?.reporting !== undefined ? { reportingRole: roles.reporting } : {}
335
505
  };
336
506
  }
507
+ function authorSchema(author) {
508
+ for (const object of author.objects) {
509
+ if (object.kind === "table" && object.owner !== "external" && object.identity.namespace.form === "static") {
510
+ return object.identity.namespace.name;
511
+ }
512
+ }
513
+ return "public";
514
+ }
515
+ function metaReg(schema) {
516
+ if (schema === "public")
517
+ return "public.okm_meta";
518
+ return `${quoteIdent2(schema)}.okm_meta`;
519
+ }
337
520
  function managedRoleNames(roles) {
338
521
  if (roles === undefined)
339
522
  return;
@@ -345,4 +528,4 @@ function managedRoleNames(roles) {
345
528
  return [...names];
346
529
  }
347
530
 
348
- export { sealViews, assertAuthorDrift2, catalogQuery2, managedRoleOptions2 };
531
+ export { sealViews, assertAuthorDrift2, sealDomainChecks2, catalogQuery2, managedRoleOptions2 };
@@ -3,11 +3,11 @@ import {
3
3
  } from "./cm3w0ywp.js";
4
4
  import {
5
5
  noTimeout
6
- } from "./q0cqt2sp.js";
6
+ } from "./tr64w5p0.js";
7
7
  import {
8
8
  noticeBuffer,
9
9
  WireSession
10
- } from "./mtw6jz76.js";
10
+ } from "./e275q7sd.js";
11
11
  import {
12
12
  NEON_WEBSOCKET_CAPABILITIES,
13
13
  NEON_HTTP_CAPABILITIES,
@@ -17,7 +17,7 @@ import {
17
17
  runCall,
18
18
  EMPTY_NOTICES,
19
19
  resultFrom
20
- } from "./ae4j5f42.js";
20
+ } from "./mfvx6kjx.js";
21
21
 
22
22
  // src/adapters/pg/neon.ts
23
23
  import {
@@ -117,7 +117,7 @@ async function openWebSocket(config) {
117
117
  counters.busy = Math.max(0, counters.busy - 1);
118
118
  });
119
119
  const held = { pool, acquireMs, counters, notices, named, isClosed };
120
- const checkout = () => closed ? rejectClosed() : import("./jx2m62cs.js").then((mod) => mod.checkout(held));
120
+ const checkout = () => closed ? rejectClosed() : import("./wbdh9qbg.js").then((mod) => mod.checkout(held));
121
121
  return {
122
122
  capabilities: NEON_WEBSOCKET_CAPABILITIES,
123
123
  execute(text, params, options) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  touchFields,
3
3
  fieldSealed
4
- } from "./bxas03mq.js";
4
+ } from "./63qjmhnp.js";
5
5
  import {
6
6
  projectExpr,
7
7
  quote,
@@ -0,0 +1,35 @@
1
+ import {
2
+ quoteIdent2,
3
+ renderCatalog2,
4
+ uniqueBeforeForeignKey2,
5
+ ownedByView2,
6
+ dropObjectSql2,
7
+ createObjectSql2,
8
+ functionSql2,
9
+ viewSql2,
10
+ policyCreatePlan2,
11
+ policyDropPlan2,
12
+ refreshMaterializedViewSql2,
13
+ alterColumnSql2,
14
+ identitySequence2,
15
+ createTableSql2,
16
+ qualify2
17
+ } from "./fk9vef30.js";
18
+ import"./12z7aznj.js";
19
+ export {
20
+ alterColumnSql2 as alterColumnSql,
21
+ createObjectSql2 as createObjectSql,
22
+ createTableSql2 as createTableSql,
23
+ dropObjectSql2 as dropObjectSql,
24
+ functionSql2 as functionSql,
25
+ identitySequence2 as identitySequence,
26
+ ownedByView2 as ownedByView,
27
+ policyCreatePlan2 as policyCreatePlan,
28
+ policyDropPlan2 as policyDropPlan,
29
+ qualify2 as qualify,
30
+ quoteIdent2 as quoteIdent,
31
+ refreshMaterializedViewSql2 as refreshMaterializedViewSql,
32
+ renderCatalog2 as renderCatalog,
33
+ uniqueBeforeForeignKey2 as uniqueBeforeForeignKey,
34
+ viewSql2 as viewSql
35
+ };