okmodel 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/README.md +14 -0
  2. package/dist/dialects/pg/ext/btree-gin.d.ts +26 -0
  3. package/dist/dialects/pg/ext/btree-gin.js +20 -0
  4. package/dist/dialects/pg/ext/btree-gist.d.ts +26 -0
  5. package/dist/dialects/pg/ext/btree-gist.js +20 -0
  6. package/dist/dialects/pg/ext/call.d.ts +53 -0
  7. package/dist/dialects/pg/ext/citext.js +1 -1
  8. package/dist/dialects/pg/ext/feature.d.ts +26 -0
  9. package/dist/dialects/pg/ext/fuzzystrmatch.d.ts +34 -0
  10. package/dist/dialects/pg/ext/fuzzystrmatch.js +33 -0
  11. package/dist/dialects/pg/ext/hstore.d.ts +41 -0
  12. package/dist/dialects/pg/ext/hstore.js +29 -0
  13. package/dist/dialects/pg/ext/index.d.ts +56 -0
  14. package/dist/dialects/pg/ext/index.js +1 -1
  15. package/dist/dialects/pg/ext/ltree.d.ts +41 -0
  16. package/dist/dialects/pg/ext/ltree.js +29 -0
  17. package/dist/dialects/pg/ext/pg-trgm.js +4 -13
  18. package/dist/dialects/pg/ext/pgcrypto.d.ts +33 -0
  19. package/dist/dialects/pg/ext/pgcrypto.js +33 -0
  20. package/dist/dialects/pg/ext/unaccent.d.ts +26 -0
  21. package/dist/dialects/pg/ext/unaccent.js +21 -0
  22. package/dist/dialects/pg/ext/using.d.ts +23 -0
  23. package/dist/dialects/pg/ext/versions.d.ts +36 -0
  24. package/dist/dialects/pg/external.d.ts +19 -0
  25. package/dist/dialects/pg/fn/index.js +4 -4
  26. package/dist/dialects/pg/index.d.ts +1 -0
  27. package/dist/dialects/pg/index.js +16 -11
  28. package/dist/dialects/pg/view/index.js +5 -5
  29. package/dist/dialects/pg/view/scratch.d.ts +4 -1
  30. package/dist/runtime/artifact-file.d.ts +22 -0
  31. package/dist/runtime/client.d.ts +10 -0
  32. package/dist/runtime/drift-detail.d.ts +2 -1
  33. package/dist/runtime/drift.d.ts +3 -10
  34. package/dist/runtime/pg/bun.js +4 -4
  35. package/dist/runtime/pg/neon.js +4 -4
  36. package/dist/runtime/pg/pg.js +4 -4
  37. package/dist/runtime/pg/pglite.js +4 -4
  38. package/dist/runtime/pg/postgresjs.js +4 -4
  39. package/dist/runtime/server-check.d.ts +36 -6
  40. package/dist/runtime/traits/index.js +5 -5
  41. package/dist/runtime/validate/index.js +1 -1
  42. package/dist/shared/{4m6hskg8.js → 0j6qe91y.js} +4 -4
  43. package/dist/shared/{14x60fbf.js → 1mxm04fy.js} +5 -5
  44. package/dist/shared/{b6d6p0zc.js → 2szgv6yj.js} +5 -5
  45. package/dist/shared/{f4jy1j7x.js → 2zdxkt7b.js} +909 -100
  46. package/dist/shared/{mnvjvqyp.js → 3456242y.js} +17 -17
  47. package/dist/shared/3t6kw83m.js +1 -1
  48. package/dist/shared/{6m78c8ss.js → 5kyb3tqx.js} +1 -1
  49. package/dist/shared/61bmrmhr.js +35 -0
  50. package/dist/shared/{zbqbmmrp.js → 62b603gr.js} +8 -8
  51. package/dist/shared/{jgqj11w4.js → 6f0z3hzh.js} +4 -0
  52. package/dist/shared/{dpc2r7rb.js → 6nae0spm.js} +150 -89
  53. package/dist/shared/{0wrea3jq.js → 71n0jmhc.js} +1 -1
  54. package/dist/shared/7ba5h6pb.js +17 -0
  55. package/dist/shared/{k86n8vq3.js → 8jesqsrk.js} +1 -1
  56. package/dist/shared/{qd9hhd8f.js → 8n688yjg.js} +1 -1
  57. package/dist/shared/{zgex00fd.js → 8qzkd9f3.js} +5 -5
  58. package/dist/shared/{mkrn359n.js → 90sg0w5a.js} +159 -31
  59. package/dist/shared/{7ghwamrf.js → 99qp9vtg.js} +1 -1
  60. package/dist/shared/{bxas03mq.js → 9dtgn1z2.js} +1 -1
  61. package/dist/shared/{p5nh3r8q.js → aksb89mn.js} +2 -2
  62. package/dist/shared/{wcrheftc.js → bphrgwz9.js} +2 -2
  63. package/dist/shared/{wz2a78mp.js → c3mvnq7a.js} +1 -1
  64. package/dist/shared/{pan0370z.js → ccsmhv9r.js} +24 -6
  65. package/dist/shared/{n0jmpgj1.js → cexb7z6b.js} +1 -1
  66. package/dist/shared/{wvdjznah.js → cf8zdz5p.js} +5 -5
  67. package/dist/shared/{3449rcae.js → ckz05z15.js} +4 -4
  68. package/dist/shared/{35q0n9tz.js → dd5pmnky.js} +7 -7
  69. package/dist/shared/{e8zyaqvj.js → ds229x4r.js} +1 -1
  70. package/dist/{tooling/shared/yw30vnq2.js → shared/e275q7sd.js} +1 -1
  71. package/dist/shared/{mfedzr74.js → ebhz8vh6.js} +4 -4
  72. package/dist/shared/{z581d7ny.js → fdsz3w80.js} +2 -2
  73. package/dist/shared/{sjk86yrx.js → fk9vef30.js} +84 -73
  74. package/dist/shared/{needfe47.js → g89fmz5s.js} +1 -1
  75. package/dist/shared/{m4xff2a6.js → ghqzdp94.js} +2 -2
  76. package/dist/shared/h9811jjm.js +17 -0
  77. package/dist/shared/{kj9d8maq.js → jpybhf98.js} +1 -1
  78. package/dist/shared/kzgrnckd.js +29 -0
  79. package/dist/shared/{agsfb86s.js → mazpbcdj.js} +4 -4
  80. package/dist/shared/{195pzzzz.js → mgaq2sd3.js} +10 -7
  81. package/dist/shared/{5mtf6cj3.js → mvmm3xpb.js} +5 -2
  82. package/dist/shared/{p3xbdcvt.js → myk8fswx.js} +55 -6
  83. package/dist/shared/{njga14v4.js → n306gqkd.js} +8 -8
  84. package/dist/shared/n5whk3mt.js +665 -0
  85. package/dist/shared/{bah9nbg3.js → npdftanb.js} +12 -20
  86. package/dist/shared/{16kvjebh.js → pg4ezgyf.js} +7 -26
  87. package/dist/{tooling/shared/08kemxjd.js → shared/pgsak1yw.js} +1 -1
  88. package/dist/shared/{jp36k7dp.js → qvwwp1mp.js} +61 -40
  89. package/dist/shared/rbxt795q.js +1766 -0
  90. package/dist/shared/{g5yc06ka.js → s7he5e5d.js} +1 -1
  91. package/dist/shared/{hfqmpasr.js → ss2kv2rs.js} +5 -5
  92. package/dist/shared/stfa9xcw.js +450 -0
  93. package/dist/{tooling/shared/rs1jb051.js → shared/tr64w5p0.js} +1 -1
  94. package/dist/shared/{jebgrkeq.js → tw1nvvfj.js} +2 -2
  95. package/dist/shared/{v1wad97q.js → wvtjg5m3.js} +1 -1
  96. package/dist/shared/xqacq37x.js +61 -0
  97. package/dist/shared/{n05z9nwz.js → xtsydxjg.js} +1 -1
  98. package/dist/shared/{jx2m62cs.js → xv8qj97g.js} +5 -5
  99. package/dist/shared/{63f4ksbz.js → xwhdcrm4.js} +1 -1
  100. package/dist/shared/{hm5f8jby.js → yvabyg9k.js} +6 -6
  101. package/dist/shared/yybhre6n.js +136 -0
  102. package/dist/shared/zdqf8k5d.js +8 -0
  103. package/dist/tooling/cli.js +94 -22
  104. package/dist/tooling/driver-run.js +15 -332
  105. package/dist/tooling/github/comment.d.ts +50 -0
  106. package/dist/tooling/github/post-comment.d.ts +17 -0
  107. package/dist/tooling/migrate/commands.d.ts +2 -1
  108. package/dist/tooling/migrate/config.d.ts +13 -0
  109. package/dist/tooling/migrate/export.d.ts +165 -0
  110. package/dist/tooling/migrate/ext-surface.d.ts +80 -0
  111. package/dist/tooling/migrate/ext.d.ts +31 -4
  112. package/dist/tooling/migrate/import-drizzle.d.ts +40 -0
  113. package/dist/tooling/migrate/index.d.ts +3 -0
  114. package/dist/tooling/migrate/index.js +55 -10
  115. package/dist/tooling/migrate/lint-rules.d.ts +18 -1
  116. package/dist/tooling/migrate/lint.d.ts +14 -1
  117. package/dist/tooling/migrate/place.d.ts +18 -0
  118. package/dist/tooling/migrate/plan-json.d.ts +65 -0
  119. package/dist/tooling/migrate/project.d.ts +10 -1
  120. package/dist/tooling/migrate/pull-emit.d.ts +98 -0
  121. package/dist/tooling/migrate/pull-routines.d.ts +126 -0
  122. package/dist/tooling/migrate/pull-verify.d.ts +26 -0
  123. package/dist/tooling/migrate/pull.d.ts +62 -0
  124. package/dist/tooling/migrate/reprint.d.ts +32 -0
  125. package/dist/tooling/migrate/sandbox.d.ts +8 -2
  126. package/dist/tooling/migrate/schema-api.d.ts +43 -0
  127. package/dist/tooling/migrate/sql-lex.d.ts +18 -0
  128. package/dist/tooling/shared/{3m1hkg7z.js → 04svnxxj.js} +4 -4
  129. package/dist/tooling/shared/{ppnnnvj8.js → 0j0jtse1.js} +1 -1
  130. package/dist/tooling/shared/{z8d7ptht.js → 0r05zhyq.js} +5 -5
  131. package/dist/tooling/shared/{a6pp9d12.js → 1800eymw.js} +3 -3
  132. package/dist/tooling/shared/{cmptmb4f.js → 35zemrmf.js} +1 -1
  133. package/dist/tooling/shared/{w7qe8sj1.js → 3rmaz3pq.js} +1 -1
  134. package/dist/{shared/q0cqt2sp.js → tooling/shared/3yn79q5m.js} +1 -1
  135. package/dist/tooling/shared/{2revefqt.js → 57btdkgm.js} +2 -2
  136. package/dist/tooling/shared/{ma2340rx.js → 5bmksndh.js} +2 -2
  137. package/dist/tooling/shared/{9xzm7hjg.js → 5p8km5jb.js} +3 -3
  138. package/dist/tooling/shared/{xhrnjch9.js → 5x3pf400.js} +3 -3
  139. package/dist/tooling/shared/{wwnekq5n.js → 5zrzffnk.js} +1 -1
  140. package/dist/tooling/shared/{p7f08ktn.js → 62fxpc1p.js} +7 -7
  141. package/dist/tooling/shared/{7ae7rjmn.js → 68tf18v4.js} +2 -2
  142. package/dist/tooling/shared/{rf83gr2d.js → 6vk28rjp.js} +7 -3
  143. package/dist/tooling/shared/76pv6qff.js +9 -0
  144. package/dist/tooling/shared/{bz2dqhab.js → 7aews1zg.js} +3 -3
  145. package/dist/tooling/shared/{9kazs5p6.js → 7b3xp9gc.js} +3 -3
  146. package/dist/tooling/shared/{4d2w25vw.js → 7pxncnzs.js} +2 -2
  147. package/dist/tooling/shared/{zvnhh1n0.js → 829fjxyw.js} +2 -2
  148. package/dist/tooling/shared/{dzx85q70.js → 8m5znpdt.js} +1 -1
  149. package/dist/tooling/shared/{g9ad4n80.js → 8yr7ges1.js} +7 -7
  150. package/dist/tooling/shared/{tn8gay14.js → 9qr9rkbh.js} +6 -6
  151. package/dist/tooling/shared/{8sqrsw3s.js → 9sfbtwsk.js} +3 -3
  152. package/dist/{shared/bnby0esn.js → tooling/shared/9wsnsvbf.js} +1 -1
  153. package/dist/tooling/shared/{aftb2mwr.js → a2xe04bm.js} +1 -1
  154. package/dist/tooling/shared/{nf7jmhfa.js → a4pzghha.js} +2 -2
  155. package/dist/tooling/shared/{y5656f0e.js → am04v8na.js} +5 -5
  156. package/dist/tooling/shared/{417zdsk7.js → asgr07mp.js} +5 -5
  157. package/dist/tooling/shared/{pqy21k24.js → c0xevn1h.js} +4 -4
  158. package/dist/tooling/shared/dhatassp.js +134 -0
  159. package/dist/tooling/shared/{spk1jg3r.js → ezqn88nj.js} +8 -8
  160. package/dist/tooling/shared/{6nyfyw70.js → f77nnfqy.js} +2 -2
  161. package/dist/tooling/shared/{wt7j7nf6.js → fh07z1dt.js} +1 -1
  162. package/dist/tooling/shared/{3rrw5w8f.js → gqwevek4.js} +1 -1
  163. package/dist/tooling/shared/{f9mphxej.js → hfq3n3bd.js} +346 -19
  164. package/dist/tooling/shared/{vs0t6qt8.js → j664qjrt.js} +2 -2
  165. package/dist/tooling/shared/{733a1tq3.js → jpgmjsx3.js} +3 -3
  166. package/dist/tooling/shared/{mtrqn2hn.js → jr2nmr81.js} +22 -30
  167. package/dist/{shared/mtw6jz76.js → tooling/shared/jsjjz875.js} +1 -1
  168. package/dist/tooling/shared/{2wtvc7rw.js → kbqnrs1x.js} +2 -2
  169. package/dist/tooling/shared/{gfvtj6d0.js → kz715295.js} +7 -7
  170. package/dist/tooling/shared/{a7q7t4n3.js → m3xt8b1h.js} +2 -2
  171. package/dist/tooling/shared/{dw08f3m8.js → m4hhb8aa.js} +2 -2
  172. package/dist/tooling/shared/{y031jct9.js → mw5npye0.js} +2 -2
  173. package/dist/tooling/shared/{vraj6d74.js → nxq95eb6.js} +3 -3
  174. package/dist/tooling/shared/{fb9k2qwd.js → qartgazh.js} +11 -30
  175. package/dist/tooling/shared/{xjs6zqtc.js → rcywj2w8.js} +9 -9
  176. package/dist/tooling/shared/{dy672fz6.js → s6qha57m.js} +2 -2
  177. package/dist/tooling/shared/{vx86qjv8.js → shjs0379.js} +3 -3
  178. package/dist/tooling/shared/{345tbc2k.js → sjwkt1pg.js} +1 -1
  179. package/dist/tooling/shared/{rq5kk8j6.js → stebqyyd.js} +3 -3
  180. package/dist/tooling/shared/{yk9mp7vb.js → t4xveemq.js} +4 -4
  181. package/dist/tooling/shared/{djydjpqt.js → t6zjeake.js} +5 -5
  182. package/dist/tooling/shared/{zhwnfyb2.js → tcwpjvxe.js} +1 -1
  183. package/dist/tooling/shared/{72fyg4zv.js → tpssp7ac.js} +1 -1
  184. package/dist/tooling/shared/{jne7b93p.js → v6j1ep6w.js} +3 -3
  185. package/dist/tooling/shared/{ec71zqgt.js → vwr2y833.js} +2 -2
  186. package/dist/tooling/shared/{j9t5s12a.js → w17sj05d.js} +2 -2
  187. package/dist/tooling/shared/{3tq8pnb8.js → w5d89rb4.js} +1 -1
  188. package/dist/tooling/shared/{smn6kz1p.js → wbwq1jsa.js} +2 -2
  189. package/dist/tooling/shared/{pwsytxm5.js → wezxf3h8.js} +1 -1
  190. package/dist/tooling/shared/{5bvw2nev.js → yb4kd19s.js} +1 -1
  191. package/dist/tooling/shared/{gmcf9cxf.js → ybdew6j7.js} +2 -2
  192. package/dist/tooling/shared/{ep8zh3bk.js → yfedr1zb.js} +1 -1
  193. package/dist/tooling/shared/{ddjtfgnx.js → yhp829bx.js} +3 -3
  194. package/dist/tooling/shared/{yfr8hzhm.js → ytk1tjs0.js} +1 -1
  195. package/dist/tooling/shared/{03k6res6.js → zs9aymcp.js} +1 -1
  196. package/dist/tooling/shared/zx3v9phv.js +8 -0
  197. package/dist/tooling/testing/index.js +2 -2
  198. package/package.json +38 -9
  199. package/dist/shared/fjpnhqan.js +0 -71
  200. package/dist/shared/n41w4fbz.js +0 -113
  201. package/dist/tooling/shared/pw8fgahx.js +0 -69
  202. /package/dist/shared/{ae4j5f42.js → mfvx6kjx.js} +0 -0
