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.
- package/README.md +23 -1
- package/dist/adapters/pg/bunsql-extra.d.ts +5 -5
- package/dist/adapters/pg/bunsql.d.ts +6 -2
- package/dist/adapters/pg/nodepostgres.d.ts +16 -1
- package/dist/adapters/pg/postgres-extra.d.ts +3 -17
- package/dist/adapters/pg/postgresjs.d.ts +2 -1
- package/dist/contracts/driver.d.ts +3 -2
- package/dist/contracts/error.d.ts +1 -1
- package/dist/dialects/pg/errors.d.ts +2 -0
- package/dist/dialects/pg/ext/btree-gin.d.ts +26 -0
- package/dist/dialects/pg/ext/btree-gin.js +20 -0
- package/dist/dialects/pg/ext/btree-gist.d.ts +26 -0
- package/dist/dialects/pg/ext/btree-gist.js +20 -0
- package/dist/dialects/pg/ext/call.d.ts +53 -0
- package/dist/dialects/pg/ext/citext.js +1 -1
- package/dist/dialects/pg/ext/feature.d.ts +26 -0
- package/dist/dialects/pg/ext/fuzzystrmatch.d.ts +34 -0
- package/dist/dialects/pg/ext/fuzzystrmatch.js +33 -0
- package/dist/dialects/pg/ext/hstore.d.ts +41 -0
- package/dist/dialects/pg/ext/hstore.js +29 -0
- package/dist/dialects/pg/ext/index.d.ts +56 -0
- package/dist/dialects/pg/ext/index.js +1 -1
- package/dist/dialects/pg/ext/ltree.d.ts +41 -0
- package/dist/dialects/pg/ext/ltree.js +29 -0
- package/dist/dialects/pg/ext/pg-trgm.js +4 -13
- package/dist/dialects/pg/ext/pgcrypto.d.ts +33 -0
- package/dist/dialects/pg/ext/pgcrypto.js +33 -0
- package/dist/dialects/pg/ext/unaccent.d.ts +26 -0
- package/dist/dialects/pg/ext/unaccent.js +21 -0
- package/dist/dialects/pg/ext/using.d.ts +23 -0
- package/dist/dialects/pg/ext/versions.d.ts +36 -0
- package/dist/dialects/pg/external.d.ts +19 -0
- package/dist/dialects/pg/filters.d.ts +2 -2
- package/dist/dialects/pg/fn/index.js +5 -5
- package/dist/dialects/pg/index.d.ts +1 -0
- package/dist/dialects/pg/index.js +19 -14
- package/dist/dialects/pg/introspect.d.ts +12 -0
- package/dist/dialects/pg/view/index.js +7 -7
- package/dist/dialects/pg/view/scratch.d.ts +4 -1
- package/dist/runtime/artifact-file.d.ts +22 -0
- package/dist/runtime/client.d.ts +10 -0
- package/dist/runtime/drift-detail.d.ts +2 -1
- package/dist/runtime/drift.d.ts +3 -10
- package/dist/runtime/param-limit.d.ts +20 -0
- package/dist/runtime/pg/bun.js +4 -4
- package/dist/runtime/pg/neon.js +4 -4
- package/dist/runtime/pg/pg.js +4 -4
- package/dist/runtime/pg/pglite.js +4 -4
- package/dist/runtime/pg/postgresjs.js +11 -11
- package/dist/runtime/server-check.d.ts +36 -6
- package/dist/runtime/tenancy/index.js +1 -1
- package/dist/runtime/traits/index.js +6 -6
- package/dist/runtime/validate/index.js +2 -2
- package/dist/runtime/write.d.ts +1 -1
- package/dist/shared/{4m6hskg8.js → 0j6qe91y.js} +4 -4
- package/dist/shared/{6m78c8ss.js → 1h5h1rf5.js} +1 -1
- package/dist/shared/{4vbf83xx.js → 2vcnpf0n.js} +1 -1
- package/dist/shared/{qd9hhd8f.js → 3ap5hxvj.js} +2 -1
- package/dist/shared/{v1wad97q.js → 3d7a80fq.js} +1 -1
- package/dist/shared/{wcrheftc.js → 3dr444ny.js} +58 -79
- package/dist/shared/{hm5f8jby.js → 3vvpcphd.js} +8 -7
- package/dist/shared/{760ppr76.js → 4a3mmhhe.js} +2 -2
- package/dist/shared/{mkrn359n.js → 4pkz5nvw.js} +222 -39
- package/dist/shared/{agsfb86s.js → 4te76xc5.js} +4 -4
- package/dist/shared/{63f4ksbz.js → 60y4ahmw.js} +1 -1
- package/dist/shared/61bmrmhr.js +35 -0
- package/dist/shared/{bxas03mq.js → 63qjmhnp.js} +100 -17
- package/dist/shared/{g5yc06ka.js → 67w3kn71.js} +1 -1
- package/dist/shared/{jgqj11w4.js → 6f0z3hzh.js} +4 -0
- package/dist/shared/{njga14v4.js → 6vfvsdkt.js} +10 -8
- package/dist/shared/{kj9d8maq.js → 6xqvesa5.js} +1 -1
- package/dist/shared/8gdbty5v.js +665 -0
- package/dist/shared/{pan0370z.js → 8ma6drzr.js} +211 -30
- package/dist/shared/{mnvjvqyp.js → 8p2bgye0.js} +124 -32
- package/dist/shared/{mfedzr74.js → 8qwqrxed.js} +14 -6
- package/dist/shared/{hfqmpasr.js → 8v7vzpgt.js} +11 -8
- package/dist/shared/{7ghwamrf.js → 99qp9vtg.js} +1 -1
- package/dist/shared/{zgex00fd.js → ak61ye1f.js} +5 -5
- package/dist/shared/{dpc2r7rb.js → bdekbvmt.js} +218 -95
- package/dist/shared/{jebgrkeq.js → bxjq6xqv.js} +2 -2
- package/dist/shared/c7dqd3gk.js +1806 -0
- package/dist/shared/ddh72ym5.js +20 -0
- package/dist/shared/e1c55v04.js +10 -0
- package/dist/shared/{mtw6jz76.js → e275q7sd.js} +1 -1
- package/dist/shared/{k86n8vq3.js → ekhq3ytz.js} +1 -1
- package/dist/shared/esy4dyxe.js +17 -0
- package/dist/shared/{gcefca6p.js → f9t9g54z.js} +22 -9
- package/dist/shared/{sjk86yrx.js → fk9vef30.js} +84 -73
- package/dist/shared/fkjne6gx.js +8 -0
- package/dist/shared/{e8zyaqvj.js → fne90dvz.js} +4 -1
- package/dist/shared/{needfe47.js → g89fmz5s.js} +1 -1
- package/dist/shared/{m4xff2a6.js → ghqzdp94.js} +2 -2
- package/dist/shared/{n0jmpgj1.js → gr9sn4za.js} +1 -1
- package/dist/shared/{5mtf6cj3.js → gzgfsspx.js} +5 -2
- package/dist/shared/h9811jjm.js +17 -0
- package/dist/shared/{z581d7ny.js → hgt69zjf.js} +2 -2
- package/dist/shared/{35q0n9tz.js → jvxcp1qk.js} +71 -87
- package/dist/shared/k73e8n9d.js +136 -0
- package/dist/shared/{195pzzzz.js → kzgrcy8s.js} +12 -8
- package/dist/shared/kzgrnckd.js +29 -0
- package/dist/shared/{p3xbdcvt.js → mz48rs74.js} +68 -8
- package/dist/shared/{zbqbmmrp.js → n6je5b28.js} +13 -26
- package/dist/shared/{b6d6p0zc.js → ns35jqz0.js} +75 -49
- package/dist/shared/{n05z9nwz.js → nstwgzn8.js} +1 -1
- package/dist/{tooling/shared/08kemxjd.js → shared/pgsak1yw.js} +1 -1
- package/dist/shared/py2zrrm6.js +451 -0
- package/dist/shared/{9dr2qnx7.js → qqm3ze6q.js} +1 -1
- package/dist/shared/{wvdjznah.js → rcjm0yn7.js} +31 -38
- package/dist/shared/rged92v6.js +17 -0
- package/dist/shared/{jp36k7dp.js → rw4tpcd0.js} +81 -51
- package/dist/shared/{bsek72fg.js → s5qe47a6.js} +3 -0
- package/dist/shared/{1d9q9cv2.js → smxzjz60.js} +2 -2
- package/dist/shared/{wz2a78mp.js → th5rnaxw.js} +1 -1
- package/dist/{tooling/shared/rs1jb051.js → shared/tr64w5p0.js} +1 -1
- package/dist/shared/{14x60fbf.js → tyqapcgk.js} +73 -10
- package/dist/shared/vsna85qf.js +8 -0
- package/dist/shared/{63qtkrca.js → vy47ryqa.js} +55 -5
- package/dist/shared/{jx2m62cs.js → wbdh9qbg.js} +7 -5
- package/dist/shared/{f4jy1j7x.js → wp7y8q3y.js} +946 -105
- package/dist/shared/{16kvjebh.js → xbd9xs6p.js} +7 -26
- package/dist/shared/{bah9nbg3.js → xbvz446k.js} +18 -23
- package/dist/shared/{p5nh3r8q.js → y6tfjk9q.js} +2 -2
- package/dist/shared/{3bb7wsqt.js → ycnft340.js} +1 -1
- package/dist/shared/{z7s6fpxv.js → ymenf259.js} +1 -1
- package/dist/shared/{0wrea3jq.js → ysdw2fg3.js} +10 -2
- package/dist/shared/zecrwdk9.js +61 -0
- package/dist/shared/{3t6kw83m.js → zm2rzqba.js} +2 -1
- package/dist/tooling/cli.js +200 -50
- package/dist/tooling/driver-run.js +109 -343
- package/dist/tooling/github/comment.d.ts +56 -0
- package/dist/tooling/github/post-comment.d.ts +17 -0
- package/dist/tooling/migrate/apply.d.ts +17 -2
- package/dist/tooling/migrate/commands.d.ts +2 -1
- package/dist/tooling/migrate/config.d.ts +13 -0
- package/dist/tooling/migrate/drift.d.ts +12 -0
- package/dist/tooling/migrate/driver-url.d.ts +17 -0
- package/dist/tooling/migrate/export.d.ts +165 -0
- package/dist/tooling/migrate/ext-surface.d.ts +80 -0
- package/dist/tooling/migrate/ext.d.ts +31 -4
- package/dist/tooling/migrate/import-drizzle.d.ts +40 -0
- package/dist/tooling/migrate/index.d.ts +3 -0
- package/dist/tooling/migrate/index.js +57 -10
- package/dist/tooling/migrate/lint-rules.d.ts +18 -1
- package/dist/tooling/migrate/lint.d.ts +14 -1
- package/dist/tooling/migrate/place.d.ts +18 -0
- package/dist/tooling/migrate/plan-json.d.ts +65 -0
- package/dist/tooling/migrate/policy.d.ts +17 -5
- package/dist/tooling/migrate/pooler-probe.d.ts +23 -0
- package/dist/tooling/migrate/project.d.ts +10 -1
- package/dist/tooling/migrate/pull-emit.d.ts +98 -0
- package/dist/tooling/migrate/pull-routines.d.ts +126 -0
- package/dist/tooling/migrate/pull-verify.d.ts +26 -0
- package/dist/tooling/migrate/pull.d.ts +65 -0
- package/dist/tooling/migrate/reprint.d.ts +32 -0
- package/dist/tooling/migrate/runner.d.ts +24 -1
- package/dist/tooling/migrate/sandbox.d.ts +8 -2
- package/dist/tooling/migrate/schema-api.d.ts +43 -0
- package/dist/tooling/migrate/sql-lex.d.ts +18 -0
- package/dist/tooling/shared/{ppnnnvj8.js → 09a6vsys.js} +1 -1
- package/dist/tooling/shared/{7ae7rjmn.js → 0v9ptnxp.js} +8 -8
- package/dist/tooling/shared/{fb9k2qwd.js → 0wtzps9p.js} +11 -30
- package/dist/tooling/shared/{a6pp9d12.js → 0yhf1db4.js} +6 -6
- package/dist/tooling/shared/{dy672fz6.js → 19msgrsc.js} +2 -2
- package/dist/{shared/q0cqt2sp.js → tooling/shared/1fwfm5m3.js} +1 -1
- package/dist/tooling/shared/{f9mphxej.js → 2jdn09e2.js} +401 -24
- package/dist/tooling/shared/{jne7b93p.js → 2qrte2ct.js} +5 -5
- package/dist/tooling/shared/{5bvw2nev.js → 2v4nwnkb.js} +1 -1
- package/dist/tooling/shared/{spk1jg3r.js → 33z39trp.js} +106 -23
- package/dist/tooling/shared/{z8d7ptht.js → 353vnw9z.js} +5 -5
- package/dist/tooling/shared/{dw08f3m8.js → 390kry9g.js} +2 -2
- package/dist/tooling/shared/{xjs6zqtc.js → 3f6etb9z.js} +18 -31
- package/dist/{shared/bnby0esn.js → tooling/shared/3t2cqmsx.js} +1 -1
- package/dist/tooling/shared/{wwnekq5n.js → 4dzvjtpy.js} +1 -1
- package/dist/tooling/shared/{y5656f0e.js → 4ec0nxvw.js} +10 -10
- package/dist/tooling/shared/{3m1hkg7z.js → 4tg2bn41.js} +59 -78
- package/dist/tooling/shared/{zvnhh1n0.js → 5rah55z0.js} +2 -2
- package/dist/tooling/shared/{pqy21k24.js → 804w1t69.js} +4 -4
- package/dist/tooling/shared/8g0m0rvd.js +134 -0
- package/dist/tooling/shared/8msbtw5s.js +8 -0
- package/dist/tooling/shared/{4d2w25vw.js → 8t22h3h7.js} +2 -2
- package/dist/tooling/shared/{smn6kz1p.js → 91c59b7b.js} +2 -2
- package/dist/tooling/shared/{aftb2mwr.js → adk9k6va.js} +1 -1
- package/dist/tooling/shared/{j9t5s12a.js → ajjd5cwz.js} +2 -2
- package/dist/tooling/shared/{cmptmb4f.js → angjck01.js} +1 -1
- package/dist/tooling/shared/{yw30vnq2.js → asnnc3v5.js} +1 -1
- package/dist/tooling/shared/{ma2340rx.js → bj1kyqc8.js} +2 -2
- package/dist/tooling/shared/{2wtvc7rw.js → bt3tjemb.js} +11 -3
- package/dist/tooling/shared/{ec71zqgt.js → chk2bh4f.js} +2 -2
- package/dist/tooling/shared/{gmcf9cxf.js → ckq4z5ax.js} +5 -2
- package/dist/tooling/shared/{w7qe8sj1.js → d3rhb24q.js} +1 -1
- package/dist/tooling/shared/{y031jct9.js → d8q00vxg.js} +4 -4
- package/dist/tooling/shared/{vs0t6qt8.js → dx188rxs.js} +2 -2
- package/dist/tooling/shared/{g9ad4n80.js → efq6p9df.js} +35 -42
- package/dist/tooling/shared/{ddjtfgnx.js → en6rwzq0.js} +3 -3
- package/dist/tooling/shared/{6nyfyw70.js → f2r5g0fs.js} +2 -2
- package/dist/tooling/shared/{03k6res6.js → f4gep0nk.js} +1 -1
- package/dist/tooling/shared/{gfvtj6d0.js → f8a010fm.js} +13 -11
- package/dist/tooling/shared/{3tq8pnb8.js → fdsek6pa.js} +1 -1
- package/dist/tooling/shared/fvmrxsd1.js +8 -0
- package/dist/tooling/shared/{733a1tq3.js → g3xybeqf.js} +4 -3
- package/dist/tooling/shared/{pwsytxm5.js → gefmpwsa.js} +1 -1
- package/dist/tooling/shared/{mtrqn2hn.js → gjj71hfh.js} +25 -30
- package/dist/tooling/shared/{8sqrsw3s.js → jgzt69pa.js} +5 -5
- package/dist/tooling/shared/{nf7jmhfa.js → jm30k2ca.js} +10 -8
- package/dist/tooling/shared/{vx86qjv8.js → kayqzpbk.js} +6 -3
- package/dist/tooling/shared/{zhwnfyb2.js → kvw1672d.js} +1 -1
- package/dist/tooling/shared/{rq5kk8j6.js → mr1kcgpw.js} +3 -3
- package/dist/tooling/shared/{72fyg4zv.js → mwbdf409.js} +1 -1
- package/dist/tooling/shared/{wt7j7nf6.js → ns9207v3.js} +1 -1
- package/dist/tooling/shared/{9xzm7hjg.js → p6tjv97k.js} +3 -3
- package/dist/tooling/shared/{yfr8hzhm.js → p73evwf0.js} +1 -1
- package/dist/tooling/shared/{dzx85q70.js → phc1nc4g.js} +1 -1
- package/dist/tooling/shared/{417zdsk7.js → ppybjw50.js} +79 -16
- package/dist/tooling/shared/{yk9mp7vb.js → qdrn8ghn.js} +5 -4
- package/dist/tooling/shared/rd8h01ta.js +20 -0
- package/dist/tooling/shared/{bz2dqhab.js → rwg8y90m.js} +3 -3
- package/dist/tooling/shared/{xhrnjch9.js → ry2f3w8p.js} +3 -3
- package/dist/tooling/shared/{a7q7t4n3.js → ryc5sa58.js} +8 -8
- package/dist/tooling/shared/{2revefqt.js → ss87qxwv.js} +2 -2
- package/dist/tooling/shared/{rf83gr2d.js → vg68k11z.js} +7 -3
- package/dist/tooling/shared/{p7f08ktn.js → vms9dta5.js} +73 -89
- package/dist/tooling/shared/{3rrw5w8f.js → xchpnbdv.js} +1 -1
- package/dist/tooling/shared/{djydjpqt.js → xn6p01fh.js} +5 -5
- package/dist/tooling/shared/{9kazs5p6.js → xwr6q618.js} +3 -3
- package/dist/tooling/shared/{ep8zh3bk.js → xx3gmq94.js} +1 -1
- package/dist/tooling/shared/{tn8gay14.js → y2bd7yfx.js} +21 -13
- package/dist/tooling/shared/{vraj6d74.js → y4gq9rbe.js} +11 -11
- package/dist/tooling/shared/y4vwft92.js +9 -0
- package/dist/tooling/shared/{345tbc2k.js → yz68xcmc.js} +1 -1
- package/dist/tooling/testing/factories.d.ts +1 -3
- package/dist/tooling/testing/index.js +2 -2
- package/package.json +39 -9
- package/dist/shared/3449rcae.js +0 -14
- package/dist/shared/fjpnhqan.js +0 -71
- package/dist/shared/n41w4fbz.js +0 -113
- package/dist/tooling/shared/pw8fgahx.js +0 -69
- /package/dist/shared/{ae4j5f42.js → mfvx6kjx.js} +0 -0
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
runCall,
|
|
7
7
|
EMPTY_NOTICES,
|
|
8
8
|
resultFrom
|
|
9
|
-
} from "./
|
|
9
|
+
} from "./mfvx6kjx.js";
|
|
10
10
|
|
|
11
11
|
// src/adapters/pg/postgresjs.ts
|
|
12
12
|
import net from "node:net";
|
|
@@ -36,41 +36,29 @@ class PoolSockets {
|
|
|
36
36
|
this.park();
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
gate(key) {
|
|
40
40
|
return {
|
|
41
41
|
enter: () => {
|
|
42
|
-
this
|
|
42
|
+
this[key] += 1;
|
|
43
43
|
this.wake();
|
|
44
44
|
},
|
|
45
45
|
leave: () => {
|
|
46
|
-
this
|
|
47
|
-
this.park();
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
listenerGate() {
|
|
52
|
-
return {
|
|
53
|
-
enter: () => {
|
|
54
|
-
this.listeners += 1;
|
|
55
|
-
this.wake();
|
|
56
|
-
},
|
|
57
|
-
leave: () => {
|
|
58
|
-
this.listeners -= 1;
|
|
46
|
+
this[key] -= 1;
|
|
59
47
|
this.park();
|
|
60
48
|
}
|
|
61
49
|
};
|
|
62
50
|
}
|
|
63
51
|
wake() {
|
|
64
|
-
for (const
|
|
65
|
-
if (
|
|
66
|
-
|
|
52
|
+
for (const s of this.held)
|
|
53
|
+
if (s.writable)
|
|
54
|
+
s.ref();
|
|
67
55
|
}
|
|
68
56
|
park() {
|
|
69
57
|
if (this.busy > 0 || this.listeners > 0)
|
|
70
58
|
return;
|
|
71
|
-
for (const
|
|
72
|
-
if (
|
|
73
|
-
|
|
59
|
+
for (const s of this.held)
|
|
60
|
+
if (s.writable)
|
|
61
|
+
s.unref();
|
|
74
62
|
}
|
|
75
63
|
}
|
|
76
64
|
function driverOptions(config, state) {
|
|
@@ -80,6 +68,7 @@ function driverOptions(config, state) {
|
|
|
80
68
|
idle_timeout: state.plain ? 0 : 30,
|
|
81
69
|
...state.plain ? { max_lifetime: null } : {},
|
|
82
70
|
connect_timeout: 5,
|
|
71
|
+
backoff: () => 0.05 + Math.random() * 0.2,
|
|
83
72
|
types: WIRE_TYPES,
|
|
84
73
|
...state.plain ? { socket: (options) => state.sockets.connect(options) } : {},
|
|
85
74
|
...config.ssl !== undefined ? { ssl: config.ssl } : {},
|
|
@@ -92,9 +81,24 @@ function driverOptions(config, state) {
|
|
|
92
81
|
}
|
|
93
82
|
};
|
|
94
83
|
}
|
|
84
|
+
var lives = [];
|
|
85
|
+
process.on("uncaughtException", (e) => {
|
|
86
|
+
if (e instanceof TypeError && /socket\.write|reading 'write'/.test(e.message)) {
|
|
87
|
+
for (const x of lives) {
|
|
88
|
+
if (!x.on)
|
|
89
|
+
continue;
|
|
90
|
+
const prev = x.sql;
|
|
91
|
+
x.m();
|
|
92
|
+
prev.end({ timeout: 0 }).catch(() => {});
|
|
93
|
+
}
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
console.error(e);
|
|
97
|
+
process.exitCode = 1;
|
|
98
|
+
});
|
|
95
99
|
function open2(config) {
|
|
96
100
|
const max = config.max ?? 10;
|
|
97
|
-
const acquireMs = config.timeouts?.acquire;
|
|
101
|
+
const acquireMs = config.timeouts?.acquire ?? 1e4;
|
|
98
102
|
const counters = { reserved: 0, busy: 0, reservedBusy: 0, waiting: 0 };
|
|
99
103
|
const poolInflight = new Set;
|
|
100
104
|
const notices = noticeBuffer();
|
|
@@ -103,48 +107,56 @@ function open2(config) {
|
|
|
103
107
|
const named = config.prepared === "named";
|
|
104
108
|
const plain = config.ssl === undefined;
|
|
105
109
|
const sockets = new PoolSockets;
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
const opts = { max, named, plain, notices, sockets };
|
|
111
|
+
const make = () => postgres(config.url, driverOptions(config, opts));
|
|
112
|
+
const root = new PgSession(make(), counters, "pool", poolInflight, isClosed, undefined, notices, named);
|
|
113
|
+
const held = {
|
|
114
|
+
on: true,
|
|
115
|
+
m: () => root.sql = make(),
|
|
116
|
+
get sql() {
|
|
117
|
+
return root.sql;
|
|
118
|
+
},
|
|
119
|
+
acquireMs,
|
|
120
|
+
counters,
|
|
121
|
+
isClosed,
|
|
110
122
|
notices,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
123
|
+
named,
|
|
124
|
+
poolInflight
|
|
125
|
+
};
|
|
126
|
+
lives.push(held);
|
|
115
127
|
return {
|
|
116
128
|
capabilities: POSTGRESJS_CAPABILITIES,
|
|
117
129
|
execute(text, params, options) {
|
|
118
130
|
return sockets.occupy(() => runCall(closed, options, (watch) => root.query(text, params, watch)));
|
|
119
131
|
},
|
|
120
132
|
batch(statements, options) {
|
|
121
|
-
return sockets.occupy(() => import("./
|
|
133
|
+
return sockets.occupy(() => import("./hgt69zjf.js").then((mod) => mod.runBatch(held, statements, options)));
|
|
122
134
|
},
|
|
123
135
|
reserve() {
|
|
124
|
-
const gate = sockets.
|
|
136
|
+
const gate = sockets.gate("busy");
|
|
125
137
|
gate.enter();
|
|
126
|
-
return import("./
|
|
138
|
+
return import("./hgt69zjf.js").then((mod) => mod.holdCheckout(gate, () => mod.checkout(held)), (error) => {
|
|
127
139
|
gate.leave();
|
|
128
140
|
throw error;
|
|
129
141
|
});
|
|
130
142
|
},
|
|
131
|
-
describe: (text, params) => sockets.occupy(() => import("./
|
|
143
|
+
describe: (text, params) => sockets.occupy(() => import("./hgt69zjf.js").then((mod) => mod.describe(root.sql, text, params))),
|
|
132
144
|
stream(text, params) {
|
|
133
|
-
const gate = sockets.
|
|
145
|
+
const gate = sockets.gate("busy");
|
|
134
146
|
return async function* () {
|
|
135
147
|
gate.enter();
|
|
136
148
|
try {
|
|
137
|
-
yield*
|
|
149
|
+
yield* (await import("./hgt69zjf.js")).stream(root.sql, text, params);
|
|
138
150
|
} finally {
|
|
139
151
|
gate.leave();
|
|
140
152
|
}
|
|
141
153
|
}();
|
|
142
154
|
},
|
|
143
155
|
listen(channel, onNotify) {
|
|
144
|
-
const gate = sockets.
|
|
156
|
+
const gate = sockets.gate("listeners");
|
|
145
157
|
gate.enter();
|
|
146
|
-
return import("./
|
|
147
|
-
const listening = await sql.listen(channel, onNotify);
|
|
158
|
+
return import("./hgt69zjf.js").then((mod) => mod.holdListener(gate, async () => {
|
|
159
|
+
const listening = await root.sql.listen(channel, onNotify);
|
|
148
160
|
return async () => {
|
|
149
161
|
await listening.unlisten();
|
|
150
162
|
};
|
|
@@ -160,7 +172,8 @@ function open2(config) {
|
|
|
160
172
|
stats: () => statsOf(counters, max),
|
|
161
173
|
async close() {
|
|
162
174
|
closed = true;
|
|
163
|
-
|
|
175
|
+
held.on = false;
|
|
176
|
+
await root.sql.end({ timeout: 5 });
|
|
164
177
|
}
|
|
165
178
|
};
|
|
166
179
|
}
|
|
@@ -213,7 +226,7 @@ class PgSession {
|
|
|
213
226
|
onAbort();
|
|
214
227
|
else
|
|
215
228
|
watch.signal.addEventListener("abort", onAbort, { once: true });
|
|
216
|
-
return import("./
|
|
229
|
+
return import("./hgt69zjf.js").then((mod) => mod.watchQuery(pending, watch, onAbort, {
|
|
217
230
|
start,
|
|
218
231
|
text,
|
|
219
232
|
notices: this.notices,
|
|
@@ -252,67 +265,38 @@ class PgSession {
|
|
|
252
265
|
this.transactionDepth = nextTransactionDepth(this.transactionDepth, text);
|
|
253
266
|
}
|
|
254
267
|
enter() {
|
|
255
|
-
|
|
256
|
-
this.counters.busy += 1;
|
|
257
|
-
else
|
|
258
|
-
this.counters.reservedBusy += 1;
|
|
268
|
+
this.counters[this.scope === "pool" ? "busy" : "reservedBusy"] += 1;
|
|
259
269
|
}
|
|
260
270
|
leave() {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
else
|
|
264
|
-
this.counters.reservedBusy = Math.max(0, this.counters.reservedBusy - 1);
|
|
271
|
+
const k = this.scope === "pool" ? "busy" : "reservedBusy";
|
|
272
|
+
this.counters[k] = Math.max(0, this.counters[k] - 1);
|
|
265
273
|
}
|
|
266
274
|
}
|
|
267
|
-
async function* loadStream(sql, text, params) {
|
|
268
|
-
const { stream } = await import("./z581d7ny.js");
|
|
269
|
-
yield* stream(sql, text, params);
|
|
270
|
-
}
|
|
271
275
|
function send(sql, text, params, named) {
|
|
272
|
-
|
|
273
|
-
return sql.unsafe(text).raw();
|
|
274
|
-
return sql.unsafe(text, asParams(params), { prepare: named }).raw();
|
|
275
|
-
}
|
|
276
|
-
function asParams(params) {
|
|
277
|
-
if (params === undefined)
|
|
278
|
-
return [];
|
|
279
|
-
return params;
|
|
280
|
-
}
|
|
281
|
-
function statsOf(counters, size) {
|
|
282
|
-
return {
|
|
283
|
-
size,
|
|
284
|
-
idle: Math.max(0, size - counters.reserved - counters.busy),
|
|
285
|
-
inflight: counters.busy + counters.reservedBusy,
|
|
286
|
-
waiting: counters.waiting
|
|
287
|
-
};
|
|
276
|
+
return !named && (params === undefined || params.length === 0) ? sql.unsafe(text).raw() : sql.unsafe(text, asParams(params), { prepare: named }).raw();
|
|
288
277
|
}
|
|
278
|
+
var asParams = (params) => params ?? [];
|
|
279
|
+
var statsOf = (c, size) => ({
|
|
280
|
+
size,
|
|
281
|
+
idle: Math.max(0, size - c.reserved - c.busy),
|
|
282
|
+
inflight: c.busy + c.reservedBusy,
|
|
283
|
+
waiting: c.waiting
|
|
284
|
+
});
|
|
289
285
|
function noticeBuffer() {
|
|
290
286
|
let notices;
|
|
291
287
|
return {
|
|
292
288
|
push(notice) {
|
|
293
289
|
const severity = typeof notice.severity === "string" ? notice.severity : "";
|
|
294
290
|
const message = typeof notice.message === "string" ? notice.message : "";
|
|
295
|
-
const code = typeof notice.code === "string" && notice.code
|
|
296
|
-
|
|
297
|
-
(notices ??= []).push(entry);
|
|
298
|
-
},
|
|
299
|
-
start() {
|
|
300
|
-
return notices?.length ?? 0;
|
|
291
|
+
const code = typeof notice.code === "string" && notice.code ? notice.code : undefined;
|
|
292
|
+
(notices ??= []).push(code ? { severity, message, code } : { severity, message });
|
|
301
293
|
},
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
return EMPTY_NOTICES;
|
|
305
|
-
return notices.slice(start);
|
|
306
|
-
}
|
|
294
|
+
start: () => notices?.length ?? 0,
|
|
295
|
+
since: (start) => notices === undefined || notices.length === start ? EMPTY_NOTICES : notices.slice(start)
|
|
307
296
|
};
|
|
308
297
|
}
|
|
309
298
|
function wire(to, from) {
|
|
310
|
-
return {
|
|
311
|
-
to,
|
|
312
|
-
from: [...from],
|
|
313
|
-
serialize: (value) => value,
|
|
314
|
-
parse: (value) => value
|
|
315
|
-
};
|
|
299
|
+
return { to, from, serialize: String, parse: String };
|
|
316
300
|
}
|
|
317
301
|
var WIRE_TYPES = {
|
|
318
302
|
number: wire(0, [21, 23, 26, 700, 701]),
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import {
|
|
2
|
+
POSTGRES_FLOOR,
|
|
3
|
+
isPostgresMajor,
|
|
4
|
+
parsePostgresFloor,
|
|
5
|
+
serverNeedsPostgres
|
|
6
|
+
} from "./ga9j92qj.js";
|
|
7
|
+
import {
|
|
8
|
+
withHttp,
|
|
9
|
+
attachHttp,
|
|
10
|
+
mapOptions
|
|
11
|
+
} from "./xbvz446k.js";
|
|
12
|
+
import {
|
|
13
|
+
OkmError2
|
|
14
|
+
} from "./52szzakm.js";
|
|
15
|
+
|
|
16
|
+
// src/runtime/artifact-file.ts
|
|
17
|
+
function artifactDir(catalogDir) {
|
|
18
|
+
if (catalogDir !== undefined)
|
|
19
|
+
return catalogDir.replace(/[/\\]+$/, "");
|
|
20
|
+
const cwd = globalThis.process?.cwd?.() ?? ".";
|
|
21
|
+
return `${cwd}/.okm`;
|
|
22
|
+
}
|
|
23
|
+
async function readText(path) {
|
|
24
|
+
const bun = globalThis.Bun;
|
|
25
|
+
if (bun !== undefined) {
|
|
26
|
+
const file = bun.file(path);
|
|
27
|
+
if (!await file.exists())
|
|
28
|
+
return;
|
|
29
|
+
return file.text();
|
|
30
|
+
}
|
|
31
|
+
const loader = globalThis.process?.getBuiltinModule;
|
|
32
|
+
if (loader === undefined)
|
|
33
|
+
return;
|
|
34
|
+
try {
|
|
35
|
+
return await loader("node:fs/promises").readFile(path, "utf8");
|
|
36
|
+
} catch {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/runtime/server-check.ts
|
|
42
|
+
var versionQuery = "select current_setting('server_version_num'), version(), (select (xpath('//catalog_hash/text()', query_to_xml('select catalog_hash from okm_meta where id = ''head''', true, false, '')))[1]::text where to_regclass('okm_meta') is not null)";
|
|
43
|
+
var historyQuery = "select migration_id, class, catalog_hash from okm_history order by migration_id, step_index";
|
|
44
|
+
async function versionSql(namespace) {
|
|
45
|
+
if (namespace === "public")
|
|
46
|
+
return versionQuery;
|
|
47
|
+
const relation = await qualified("okm_meta", namespace);
|
|
48
|
+
const literal = relation.replaceAll("'", "''");
|
|
49
|
+
return `select current_setting('server_version_num'), version(), (select (xpath('//catalog_hash/text()', query_to_xml('select catalog_hash from ${literal} where id = ''head''', true, false, '')))[1]::text where to_regclass('${literal}') is not null)`;
|
|
50
|
+
}
|
|
51
|
+
async function historySql2(namespace) {
|
|
52
|
+
if (namespace === "public")
|
|
53
|
+
return historyQuery;
|
|
54
|
+
return `select migration_id, class, catalog_hash from ${await qualified("okm_history", namespace)} order by migration_id, step_index`;
|
|
55
|
+
}
|
|
56
|
+
async function recordedNamespace(catalogDir) {
|
|
57
|
+
const text = await readText(`${artifactDir(catalogDir)}/namespace`);
|
|
58
|
+
if (text === undefined)
|
|
59
|
+
return "public";
|
|
60
|
+
const line = text.trim();
|
|
61
|
+
if (line === "" || line === "public")
|
|
62
|
+
return "public";
|
|
63
|
+
if (line.includes("\x00") || line.includes(`
|
|
64
|
+
`) || line.includes("\r")) {
|
|
65
|
+
throw new OkmError2("OKM1122", "The catalog namespace file is not one identifier.", {
|
|
66
|
+
fix: { summary: "Run okm build so .okm/namespace is the schema from defineConfig." }
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return line;
|
|
70
|
+
}
|
|
71
|
+
async function acceptServer2(pool, schema, http, requireMeta, options, source) {
|
|
72
|
+
const namespace = await recordedNamespace(source.catalogDir);
|
|
73
|
+
let rows;
|
|
74
|
+
try {
|
|
75
|
+
const result = await pool.execute(await versionSql(namespace), undefined, options);
|
|
76
|
+
rows = result.rows;
|
|
77
|
+
} catch (error) {
|
|
78
|
+
const { mapPostgresError } = await import("./vy47ryqa.js");
|
|
79
|
+
throw mapPostgresError(error, mapOptions(http, false, schema));
|
|
80
|
+
}
|
|
81
|
+
for (const name in schema.model) {
|
|
82
|
+
if (schema.model[name]?.presets !== undefined) {
|
|
83
|
+
(await import("./m7n9h2a5.js")).checkSchema(schema);
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const version = rows[0]?.[1];
|
|
88
|
+
if (version === null || version === undefined || !version.startsWith("PostgreSQL")) {
|
|
89
|
+
throw new OkmError2("OKM1801", "The server is not PostgreSQL. The schema dialect is postgres.", withHttp(http, {
|
|
90
|
+
fix: { summary: "Open the schema with the Postgres driver that matches it." }
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
const recorded = rows[0]?.[2];
|
|
94
|
+
if (recorded === null || recorded === undefined || recorded.length === 0) {
|
|
95
|
+
if (requireMeta) {
|
|
96
|
+
throw new OkmError2("OKM1520", "okm_meta has no catalog hash.", withHttp(http, {
|
|
97
|
+
fix: {
|
|
98
|
+
summary: "Apply migrations so okm_meta records the catalog, or omit requireMeta to adopt this database."
|
|
99
|
+
}
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
const { assertCompatible } = await import("./xbd9xs6p.js");
|
|
104
|
+
try {
|
|
105
|
+
await assertCompatible(pool, schema, recorded, source, options, namespace);
|
|
106
|
+
} catch (error) {
|
|
107
|
+
if (error instanceof OkmError2)
|
|
108
|
+
throw attachHttp(http, error);
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const major = Math.floor(Number(rows[0]?.[0] ?? "0") / 1e4);
|
|
113
|
+
const raw = schema.requires?.postgres;
|
|
114
|
+
if (raw === undefined) {
|
|
115
|
+
if (major < POSTGRES_FLOOR) {
|
|
116
|
+
throw new OkmError2("OKM1803", serverNeedsPostgres(major, POSTGRES_FLOOR), withHttp(http, {
|
|
117
|
+
fix: {
|
|
118
|
+
summary: `Upgrade to PostgreSQL ${String(POSTGRES_FLOOR)} or higher.`
|
|
119
|
+
}
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const need = parsePostgresFloor(raw);
|
|
125
|
+
if (!isPostgresMajor(need) || major < need) {
|
|
126
|
+
throw new OkmError2("OKM1802", serverNeedsPostgres(major, isPostgresMajor(need) ? need : POSTGRES_FLOOR), withHttp(http, {
|
|
127
|
+
fix: { summary: "Upgrade the server, or lower minPostgres to a major the server meets." }
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async function qualified(table, namespace) {
|
|
132
|
+
const { quoteIdent } = await import("./61bmrmhr.js");
|
|
133
|
+
return `${quoteIdent(namespace)}.${table}`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export { artifactDir, readText, historySql2, acceptServer2 };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
open2
|
|
3
|
-
} from "./
|
|
3
|
+
} from "./jvxcp1qk.js";
|
|
4
4
|
import"./12z7aznj.js";
|
|
5
|
+
import"./fk9vef30.js";
|
|
5
6
|
import"./n442h54c.js";
|
|
6
7
|
import {
|
|
7
8
|
CURRENT,
|
|
@@ -14,21 +15,22 @@ import {
|
|
|
14
15
|
import {
|
|
15
16
|
expandProvisioned,
|
|
16
17
|
provisionHistoryIsKnown
|
|
17
|
-
} from "./
|
|
18
|
-
import"./
|
|
19
|
-
import"./
|
|
18
|
+
} from "./8p2bgye0.js";
|
|
19
|
+
import"./6xqvesa5.js";
|
|
20
|
+
import"./mz48rs74.js";
|
|
20
21
|
import {
|
|
21
22
|
projectPath,
|
|
23
|
+
catalogNamespace,
|
|
22
24
|
loadMigrations,
|
|
23
25
|
loadConfig
|
|
24
|
-
} from "./
|
|
26
|
+
} from "./wp7y8q3y.js";
|
|
25
27
|
import {
|
|
28
|
+
driverUrl,
|
|
26
29
|
sessionFailure,
|
|
27
30
|
finishQuiet,
|
|
28
31
|
assertTargetPolicy,
|
|
29
32
|
listTargets
|
|
30
|
-
} from "./
|
|
31
|
-
import"./sjk86yrx.js";
|
|
33
|
+
} from "./bdekbvmt.js";
|
|
32
34
|
import {
|
|
33
35
|
OkmError2
|
|
34
36
|
} from "./52szzakm.js";
|
|
@@ -82,7 +84,7 @@ function describeStatus(migrations, history, recorded) {
|
|
|
82
84
|
async function readTargetStatus(input) {
|
|
83
85
|
assertTargetPolicy({ name: input.target, protected: input.protected }, "status");
|
|
84
86
|
const pool = open2({
|
|
85
|
-
url: input.url,
|
|
87
|
+
url: driverUrl(input.url),
|
|
86
88
|
max: 1,
|
|
87
89
|
...input.searchPath !== undefined ? { searchPath: input.searchPath } : {}
|
|
88
90
|
});
|
|
@@ -109,6 +111,7 @@ async function readTargetStatus(input) {
|
|
|
109
111
|
}
|
|
110
112
|
async function statusProject(cwd, flags) {
|
|
111
113
|
const config = await loadConfig(cwd);
|
|
114
|
+
const namespace = catalogNamespace(config);
|
|
112
115
|
const targets = chosen(listTargets(config), flags.target);
|
|
113
116
|
const migrations = loadMigrations(projectPath(cwd, config.migrations ?? "migrations"));
|
|
114
117
|
const rows = [];
|
|
@@ -117,6 +120,7 @@ async function statusProject(cwd, flags) {
|
|
|
117
120
|
url: target.url,
|
|
118
121
|
target: target.name,
|
|
119
122
|
protected: target.protected,
|
|
123
|
+
...namespace === "public" ? {} : { searchPath: namespace },
|
|
120
124
|
migrations
|
|
121
125
|
}));
|
|
122
126
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isExactVersion,
|
|
3
|
+
compareExtensionVersions
|
|
4
|
+
} from "./r3j8s5y0.js";
|
|
5
|
+
import {
|
|
6
|
+
OkmError2
|
|
7
|
+
} from "./52szzakm.js";
|
|
8
|
+
|
|
9
|
+
// src/dialects/pg/ext/feature.ts
|
|
10
|
+
function assertExtFeature(declared, feature, need) {
|
|
11
|
+
if (declared === undefined)
|
|
12
|
+
return;
|
|
13
|
+
if (pinAllows(declared, need.extension))
|
|
14
|
+
return;
|
|
15
|
+
throw new OkmError2("OKM1812", `${feature} needs ${need.name} ${need.extension} or higher and PostgreSQL ${String(need.postgres)}. minPostgres: ${String(need.postgres)}. The declaration allows ${declared}.`, {
|
|
16
|
+
fix: {
|
|
17
|
+
summary: `Raise the ${need.name} pin to ${need.extension} or higher, and set minPostgres to ${String(need.postgres)}.`
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function pinAllows(declared, minimum) {
|
|
22
|
+
const floor = /^>=(\d+(?:\.\d+)*)$/.exec(declared);
|
|
23
|
+
const pinned = floor?.[1] ?? declared;
|
|
24
|
+
if (!isExactVersion(pinned))
|
|
25
|
+
return false;
|
|
26
|
+
return compareExtensionVersions(pinned, minimum) >= 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { assertExtFeature };
|
|
@@ -10,11 +10,11 @@ import {
|
|
|
10
10
|
materializedViewIndex
|
|
11
11
|
} from "./12z7aznj.js";
|
|
12
12
|
import {
|
|
13
|
-
|
|
14
|
-
} from "./
|
|
13
|
+
quoteIdent2
|
|
14
|
+
} from "./fk9vef30.js";
|
|
15
15
|
import {
|
|
16
|
-
|
|
17
|
-
} from "./
|
|
16
|
+
columnPrivilege
|
|
17
|
+
} from "./bdekbvmt.js";
|
|
18
18
|
import {
|
|
19
19
|
policyObject
|
|
20
20
|
} from "./bdk4sty6.js";
|
|
@@ -265,7 +265,10 @@ async function introspectSchema(runner, concrete, logical = "public", options) {
|
|
|
265
265
|
...expression.length > 0 ? { expression } : {},
|
|
266
266
|
...refTable.length > 0 ? {
|
|
267
267
|
references: {
|
|
268
|
-
parent: {
|
|
268
|
+
parent: {
|
|
269
|
+
namespace: referencedNamespace(text(row, "ref_schema"), concrete, namespace),
|
|
270
|
+
name: refTable
|
|
271
|
+
},
|
|
269
272
|
columns: refColumns,
|
|
270
273
|
...onDelete !== undefined ? { onDelete } : {},
|
|
271
274
|
...onUpdate !== undefined ? { onUpdate } : {}
|
|
@@ -370,7 +373,7 @@ async function introspectSchema(runner, concrete, logical = "public", options) {
|
|
|
370
373
|
events: triggerEvents(bits),
|
|
371
374
|
level: (bits & 1) === 1 ? "row" : "statement",
|
|
372
375
|
calls: {
|
|
373
|
-
namespace:
|
|
376
|
+
namespace: referencedNamespace(text(row, "function_schema"), concrete, namespace),
|
|
374
377
|
name: text(row, "function"),
|
|
375
378
|
argTypes
|
|
376
379
|
},
|
|
@@ -446,8 +449,38 @@ async function introspectSchema(runner, concrete, logical = "public", options) {
|
|
|
446
449
|
if (options?.managedRoles !== undefined) {
|
|
447
450
|
objects.push(...await readPrivileges(runner, concrete, logical, namespace, provenance, objects, options.managedRoles, options.reportingRole));
|
|
448
451
|
}
|
|
452
|
+
await includeOutsideReferences(runner, logical, provenance, objects);
|
|
449
453
|
return catalog(objects);
|
|
450
454
|
}
|
|
455
|
+
async function includeOutsideReferences(runner, logical, provenance, objects) {
|
|
456
|
+
const wanted = new Map;
|
|
457
|
+
for (const object of objects) {
|
|
458
|
+
if (object.kind !== "constraint" || object.definition.references === undefined)
|
|
459
|
+
continue;
|
|
460
|
+
const parent = object.definition.references.parent;
|
|
461
|
+
if (parent.namespace.form !== "static" || parent.namespace.name === logical)
|
|
462
|
+
continue;
|
|
463
|
+
wanted.set(`${parent.namespace.name}.${parent.name}`, {
|
|
464
|
+
schema: parent.namespace.name,
|
|
465
|
+
name: parent.name
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
for (const target of wanted.values()) {
|
|
469
|
+
const namespace = staticNamespace2(target.schema);
|
|
470
|
+
const parent = { namespace, name: target.name };
|
|
471
|
+
objects.push(table3({ namespace, name: target.name, provenance }));
|
|
472
|
+
const rows = await runner.query(OUTSIDE_COLUMNS, [target.schema, target.name]);
|
|
473
|
+
for (const row of rows) {
|
|
474
|
+
objects.push(column2({
|
|
475
|
+
parent,
|
|
476
|
+
name: text(row, "name"),
|
|
477
|
+
dataType: text(row, "type"),
|
|
478
|
+
nullable: !flag(row, "not_null"),
|
|
479
|
+
provenance
|
|
480
|
+
}));
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
451
484
|
var EMITTED = new Set(["SELECT", "INSERT", "UPDATE", "DELETE", "EXECUTE", "USAGE"]);
|
|
452
485
|
var ROLES = `select rolname, rolcanlogin, rolinherit from pg_roles where rolname !~ '^pg_'`;
|
|
453
486
|
var RELATION_GRANTS = `select c.relname as name,
|
|
@@ -704,10 +737,21 @@ function indexExpression(row, columns) {
|
|
|
704
737
|
const opclasses = list(text(row, "opc"));
|
|
705
738
|
const body = columns.map((name, index) => {
|
|
706
739
|
const opclass = opclasses[index];
|
|
707
|
-
return opclass === undefined ?
|
|
740
|
+
return opclass === undefined ? quoteIdent2(name) : `${quoteIdent2(name)} ${opclass}`;
|
|
708
741
|
}).join(", ");
|
|
709
742
|
return `using ${method} (${body.length > 0 ? body : stored})`;
|
|
710
743
|
}
|
|
744
|
+
async function reprintDomainCheck(runner, base, expression) {
|
|
745
|
+
await runner.query("drop domain if exists okm_expr_domain");
|
|
746
|
+
await runner.query(`create domain okm_expr_domain as ${base} check (${expression})`);
|
|
747
|
+
const rows = await runner.query(`select pg_get_constraintdef(c.oid) as definition
|
|
748
|
+
from pg_constraint c
|
|
749
|
+
join pg_type t on t.oid = c.contypid
|
|
750
|
+
join pg_namespace n on n.oid = t.typnamespace
|
|
751
|
+
where t.typname = 'okm_expr_domain' and n.nspname = current_schema()`);
|
|
752
|
+
await runner.query("drop domain okm_expr_domain");
|
|
753
|
+
return checkExpression(text(rows[0] ?? {}, "definition"));
|
|
754
|
+
}
|
|
711
755
|
var CHILD = "not exists (select 1 from pg_inherits i where i.inhrelid = c.oid)";
|
|
712
756
|
var TABLES = `
|
|
713
757
|
select c.relname as name, pt.partstrat as partstrat,
|
|
@@ -761,6 +805,20 @@ var COLUMNS = `
|
|
|
761
805
|
and ${CHILD}
|
|
762
806
|
and ${member("c.oid", "pg_class")}
|
|
763
807
|
`;
|
|
808
|
+
function referencedNamespace(refSchema, concrete, logical) {
|
|
809
|
+
if (refSchema.length > 0 && refSchema !== concrete)
|
|
810
|
+
return staticNamespace2(refSchema);
|
|
811
|
+
return logical;
|
|
812
|
+
}
|
|
813
|
+
var OUTSIDE_COLUMNS = `
|
|
814
|
+
select a.attname as name, format_type(a.atttypid, a.atttypmod) as type, a.attnotnull as not_null
|
|
815
|
+
from pg_attribute a
|
|
816
|
+
join pg_class c on c.oid = a.attrelid
|
|
817
|
+
join pg_namespace n on n.oid = c.relnamespace
|
|
818
|
+
where n.nspname = $1 and c.relname = $2
|
|
819
|
+
and a.attnum > 0 and not a.attisdropped
|
|
820
|
+
order by a.attnum
|
|
821
|
+
`;
|
|
764
822
|
var CONSTRAINTS = `
|
|
765
823
|
select rel.relname as parent, con.conname as name, con.contype as contype,
|
|
766
824
|
con.condeferrable as deferrable, con.condeferred as deferred,
|
|
@@ -771,6 +829,7 @@ var CONSTRAINTS = `
|
|
|
771
829
|
join pg_attribute a on a.attrelid = con.conrelid and a.attnum = cols.attnum
|
|
772
830
|
) as columns,
|
|
773
831
|
ref.relname as ref_table,
|
|
832
|
+
refn.nspname as ref_schema,
|
|
774
833
|
(
|
|
775
834
|
select coalesce(string_agg(a.attname, ',' order by cols.ord), '')
|
|
776
835
|
from unnest(con.confkey) with ordinality as cols(attnum, ord)
|
|
@@ -780,6 +839,7 @@ var CONSTRAINTS = `
|
|
|
780
839
|
join pg_class rel on rel.oid = con.conrelid
|
|
781
840
|
join pg_namespace n on n.oid = rel.relnamespace
|
|
782
841
|
left join pg_class ref on ref.oid = con.confrelid
|
|
842
|
+
left join pg_namespace refn on refn.oid = ref.relnamespace
|
|
783
843
|
where n.nspname = $1
|
|
784
844
|
and con.contype in ('p', 'u', 'f', 'c')
|
|
785
845
|
and not exists (select 1 from pg_inherits i where i.inhrelid = rel.oid)
|
|
@@ -1033,4 +1093,4 @@ function flag(row, key) {
|
|
|
1033
1093
|
return value === true || value === "true" || value === "t";
|
|
1034
1094
|
}
|
|
1035
1095
|
|
|
1036
|
-
export { cellText, VIEW_DEPENDENCIES, viewDependencyEdges, PUBLIC, introspectSchema, FUNCTION_ARG_TYPES, atomicBody };
|
|
1096
|
+
export { cellText, VIEW_DEPENDENCIES, viewDependencyEdges, PUBLIC, introspectSchema, FUNCTION_ARG_TYPES, atomicBody, reprintDomainCheck };
|