@@ -3,6 +3,10 @@ import {
3
3
  viewObject,
4
4
  materializedViewObject
5
5
  } from "./12z7aznj.js";
6
+ import {
7
+ quoteIdent2,
8
+ createObjectSql2
9
+ } from "./fk9vef30.js";
6
10
  import {
7
11
  cellText,
8
12
  VIEW_DEPENDENCIES,
@@ -10,18 +14,14 @@ import {
10
14
  PUBLIC,
11
15
  introspectSchema,
12
16
  atomicBody
13
- } from "./p3xbdcvt.js";
17
+ } from "./myk8fswx.js";
14
18
  import {
15
19
  planMigration,
16
20
  sessionFailure,
17
21
  finishQuiet,
18
22
  assertDirectConnection,
19
23
  assertStableBackend
20
- } from "./dpc2r7rb.js";
21
- import {
22
- quoteIdent,
23
- createObjectSql
24
- } from "./sjk86yrx.js";
24
+ } from "./6nae0spm.js";
25
25
  import {
26
26
  catalog
27
27
  } from "./ywspezzx.js";
@@ -54,7 +54,7 @@ async function sealViews(runner, source) {
54
54
  if (views.length === 0 && !hasAtomic)
55
55
  return source;
56
56
  await dropScratch(runner);
57
- await runner.query(`create schema ${quoteIdent(SCRATCH)}`);
57
+ await runner.query(`create schema ${quoteIdent2(SCRATCH)}`);
58
58
  const previous = await runner.query(`select current_setting('search_path') as path`);
59
59
  const saved = cellText(previous[0]?.path);
60
60
  const path = await scratchSearchPath(runner, source);
@@ -141,44 +141,53 @@ async function scratchSearchPath(runner, source) {
141
141
  }
142
142
  }
143
143
  extra.sort();
144
- return [SCRATCH, ...extra, "public"].map((name) => quoteIdent(name)).join(", ");
144
+ return [SCRATCH, ...extra, "public"].map((name) => quoteIdent2(name)).join(", ");
145
145
  }
146
146
  async function createObjects(runner, source, kind) {
147
147
  for (const object of source.objects) {
148
148
  if (object.kind !== kind)
149
149
  continue;
150
- const statement = createObjectSql(object, SCRATCH);
150
+ const statement = createObjectSql2(object, SCRATCH);
151
151
  if (statement !== undefined)
152
152
  await runner.query(statement);
153
153
  }
154
154
  }
155
155
  var FUNCTION_DEFS = `
156
- select pg_get_functiondef(p.oid) as definition
156
+ select p.proname as name,
157
+ pg_get_function_identity_arguments(p.oid) as args,
158
+ pg_get_functiondef(p.oid) as definition
157
159
  from pg_proc p
158
160
  join pg_namespace n on n.oid = p.pronamespace
159
161
  where n.nspname = $1 and p.prokind = 'f'
160
- order by p.oid
161
162
  `;
162
163
  async function reprintAtomicBodies(runner, source) {
163
164
  const created = source.objects.filter((object) => object.kind === "function");
164
165
  if (!created.some((object) => object.definition.atomic === true))
165
166
  return source;
166
167
  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)));
168
+ const printed = rows.map((row) => ({
169
+ name: cellText(row.name),
170
+ args: splitIdentityArguments(cellText(row.args)),
171
+ body: atomicBody(cellText(row.definition))
172
+ }));
173
+ const byName = new Map;
174
+ for (let index = 0;index < printed.length; index += 1) {
175
+ const name = printed[index]?.name ?? "";
176
+ const list = byName.get(name);
177
+ if (list === undefined)
178
+ byName.set(name, [index]);
179
+ else
180
+ list.push(index);
176
181
  }
182
+ const used = new Set;
177
183
  let changed = false;
178
184
  const objects = source.objects.map((object) => {
179
- if (object.kind !== "function")
185
+ if (object.kind !== "function" || object.definition.atomic !== true)
180
186
  return object;
181
- const body = bodies.get(object);
187
+ const named = byName.get(object.identity.name) ?? [];
188
+ const index = chooseReprint(object, printed, named, used);
189
+ used.add(index);
190
+ const body = printed[index]?.body;
182
191
  if (body === undefined || body === object.definition.body)
183
192
  return object;
184
193
  changed = true;
@@ -186,6 +195,111 @@ async function reprintAtomicBodies(runner, source) {
186
195
  });
187
196
  return changed ? catalog(objects) : source;
188
197
  }
198
+ function chooseReprint(object, printed, named, used) {
199
+ const only = named[0];
200
+ if (named.length === 1 && only !== undefined && !used.has(only))
201
+ return only;
202
+ const matches = named.filter((index) => {
203
+ const row = printed[index];
204
+ return row !== undefined && !used.has(index) && identityMatches(object, row.args);
205
+ });
206
+ const index = matches[0];
207
+ if (named.length > 1 && matches.length === 1 && index !== undefined)
208
+ return index;
209
+ throw reprintMiss(object, named.map((index) => printed[index]).filter((row) => row !== undefined));
210
+ }
211
+ function reprintMiss(object, rows) {
212
+ const catalog = object.identity.argTypes.join(", ");
213
+ const scratch = rows.length === 0 ? "(none)" : rows.map((row) => row.args.length === 0 ? "(no arguments)" : row.args.join(", ")).join("; ");
214
+ 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." } });
215
+ }
216
+ function identityMatches(object, args) {
217
+ if (args.length !== object.identity.argTypes.length)
218
+ return false;
219
+ return args.every((printed, index) => printedHasType(object.identity.argTypes[index] ?? "", printed));
220
+ }
221
+ function splitIdentityArguments(args) {
222
+ const trimmed = args.trim();
223
+ if (trimmed.length === 0)
224
+ return [];
225
+ const parts = [];
226
+ let current = "";
227
+ let depth = 0;
228
+ for (const char of trimmed) {
229
+ if (char === "(")
230
+ depth += 1;
231
+ else if (char === ")" && depth > 0)
232
+ depth -= 1;
233
+ if (char === "," && depth === 0) {
234
+ parts.push(current.trim());
235
+ current = "";
236
+ continue;
237
+ }
238
+ current += char;
239
+ }
240
+ parts.push(current.trim());
241
+ return parts;
242
+ }
243
+ var ARG_TYPE_ALIASES = {
244
+ int: "integer",
245
+ int2: "smallint",
246
+ int4: "integer",
247
+ int8: "bigint",
248
+ bool: "boolean",
249
+ decimal: "numeric",
250
+ char: "character",
251
+ float4: "real",
252
+ float8: "double precision",
253
+ varchar: "character varying",
254
+ time: "time without time zone",
255
+ timetz: "time with time zone",
256
+ timestamp: "timestamp without time zone",
257
+ timestamptz: "timestamp with time zone"
258
+ };
259
+ function printedHasType(author, printed) {
260
+ const want = canonicalArgType(author);
261
+ const got = printed.trim().replaceAll(/\s+/g, " ").toLowerCase();
262
+ if (canonicalArgType(got) === want)
263
+ return true;
264
+ const space = got.indexOf(" ");
265
+ if (space < 0)
266
+ return false;
267
+ const name = got.slice(0, space);
268
+ if (!/^[a-z_][a-z0-9_]*$/.test(name))
269
+ return false;
270
+ return canonicalArgType(got.slice(space + 1)) === want;
271
+ }
272
+ function canonicalArgType(type) {
273
+ let compact = type.trim().replaceAll(/\s+/g, " ").toLowerCase();
274
+ const dot = compact.lastIndexOf(".");
275
+ if (dot >= 0)
276
+ compact = compact.slice(dot + 1);
277
+ compact = stripTypmods(compact).replaceAll(/\s+/g, " ").trim();
278
+ let arrays = 0;
279
+ while (compact.endsWith("[]")) {
280
+ arrays += 1;
281
+ compact = compact.slice(0, -2).trim();
282
+ }
283
+ const aliased = ARG_TYPE_ALIASES[compact] ?? compact;
284
+ return arrays === 0 ? aliased : `${aliased}${"[]".repeat(arrays)}`;
285
+ }
286
+ function stripTypmods(type) {
287
+ let out = "";
288
+ let depth = 0;
289
+ for (const char of type) {
290
+ if (char === "(") {
291
+ depth += 1;
292
+ continue;
293
+ }
294
+ if (char === ")" && depth > 0) {
295
+ depth -= 1;
296
+ continue;
297
+ }
298
+ if (depth === 0)
299
+ out += char;
300
+ }
301
+ return out;
302
+ }
189
303
  async function createViews(runner, views) {
190
304
  const pending = [...views];
191
305
  let last = "";
@@ -193,7 +307,7 @@ async function createViews(runner, views) {
193
307
  const failed = [];
194
308
  let created = 0;
195
309
  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}`;
310
+ 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
311
  try {
198
312
  await runner.query(sql);
199
313
  created += 1;
@@ -213,8 +327,8 @@ async function createViews(runner, views) {
213
327
  }
214
328
  function stubTable(object, source) {
215
329
  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(", ")})`;
330
+ const lines = columns.map((column) => `${quoteIdent2(column.identity.name)} ${column.definition.dataType}`);
331
+ return `create table ${quoteIdent2(object.identity.name)} (${lines.join(", ")})`;
218
332
  }
219
333
  function readColumns(object, printed) {
220
334
  const live = printed.length === 0 ? [] : printed.split(`
@@ -260,20 +374,20 @@ async function dropScratch(runner) {
260
374
  for (const row of views) {
261
375
  const kind = cellText(row.kind) === "m" ? "materialized view" : "view";
262
376
  try {
263
- await runner.query(`drop ${kind} if exists ${quoteIdent(SCRATCH)}.${quoteIdent(cellText(row.name))}`);
377
+ await runner.query(`drop ${kind} if exists ${quoteIdent2(SCRATCH)}.${quoteIdent2(cellText(row.name))}`);
264
378
  } catch {}
265
379
  }
266
380
  }
267
381
  for (const row of routines) {
268
382
  const args = cellText(row.args);
269
- await runner.query(`drop function if exists ${quoteIdent(SCRATCH)}.${quoteIdent(cellText(row.name))}(${args})`);
383
+ await runner.query(`drop function if exists ${quoteIdent2(SCRATCH)}.${quoteIdent2(cellText(row.name))}(${args})`);
270
384
  }
271
385
  for (const row of rows) {
272
386
  if (cellText(row.kind) !== "r")
273
387
  continue;
274
- await runner.query(`drop table if exists ${quoteIdent(SCRATCH)}.${quoteIdent(cellText(row.name))}`);
388
+ await runner.query(`drop table if exists ${quoteIdent2(SCRATCH)}.${quoteIdent2(cellText(row.name))}`);
275
389
  }
276
- await runner.query(`drop schema if exists ${quoteIdent(SCRATCH)} cascade`);
390
+ await runner.query(`drop schema if exists ${quoteIdent2(SCRATCH)} cascade`);
277
391
  }
278
392
 
279
393
  // src/tooling/migrate/drift.ts
@@ -290,14 +404,15 @@ async function assertAuthorDrift2(url, author, roles, allowPooler = false) {
290
404
  const rows = await sql`select pg_backend_pid()::text as pid`;
291
405
  return rows[0]?.pid ?? "";
292
406
  }, allowPooler);
407
+ const schema = authorSchema(author);
293
408
  const present = await sql`
294
- select to_regclass('public.okm_meta')::text as reg
409
+ select to_regclass(${metaReg(schema)})::text as reg
295
410
  `;
296
411
  if (present[0]?.reg == null)
297
412
  return;
298
413
  const runner = catalogQuery2(sql);
299
414
  const authorOnServer = await sealViews(runner, author);
300
- const live = await introspectSchema(runner, "public", "public", managedRoleOptions2(roles));
415
+ const live = await introspectSchema(runner, schema, schema, managedRoleOptions2(roles));
301
416
  const plan = planMigration({ before: live, after: authorOnServer, name: "check" });
302
417
  if (plan.steps.length === 0)
303
418
  return;
@@ -334,6 +449,19 @@ function managedRoleOptions2(roles) {
334
449
  ...roles?.reporting !== undefined ? { reportingRole: roles.reporting } : {}
335
450
  };
336
451
  }
452
+ function authorSchema(author) {
453
+ for (const object of author.objects) {
454
+ if (object.kind === "table" && object.owner !== "external" && object.identity.namespace.form === "static") {
455
+ return object.identity.namespace.name;
456
+ }
457
+ }
458
+ return "public";
459
+ }
460
+ function metaReg(schema) {
461
+ if (schema === "public")
462
+ return "public.okm_meta";
463
+ return `${quoteIdent2(schema)}.okm_meta`;
464
+ }
337
465
  function managedRoleNames(roles) {
338
466
  if (roles === undefined)
339
467
  return;
@@ -3,7 +3,7 @@ import {
3
3
  } from "./cnkky55j.js";
4
4
  import {
5
5
  rejectClosed
6
- } from "./ae4j5f42.js";
6
+ } from "./mfvx6kjx.js";
7
7
 
8
8
  // src/adapters/pg/reserved.ts
9
9
  var RESET_ALL = "RESET ALL";
@@ -244,7 +244,7 @@ async function planInsert(table, input, options, mods, generators, scope, tenanc
244
244
  keyColumns: undefined
245
245
  };
246
246
  }
247
- const conflictMod = options.onConflict === undefined || options.onConflict === "error" ? undefined : await import("./63f4ksbz.js");
247
+ const conflictMod = options.onConflict === undefined || options.onConflict === "error" ? undefined : await import("./xwhdcrm4.js");
248
248
  const conflict = conflictMod?.readConflict(table, options.onConflict, allow, tenantKeyList(tenancy));
249
249
  if (conflict?.kind === "update" && traitNamed(table, "versioned")) {
250
250
  fail2("OKM1120", `onConflict update on ${table.model.name} does not check the version you read.`, "Read the row and update. ignore and return do not change the existing row.");
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  identityColumn2
3
- } from "./g5yc06ka.js";
3
+ } from "./s7he5e5d.js";
4
4
  import {
5
5
  runWrite
6
6
  } from "./n4jqhpqz.js";
7
7
  import {
8
8
  queryHandle,
9
9
  settleCall
10
- } from "./bah9nbg3.js";
10
+ } from "./npdftanb.js";
11
11
  import {
12
12
  withRowFilters,
13
13
  archiveRules,
@@ -4,7 +4,7 @@ import {
4
4
  } from "./cm3w0ywp.js";
5
5
  import {
6
6
  PgSession
7
- } from "./35q0n9tz.js";
7
+ } from "./dd5pmnky.js";
8
8
  import {
9
9
  isConnectionLost
10
10
  } from "./cnkky55j.js";
@@ -15,7 +15,7 @@ import {
15
15
  runCall,
16
16
  rowsFrom,
17
17
  resultFrom
18
- } from "./ae4j5f42.js";
18
+ } from "./mfvx6kjx.js";
19
19
 
20
20
  // src/adapters/pg/postgres-extra.ts
21
21
  var RESET_ALL = "RESET ALL";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  build2,
3
3
  identityColumn2
4
- } from "./g5yc06ka.js";
4
+ } from "./s7he5e5d.js";
5
5
  export {
6
6
  build2 as build,
7
7
  identityColumn2 as identityColumn
@@ -1,9 +1,12 @@
1
1
  import {
2
2
  open2
3
- } from "./35q0n9tz.js";
3
+ } from "./dd5pmnky.js";
4
4
  import {
5
5
  startupHash2
6
6
  } from "./12z7aznj.js";
7
+ import {
8
+ quoteIdent2
9
+ } from "./fk9vef30.js";
7
10
  import {
8
11
  runTarget,
9
12
  assumeRole,
@@ -14,12 +17,12 @@ import {
14
17
  provisionMark,
15
18
  expandProvisioned,
16
19
  installSnapshot
17
- } from "./mnvjvqyp.js";
20
+ } from "./3456242y.js";
18
21
  import {
19
22
  assertCreateRole,
20
23
  currentUser,
21
24
  roleExists
22
- } from "./kj9d8maq.js";
25
+ } from "./jpybhf98.js";
23
26
  import {
24
27
  projectPath,
25
28
  loadMigrations,
@@ -30,7 +33,7 @@ import {
30
33
  projectHead,
31
34
  loadBuiltSchema,
32
35
  loadConfig
33
- } from "./f4jy1j7x.js";
36
+ } from "./2zdxkt7b.js";
34
37
  import {
35
38
  changesRole,
36
39
  batchSizeField,
@@ -41,7 +44,7 @@ import {
41
44
  assertDirectConnection,
42
45
  assertStableBackend,
43
46
  selectTarget
44
- } from "./dpc2r7rb.js";
47
+ } from "./6nae0spm.js";
45
48
  import {
46
49
  UUIDV7_POSTGRES,
47
50
  uuidv7NeedsPostgres
@@ -198,6 +201,7 @@ async function applyTarget2(request) {
198
201
  await prepareMigrationRole(connection, request, session);
199
202
  await assertExtensionsAvailable(connection, request.migrations);
200
203
  await assertUuidV7Available(connection, request.migrations);
204
+ await enterCatalogSchema(connection, request.schema ?? "public");
201
205
  const state = request.snapshot === undefined ? undefined : await targetState(connection);
202
206
  if (request.snapshot !== undefined && state !== undefined) {
203
207
  if (state.kind === "empty") {
@@ -273,6 +277,7 @@ nothing to apply
273
277
  reference: built === undefined ? [] : readReference(built.tables, built.casing, head.catalog)
274
278
  },
275
279
  ...config.roles !== undefined ? { migrationRole: config.roles.migration, appRole: config.roles.app } : {},
280
+ ...catalogSchema(config.namespace),
276
281
  lintDirectory: directory,
277
282
  onProgress: (line) => {
278
283
  if (write !== undefined)
@@ -299,6 +304,7 @@ async function pushProject2(cwd, flags) {
299
304
  after: head.catalog,
300
305
  renames: head.renames,
301
306
  name: "push",
307
+ ...catalogSchema(config.namespace),
302
308
  ...batchSizeField(config.backfill?.batchSize)
303
309
  });
304
310
  if (plan.steps.length === 0)
@@ -319,7 +325,8 @@ no changes
319
325
  steps: plan.steps
320
326
  }
321
327
  ],
322
- ...config.roles !== undefined ? { migrationRole: config.roles.migration, appRole: config.roles.app } : {}
328
+ ...config.roles !== undefined ? { migrationRole: config.roles.migration, appRole: config.roles.app } : {},
329
+ ...catalogSchema(config.namespace)
323
330
  });
324
331
  return formatReport(report);
325
332
  }
@@ -514,6 +521,17 @@ async function insertReference(connection, request) {
514
521
  function concreteSchema(request) {
515
522
  return request.searchPath ?? request.schema ?? "public";
516
523
  }
524
+ function catalogSchema(namespace) {
525
+ if (namespace === undefined || namespace === "public")
526
+ return;
527
+ return { schema: namespace };
528
+ }
529
+ async function enterCatalogSchema(connection, schema) {
530
+ if (schema === "public")
531
+ return;
532
+ await connection.execute(`create schema if not exists ${quoteIdent2(schema)}`);
533
+ await connection.execute(`set search_path to ${quoteIdent2(schema)}`);
534
+ }
517
535
  async function targetState(connection) {
518
536
  const meta = await connection.execute(`select to_regclass('okm_meta') is not null
519
537
  or to_regclass('okm_history') is not null
@@ -3,7 +3,7 @@ import {
3
3
  readHandle,
4
4
  readCall,
5
5
  attachHttp
6
- } from "./bah9nbg3.js";
6
+ } from "./npdftanb.js";
7
7
  import {
8
8
  selectedColumns,
9
9
  parseOrder,
@@ -5,11 +5,11 @@ import {
5
5
  send2,
6
6
  reserve,
7
7
  park
8
- } from "./zbqbmmrp.js";
8
+ } from "./62b603gr.js";
9
9
  import {
10
10
  resetSession2,
11
11
  refuseWhenLost2
12
- } from "./7ghwamrf.js";
12
+ } from "./99qp9vtg.js";
13
13
  import {
14
14
  cursorStream
15
15
  } from "./7kms6fvj.js";
@@ -18,14 +18,14 @@ import {
18
18
  } from "./cnkky55j.js";
19
19
  import {
20
20
  noTimeout
21
- } from "./q0cqt2sp.js";
21
+ } from "./tr64w5p0.js";
22
22
  import {
23
23
  WireSession
24
- } from "./mtw6jz76.js";
24
+ } from "./e275q7sd.js";
25
25
  import {
26
26
  rejectClosed,
27
27
  runCall
28
- } from "./ae4j5f42.js";
28
+ } from "./mfvx6kjx.js";
29
29
 
30
30
  // src/adapters/pg/bunsql-extra.ts
31
31
  async function recover(sql, error, text, depth, clientRead, closedDuring, again) {
@@ -2,10 +2,10 @@ import {
2
2
  assertAuthorDrift2,
3
3
  catalogQuery2,
4
4
  managedRoleOptions2
5
- } from "./mkrn359n.js";
6
- import"./p3xbdcvt.js";
7
- import"./dpc2r7rb.js";
8
- import"./sjk86yrx.js";
5
+ } from "./90sg0w5a.js";
6
+ import"./myk8fswx.js";
7
+ import"./6nae0spm.js";
8
+ import"./fk9vef30.js";
9
9
  import"./12z7aznj.js";
10
10
  export {
11
11
  assertAuthorDrift2 as assertAuthorDrift,
@@ -6,7 +6,7 @@ import {
6
6
  runCall,
7
7
  EMPTY_NOTICES,
8
8
  resultFrom
9
- } from "./ae4j5f42.js";
9
+ } from "./mfvx6kjx.js";
10
10
 
11
11
  // src/adapters/pg/postgresjs.ts
12
12
  import net from "node:net";
@@ -118,17 +118,17 @@ function open2(config) {
118
118
  return sockets.occupy(() => runCall(closed, options, (watch) => root.query(text, params, watch)));
119
119
  },
120
120
  batch(statements, options) {
121
- return sockets.occupy(() => import("./z581d7ny.js").then((mod) => mod.runBatch(held, statements, options)));
121
+ return sockets.occupy(() => import("./fdsz3w80.js").then((mod) => mod.runBatch(held, statements, options)));
122
122
  },
123
123
  reserve() {
124
124
  const gate = sockets.busyGate();
125
125
  gate.enter();
126
- return import("./z581d7ny.js").then((mod) => mod.holdCheckout(gate, () => mod.checkout(held)), (error) => {
126
+ return import("./fdsz3w80.js").then((mod) => mod.holdCheckout(gate, () => mod.checkout(held)), (error) => {
127
127
  gate.leave();
128
128
  throw error;
129
129
  });
130
130
  },
131
- describe: (text, params) => sockets.occupy(() => import("./z581d7ny.js").then((mod) => mod.describe(sql, text, params))),
131
+ describe: (text, params) => sockets.occupy(() => import("./fdsz3w80.js").then((mod) => mod.describe(sql, text, params))),
132
132
  stream(text, params) {
133
133
  const gate = sockets.busyGate();
134
134
  return async function* () {
@@ -143,7 +143,7 @@ function open2(config) {
143
143
  listen(channel, onNotify) {
144
144
  const gate = sockets.listenerGate();
145
145
  gate.enter();
146
- return import("./z581d7ny.js").then((mod) => mod.holdListener(gate, async () => {
146
+ return import("./fdsz3w80.js").then((mod) => mod.holdListener(gate, async () => {
147
147
  const listening = await sql.listen(channel, onNotify);
148
148
  return async () => {
149
149
  await listening.unlisten();
@@ -213,7 +213,7 @@ class PgSession {
213
213
  onAbort();
214
214
  else
215
215
  watch.signal.addEventListener("abort", onAbort, { once: true });
216
- return import("./z581d7ny.js").then((mod) => mod.watchQuery(pending, watch, onAbort, {
216
+ return import("./fdsz3w80.js").then((mod) => mod.watchQuery(pending, watch, onAbort, {
217
217
  start,
218
218
  text,
219
219
  notices: this.notices,
@@ -265,7 +265,7 @@ class PgSession {
265
265
  }
266
266
  }
267
267
  async function* loadStream(sql, text, params) {
268
- const { stream } = await import("./z581d7ny.js");
268
+ const { stream } = await import("./fdsz3w80.js");
269
269
  yield* stream(sql, text, params);
270
270
  }
271
271
  function send(sql, text, params, named) {
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  withHttp,
9
9
  settleCall
10
- } from "./bah9nbg3.js";
10
+ } from "./npdftanb.js";
11
11
  import {
12
12
  rejectKeys,
13
13
  isRecord,
@@ -4,7 +4,7 @@ import {
4
4
  nextTransactionDepth,
5
5
  EMPTY_NOTICES,
6
6
  resultFrom
7
- } from "./xhrnjch9.js";
7
+ } from "./mfvx6kjx.js";
8
8
 
9
9
  // src/adapters/pg/session.ts
10
10
  function noticeBuffer() {
@@ -5,10 +5,10 @@ import {
5
5
  armDriverError,
6
6
  send,
7
7
  connectClient
8
- } from "./14x60fbf.js";
8
+ } from "./1mxm04fy.js";
9
9
  import {
10
10
  resetSession2
11
- } from "./7ghwamrf.js";
11
+ } from "./99qp9vtg.js";
12
12
  import {
13
13
  cursorStream
14
14
  } from "./7kms6fvj.js";
@@ -17,11 +17,11 @@ import {
17
17
  } from "./cnkky55j.js";
18
18
  import {
19
19
  WireSession
20
- } from "./mtw6jz76.js";
20
+ } from "./e275q7sd.js";
21
21
  import {
22
22
  rejectClosed,
23
23
  runCall
24
- } from "./ae4j5f42.js";
24
+ } from "./mfvx6kjx.js";
25
25
 
26
26
  // src/adapters/pg/nodepostgres-extra.ts
27
27
  async function checkout(held) {
@@ -7,8 +7,8 @@ import {
7
7
  holdCheckout2,
8
8
  holdListener2,
9
9
  watchQuery2
10
- } from "./wcrheftc.js";
11
- import"./35q0n9tz.js";
10
+ } from "./bphrgwz9.js";
11
+ import"./dd5pmnky.js";
12
12
  import"./cm3w0ywp.js";
13
13
  export {
14
14
  checkout2 as checkout,