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
|
@@ -3,25 +3,25 @@ import {
|
|
|
3
3
|
renameColumn2,
|
|
4
4
|
renameTable2
|
|
5
5
|
} from "./12z7aznj.js";
|
|
6
|
+
import {
|
|
7
|
+
quoteIdent2,
|
|
8
|
+
uniqueBeforeForeignKey2,
|
|
9
|
+
ownedByView2,
|
|
10
|
+
dropObjectSql2,
|
|
11
|
+
createObjectSql2,
|
|
12
|
+
functionSql2,
|
|
13
|
+
viewSql2,
|
|
14
|
+
policyCreatePlan2,
|
|
15
|
+
policyDropPlan2,
|
|
16
|
+
refreshMaterializedViewSql2,
|
|
17
|
+
alterColumnSql2,
|
|
18
|
+
identitySequence2,
|
|
19
|
+
createTableSql2,
|
|
20
|
+
qualify2
|
|
21
|
+
} from "./fk9vef30.js";
|
|
6
22
|
import {
|
|
7
23
|
isConnectionLost
|
|
8
24
|
} from "./cnkky55j.js";
|
|
9
|
-
import {
|
|
10
|
-
quoteIdent,
|
|
11
|
-
uniqueBeforeForeignKey,
|
|
12
|
-
ownedByView,
|
|
13
|
-
dropObjectSql,
|
|
14
|
-
createObjectSql,
|
|
15
|
-
functionSql,
|
|
16
|
-
viewSql,
|
|
17
|
-
policyCreatePlan,
|
|
18
|
-
policyDropPlan,
|
|
19
|
-
refreshMaterializedViewSql,
|
|
20
|
-
alterColumnSql,
|
|
21
|
-
identitySequence,
|
|
22
|
-
createTableSql,
|
|
23
|
-
qualify
|
|
24
|
-
} from "./sjk86yrx.js";
|
|
25
25
|
import {
|
|
26
26
|
isDomain,
|
|
27
27
|
sameEnumLabels
|
|
@@ -47,6 +47,20 @@ import {
|
|
|
47
47
|
OkmError2
|
|
48
48
|
} from "./52szzakm.js";
|
|
49
49
|
|
|
50
|
+
// src/tooling/migrate/driver-url.ts
|
|
51
|
+
function driverUrl(url) {
|
|
52
|
+
let parsed;
|
|
53
|
+
try {
|
|
54
|
+
parsed = new URL(url);
|
|
55
|
+
} catch {
|
|
56
|
+
return url;
|
|
57
|
+
}
|
|
58
|
+
if (!parsed.searchParams.has("pgbouncer"))
|
|
59
|
+
return url;
|
|
60
|
+
parsed.searchParams.delete("pgbouncer");
|
|
61
|
+
return parsed.toString();
|
|
62
|
+
}
|
|
63
|
+
|
|
50
64
|
// src/tooling/migrate/sql-lex.ts
|
|
51
65
|
function sqlStatements(sql) {
|
|
52
66
|
return scan(sql).statements;
|
|
@@ -366,6 +380,67 @@ function isEscapeString(sql, index) {
|
|
|
366
380
|
return false;
|
|
367
381
|
return true;
|
|
368
382
|
}
|
|
383
|
+
function sqlIdentifiers(sql) {
|
|
384
|
+
const names = [];
|
|
385
|
+
let index = 0;
|
|
386
|
+
while (index < sql.length) {
|
|
387
|
+
if (sql.startsWith("--", index)) {
|
|
388
|
+
index = lineCommentEnd(sql, index + 2);
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
if (sql.startsWith("/*", index)) {
|
|
392
|
+
const block = blockComment(sql, index + 2);
|
|
393
|
+
index = block.index;
|
|
394
|
+
if (block.open)
|
|
395
|
+
break;
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
const dollar = dollarAt(sql, index);
|
|
399
|
+
if (dollar !== undefined) {
|
|
400
|
+
const closed = takeDollar(sql, dollar);
|
|
401
|
+
index = closed.index;
|
|
402
|
+
if (closed.open)
|
|
403
|
+
break;
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
if (isEscapeString(sql, index)) {
|
|
407
|
+
const quote = takeQuoted(sql, index + 2, true);
|
|
408
|
+
index = quote.index;
|
|
409
|
+
if (quote.open)
|
|
410
|
+
break;
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
const char = sql[index];
|
|
414
|
+
if (char === "'") {
|
|
415
|
+
const quote = takeQuoted(sql, index + 1, false);
|
|
416
|
+
index = quote.index;
|
|
417
|
+
if (quote.open)
|
|
418
|
+
break;
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
if (char === '"') {
|
|
422
|
+
const quote = takeIdent(sql, index + 1);
|
|
423
|
+
if (!quote.open) {
|
|
424
|
+
names.push({ text: unescapeIdent(sql.slice(index + 1, quote.index - 1)), quoted: true });
|
|
425
|
+
}
|
|
426
|
+
index = quote.index;
|
|
427
|
+
if (quote.open)
|
|
428
|
+
break;
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
if (isIdentStart(sql.charCodeAt(index))) {
|
|
432
|
+
const word = readWord(sql, index);
|
|
433
|
+
names.push({ text: word, quoted: false });
|
|
434
|
+
index += word.length;
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
index += 1;
|
|
438
|
+
}
|
|
439
|
+
return names;
|
|
440
|
+
}
|
|
441
|
+
function unescapeIdent(text) {
|
|
442
|
+
return text.replaceAll('""', '"');
|
|
443
|
+
}
|
|
369
444
|
function isIdentStart(code) {
|
|
370
445
|
return code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 95;
|
|
371
446
|
}
|
|
@@ -484,6 +559,9 @@ function privilegeSql(before, after, schema, recreated = new Set) {
|
|
|
484
559
|
const tighten = tightenColumnSelect(object, after, schema);
|
|
485
560
|
if (tighten !== undefined)
|
|
486
561
|
grant.push(tighten);
|
|
562
|
+
const fromPublic = revokePublicExecute(object, schema);
|
|
563
|
+
if (fromPublic !== undefined)
|
|
564
|
+
grant.push(fromPublic);
|
|
487
565
|
grant.push({ sql: grantStatement(object, schema, false), kind: "grant" });
|
|
488
566
|
const writes = revokeMatviewWrites(object, after, schema);
|
|
489
567
|
if (writes !== undefined)
|
|
@@ -493,6 +571,9 @@ function privilegeSql(before, after, schema, recreated = new Set) {
|
|
|
493
571
|
if (previous !== undefined)
|
|
494
572
|
continue;
|
|
495
573
|
if (object.kind === "defaultPrivilege") {
|
|
574
|
+
const fromPublic = revokePublicDefaultExecute(object, schema);
|
|
575
|
+
if (fromPublic !== undefined)
|
|
576
|
+
defaults.push(fromPublic);
|
|
496
577
|
defaults.push({ sql: defaultStatement(object, schema, false), kind: "grant-default" });
|
|
497
578
|
}
|
|
498
579
|
}
|
|
@@ -522,10 +603,10 @@ function index(objects) {
|
|
|
522
603
|
return by;
|
|
523
604
|
}
|
|
524
605
|
function createRoleSql(object) {
|
|
525
|
-
return `create role ${
|
|
606
|
+
return `create role ${quoteIdent2(object.identity.name)} with nosuperuser nocreatedb nocreaterole ${inherit(object)} ${login(object)}`;
|
|
526
607
|
}
|
|
527
608
|
function alterRoleSql(object) {
|
|
528
|
-
return `alter role ${
|
|
609
|
+
return `alter role ${quoteIdent2(object.identity.name)} with ${inherit(object)} ${login(object)}`;
|
|
529
610
|
}
|
|
530
611
|
function login(object) {
|
|
531
612
|
return object.definition.login ? "login" : "nologin";
|
|
@@ -541,10 +622,30 @@ function tightenColumnSelect(object, after, schema) {
|
|
|
541
622
|
if (covered)
|
|
542
623
|
return;
|
|
543
624
|
return {
|
|
544
|
-
sql: `revoke select on ${grantTarget(target, schema)} from ${
|
|
625
|
+
sql: `revoke select on ${grantTarget(target, schema)} from ${quoteIdent2(object.identity.role)}`,
|
|
545
626
|
kind: "revoke"
|
|
546
627
|
};
|
|
547
628
|
}
|
|
629
|
+
function revokePublicExecute(object, schema) {
|
|
630
|
+
if (object.identity.privilege.toUpperCase() !== "EXECUTE")
|
|
631
|
+
return;
|
|
632
|
+
if (object.identity.object.kind !== "function")
|
|
633
|
+
return;
|
|
634
|
+
return {
|
|
635
|
+
sql: `revoke execute on ${grantTarget(object.identity.object, schema)} from public`,
|
|
636
|
+
kind: "revoke"
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
function revokePublicDefaultExecute(object, schema) {
|
|
640
|
+
if (object.identity.objectKind !== "function")
|
|
641
|
+
return;
|
|
642
|
+
if (object.identity.privilege.toUpperCase() !== "EXECUTE")
|
|
643
|
+
return;
|
|
644
|
+
return {
|
|
645
|
+
sql: `alter default privileges for role ${quoteIdent2(object.identity.forRole)} in schema ${quoteIdent2(schema)} revoke execute on functions from public`,
|
|
646
|
+
kind: "grant-default"
|
|
647
|
+
};
|
|
648
|
+
}
|
|
548
649
|
function revokeMatviewWrites(object, after, schema) {
|
|
549
650
|
if (object.identity.privilege.toUpperCase() !== "SELECT")
|
|
550
651
|
return;
|
|
@@ -555,7 +656,7 @@ function revokeMatviewWrites(object, after, schema) {
|
|
|
555
656
|
if (!inheritsWrites)
|
|
556
657
|
return;
|
|
557
658
|
return {
|
|
558
|
-
sql: `revoke insert, update, delete on ${grantTarget(target, schema)} from ${
|
|
659
|
+
sql: `revoke insert, update, delete on ${grantTarget(target, schema)} from ${quoteIdent2(object.identity.role)}`,
|
|
559
660
|
kind: "revoke"
|
|
560
661
|
};
|
|
561
662
|
}
|
|
@@ -565,11 +666,11 @@ function grantStatement(object, schema, revoke) {
|
|
|
565
666
|
const verb = revoke ? "revoke" : "grant";
|
|
566
667
|
const direction = revoke ? "from" : "to";
|
|
567
668
|
const target = grantTarget(object.identity.object, schema);
|
|
568
|
-
const role =
|
|
669
|
+
const role = quoteIdent2(object.identity.role);
|
|
569
670
|
const listed = column?.[2];
|
|
570
671
|
const base = column?.[1];
|
|
571
672
|
if (listed !== undefined && base !== undefined) {
|
|
572
|
-
const names = listed.split(",").filter((name) => name.length > 0).map((name) =>
|
|
673
|
+
const names = listed.split(",").filter((name) => name.length > 0).map((name) => quoteIdent2(name)).join(", ");
|
|
573
674
|
return `${verb} ${base.toLowerCase()} (${names}) on ${target} ${direction} ${role}`;
|
|
574
675
|
}
|
|
575
676
|
const keyword = privilege.toLowerCase();
|
|
@@ -581,7 +682,7 @@ function defaultStatement(object, schema, revoke) {
|
|
|
581
682
|
assertPrivilege(privilege);
|
|
582
683
|
const verb = revoke ? "revoke" : "grant";
|
|
583
684
|
const direction = revoke ? "from" : "to";
|
|
584
|
-
return `alter default privileges for role ${
|
|
685
|
+
return `alter default privileges for role ${quoteIdent2(object.identity.forRole)} in schema ${quoteIdent2(schema)} ${verb} ${privilege} on ${objectKindSql(object.identity.objectKind)} ${direction} ${quoteIdent2(object.identity.grantee)}`;
|
|
585
686
|
}
|
|
586
687
|
function grantTargetKey(object) {
|
|
587
688
|
if (object.kind === "table" || object.kind === "view" || object.kind === "materializedView" || object.kind === "sequence") {
|
|
@@ -603,20 +704,20 @@ function grantTargetKey(object) {
|
|
|
603
704
|
}
|
|
604
705
|
function grantTarget(object, schema) {
|
|
605
706
|
if (object.kind === "sequence")
|
|
606
|
-
return `sequence ${
|
|
707
|
+
return `sequence ${qualify2(schema, object.name)}`;
|
|
607
708
|
if (object.kind === "function")
|
|
608
709
|
return functionTarget(object.name, schema);
|
|
609
710
|
if (object.kind === "namespace")
|
|
610
|
-
return `schema ${
|
|
611
|
-
return `table ${
|
|
711
|
+
return `schema ${quoteIdent2(schema)}`;
|
|
712
|
+
return `table ${qualify2(schema, object.name)}`;
|
|
612
713
|
}
|
|
613
714
|
function functionTarget(name, schema) {
|
|
614
715
|
const open = name.lastIndexOf("(");
|
|
615
716
|
if (open < 0 || !name.endsWith(")"))
|
|
616
|
-
return `function ${
|
|
717
|
+
return `function ${qualify2(schema, name)}()`;
|
|
617
718
|
const fn = name.slice(0, open);
|
|
618
719
|
const args = name.slice(open + 1, -1);
|
|
619
|
-
return `function ${
|
|
720
|
+
return `function ${qualify2(schema, fn)}(${args})`;
|
|
620
721
|
}
|
|
621
722
|
function objectKindSql(kind) {
|
|
622
723
|
if (kind === "function")
|
|
@@ -713,7 +814,7 @@ function keyOn(source, table) {
|
|
|
713
814
|
if (column === undefined || column.kind !== "column") {
|
|
714
815
|
throw new OkmError2("OKM1546", `Table ${table} primary key column ${name} is not in the catalog.`, { fix: { summary: "Keep the primary key columns on the table." } });
|
|
715
816
|
}
|
|
716
|
-
columns.push({ quoted:
|
|
817
|
+
columns.push({ quoted: quoteIdent2(name), dataType: column.definition.dataType });
|
|
717
818
|
}
|
|
718
819
|
if (columns.length === 0)
|
|
719
820
|
return;
|
|
@@ -777,7 +878,7 @@ function splitKey(text) {
|
|
|
777
878
|
}
|
|
778
879
|
if (!closed)
|
|
779
880
|
return [];
|
|
780
|
-
names.push(
|
|
881
|
+
names.push(quoteIdent2(value));
|
|
781
882
|
if (text[index] === ",")
|
|
782
883
|
index += 1;
|
|
783
884
|
continue;
|
|
@@ -787,7 +888,7 @@ function splitKey(text) {
|
|
|
787
888
|
const raw = text.slice(index, end);
|
|
788
889
|
if (raw.length === 0)
|
|
789
890
|
return [];
|
|
790
|
-
names.push(
|
|
891
|
+
names.push(quoteIdent2(raw));
|
|
791
892
|
index = comma === -1 ? text.length : comma + 1;
|
|
792
893
|
}
|
|
793
894
|
return names;
|
|
@@ -961,7 +1062,7 @@ function refuseDrops(beforeBy, afterBy, dropKeys) {
|
|
|
961
1062
|
}
|
|
962
1063
|
function alterExtension(before, after) {
|
|
963
1064
|
const steps = [];
|
|
964
|
-
const name =
|
|
1065
|
+
const name = quoteIdent2(after.identity.name);
|
|
965
1066
|
if (before.definition.schema !== after.definition.schema) {
|
|
966
1067
|
if (!after.definition.relocatable) {
|
|
967
1068
|
throw new OkmError2("OKM1814", `Extension ${after.identity.name} is not relocatable, so it cannot move to ${after.definition.schema}.`, {
|
|
@@ -970,7 +1071,7 @@ function alterExtension(before, after) {
|
|
|
970
1071
|
}
|
|
971
1072
|
});
|
|
972
1073
|
}
|
|
973
|
-
steps.push(extensionStep(`alter extension ${name} set schema ${
|
|
1074
|
+
steps.push(extensionStep(`alter extension ${name} set schema ${quoteIdent2(after.definition.schema)}`, "move-extension"));
|
|
974
1075
|
}
|
|
975
1076
|
const previous = before.definition.version;
|
|
976
1077
|
const next = after.definition.version;
|
|
@@ -1151,9 +1252,9 @@ function stepsForExistingTable(object, schema, catalogs, batchSize) {
|
|
|
1151
1252
|
function notNullSteps(column, schema, setKind, catalogs) {
|
|
1152
1253
|
const tableName = column.identity.parent.name;
|
|
1153
1254
|
const columnName = column.identity.name;
|
|
1154
|
-
const table =
|
|
1155
|
-
const quotedColumn =
|
|
1156
|
-
const constraint =
|
|
1255
|
+
const table = qualify2(schema, tableName);
|
|
1256
|
+
const quotedColumn = quoteIdent2(columnName);
|
|
1257
|
+
const constraint = quoteIdent2(notNullConstraintName(tableName, columnName, catalogs));
|
|
1157
1258
|
return [
|
|
1158
1259
|
{
|
|
1159
1260
|
sql: `alter table ${table} add constraint ${constraint} check (${quotedColumn} is not null) not valid`,
|
|
@@ -1216,7 +1317,7 @@ function volatileDefault(expression, catalogs) {
|
|
|
1216
1317
|
return false;
|
|
1217
1318
|
}
|
|
1218
1319
|
function concurrentIndexStep(object, schema) {
|
|
1219
|
-
const plain =
|
|
1320
|
+
const plain = createObjectSql2(object, schema) ?? "";
|
|
1220
1321
|
return {
|
|
1221
1322
|
sql: concurrentIndexSql(plain),
|
|
1222
1323
|
kind: "create-index",
|
|
@@ -1232,13 +1333,13 @@ function constraintSteps(object, schema) {
|
|
|
1232
1333
|
return notValidSteps(object, schema);
|
|
1233
1334
|
}
|
|
1234
1335
|
function notValidSteps(object, schema) {
|
|
1235
|
-
const plain =
|
|
1336
|
+
const plain = createObjectSql2(object, schema);
|
|
1236
1337
|
if (plain === undefined)
|
|
1237
1338
|
return [];
|
|
1238
|
-
const table =
|
|
1239
|
-
const name =
|
|
1339
|
+
const table = qualify2(schema, object.identity.parent.name);
|
|
1340
|
+
const name = quoteIdent2(object.identity.name);
|
|
1240
1341
|
const referenced = object.definition.references;
|
|
1241
|
-
const referencedLock = referenced === undefined ? undefined :
|
|
1342
|
+
const referencedLock = referenced === undefined ? undefined : qualify2(schema, referenced.parent.name);
|
|
1242
1343
|
return [
|
|
1243
1344
|
{
|
|
1244
1345
|
sql: `${plain} not valid`,
|
|
@@ -1257,9 +1358,9 @@ function notValidSteps(object, schema) {
|
|
|
1257
1358
|
];
|
|
1258
1359
|
}
|
|
1259
1360
|
function usingIndexSteps(object, schema) {
|
|
1260
|
-
const table =
|
|
1261
|
-
const name =
|
|
1262
|
-
const columns = object.definition.columns.map((column) =>
|
|
1361
|
+
const table = qualify2(schema, object.identity.parent.name);
|
|
1362
|
+
const name = quoteIdent2(object.identity.name);
|
|
1363
|
+
const columns = object.definition.columns.map((column) => quoteIdent2(column)).join(", ");
|
|
1263
1364
|
const nulls = object.definition.nullsNotDistinct ? " nulls not distinct" : "";
|
|
1264
1365
|
const verb = object.definition.constraintKind === "primaryKey" ? "primary key" : "unique";
|
|
1265
1366
|
const defer = object.definition.deferrable ? ` deferrable initially ${object.definition.initially}` : "";
|
|
@@ -1282,9 +1383,9 @@ function usingIndexSteps(object, schema) {
|
|
|
1282
1383
|
}
|
|
1283
1384
|
function volatileColumnSteps(column, schema, catalogs, batchSize) {
|
|
1284
1385
|
const tableName = column.identity.parent.name;
|
|
1285
|
-
const table =
|
|
1286
|
-
const name =
|
|
1287
|
-
const collate = column.definition.collation === undefined ? "" : ` collate ${
|
|
1386
|
+
const table = qualify2(schema, tableName);
|
|
1387
|
+
const name = quoteIdent2(column.identity.name);
|
|
1388
|
+
const collate = column.definition.collation === undefined ? "" : ` collate ${quoteIdent2(column.definition.collation)}`;
|
|
1288
1389
|
const expression = column.definition.defaultExpression ?? "";
|
|
1289
1390
|
const key = primaryKeyColumns(catalogs, tableName);
|
|
1290
1391
|
const backfill = {
|
|
@@ -1539,12 +1640,12 @@ function planMigration(input) {
|
|
|
1539
1640
|
const deferred = new Set(picklists.map((change) => identityKey2(change.before.identity)));
|
|
1540
1641
|
const typeDrops = [];
|
|
1541
1642
|
const extensionDrops = [];
|
|
1542
|
-
const reverse = [...
|
|
1643
|
+
const reverse = [...uniqueBeforeForeignKey2(creationOrder2(renamed))].reverse();
|
|
1543
1644
|
const emitDrop = (object) => {
|
|
1544
1645
|
const key = identityKey2(object.identity);
|
|
1545
1646
|
if (!dropKeys.has(key) || deferred.has(key) || covered(object, droppedTables))
|
|
1546
1647
|
return;
|
|
1547
|
-
const sql =
|
|
1648
|
+
const sql = dropObjectSql2(object, schema);
|
|
1548
1649
|
const kind = dropKind(object);
|
|
1549
1650
|
if (sql === undefined || kind === undefined)
|
|
1550
1651
|
return;
|
|
@@ -1566,7 +1667,7 @@ function planMigration(input) {
|
|
|
1566
1667
|
if (object.kind === "function")
|
|
1567
1668
|
emitDrop(object);
|
|
1568
1669
|
for (const object of reverse)
|
|
1569
|
-
if (
|
|
1670
|
+
if (ownedByView2(object))
|
|
1570
1671
|
emitDrop(object);
|
|
1571
1672
|
for (const object of reverse) {
|
|
1572
1673
|
if (object.kind === "view" || object.kind === "materializedView")
|
|
@@ -1578,12 +1679,12 @@ function planMigration(input) {
|
|
|
1578
1679
|
const key = identityKey2(object.identity);
|
|
1579
1680
|
if (!dropKeys.has(key) || deferred.has(key))
|
|
1580
1681
|
continue;
|
|
1581
|
-
for (const item of
|
|
1682
|
+
for (const item of policyDropPlan2(object, schema)) {
|
|
1582
1683
|
steps.push(step(item.sql, item.kind, "ddl", ACCESS2, true, [object.identity.parent.name]));
|
|
1583
1684
|
}
|
|
1584
1685
|
}
|
|
1585
1686
|
for (const object of reverse) {
|
|
1586
|
-
if (object.kind === "trigger" || object.kind === "function" || object.kind === "view" || object.kind === "materializedView" || object.kind === "policy" ||
|
|
1687
|
+
if (object.kind === "trigger" || object.kind === "function" || object.kind === "view" || object.kind === "materializedView" || object.kind === "policy" || ownedByView2(object)) {
|
|
1587
1688
|
continue;
|
|
1588
1689
|
}
|
|
1589
1690
|
const key = identityKey2(object.identity);
|
|
@@ -1606,7 +1707,7 @@ function planMigration(input) {
|
|
|
1606
1707
|
steps.push(...extensionAlterSteps(beforeBy, afterBy, dropKeys));
|
|
1607
1708
|
for (const change of alters) {
|
|
1608
1709
|
const aligned = alignedColumnType(change.before, change.after);
|
|
1609
|
-
const statements =
|
|
1710
|
+
const statements = alterColumnSql2(aligned, change.after, schema);
|
|
1610
1711
|
const kinds = columnAlterKinds(aligned, change.after);
|
|
1611
1712
|
for (let index = 0;index < statements.length; index += 1) {
|
|
1612
1713
|
const sql = statements[index];
|
|
@@ -1636,7 +1737,7 @@ function planMigration(input) {
|
|
|
1636
1737
|
if (!createKeys.has(key) || emitted.has(key))
|
|
1637
1738
|
continue;
|
|
1638
1739
|
emitted.add(key);
|
|
1639
|
-
const sql =
|
|
1740
|
+
const sql = createObjectSql2(object, schema);
|
|
1640
1741
|
const kind = createKind(object, false);
|
|
1641
1742
|
if (sql === undefined || kind === undefined)
|
|
1642
1743
|
continue;
|
|
@@ -1649,14 +1750,14 @@ function planMigration(input) {
|
|
|
1649
1750
|
if (!createKeys.has(key) || emitted.has(key))
|
|
1650
1751
|
continue;
|
|
1651
1752
|
emitted.add(key);
|
|
1652
|
-
const sql =
|
|
1753
|
+
const sql = createObjectSql2(object, schema);
|
|
1653
1754
|
const kind = createKind(object, false);
|
|
1654
1755
|
if (sql === undefined || kind === undefined)
|
|
1655
1756
|
continue;
|
|
1656
1757
|
steps.push(step(sql, kind, "ddl", ACCESS2));
|
|
1657
1758
|
}
|
|
1658
|
-
for (const object of
|
|
1659
|
-
if (object.kind === "type" || object.kind === "extension" || object.kind === "function" || object.kind === "trigger" || object.kind === "view" || object.kind === "materializedView" || object.kind === "policy" ||
|
|
1759
|
+
for (const object of uniqueBeforeForeignKey2(creationOrder2(request.after))) {
|
|
1760
|
+
if (object.kind === "type" || object.kind === "extension" || object.kind === "function" || object.kind === "trigger" || object.kind === "view" || object.kind === "materializedView" || object.kind === "policy" || ownedByView2(object)) {
|
|
1660
1761
|
continue;
|
|
1661
1762
|
}
|
|
1662
1763
|
const key = identityKey2(object.identity);
|
|
@@ -1671,10 +1772,10 @@ function planMigration(input) {
|
|
|
1671
1772
|
continue;
|
|
1672
1773
|
emitted.add(key);
|
|
1673
1774
|
if (object.kind === "table") {
|
|
1674
|
-
steps.push(step(
|
|
1775
|
+
steps.push(step(createTableSql2(object, request.after, schema), "create-table", "ddl", ACCESS2));
|
|
1675
1776
|
continue;
|
|
1676
1777
|
}
|
|
1677
|
-
const sql =
|
|
1778
|
+
const sql = createObjectSql2(object, schema);
|
|
1678
1779
|
const kind = createKind(object, tableIsNew);
|
|
1679
1780
|
if (sql === undefined || kind === undefined)
|
|
1680
1781
|
continue;
|
|
@@ -1694,7 +1795,7 @@ function planMigration(input) {
|
|
|
1694
1795
|
if (!createKeys.has(key) || emitted.has(key))
|
|
1695
1796
|
continue;
|
|
1696
1797
|
emitted.add(key);
|
|
1697
|
-
for (const item of
|
|
1798
|
+
for (const item of policyCreatePlan2(object, schema)) {
|
|
1698
1799
|
steps.push(step(item.sql, item.kind, "ddl", ACCESS2, true, [object.identity.parent.name]));
|
|
1699
1800
|
}
|
|
1700
1801
|
}
|
|
@@ -1704,7 +1805,7 @@ function planMigration(input) {
|
|
|
1704
1805
|
const key = identityKey2(change.after.identity);
|
|
1705
1806
|
if (dropKeys.has(key) && createKeys.has(key))
|
|
1706
1807
|
continue;
|
|
1707
|
-
const sql = change.kind === "function" ?
|
|
1808
|
+
const sql = change.kind === "function" ? functionSql2(change.after, schema, true) : viewSql2(change.after, schema, true);
|
|
1708
1809
|
const kind = change.kind === "function" ? "replace-function" : "replace-view";
|
|
1709
1810
|
steps.push({
|
|
1710
1811
|
sql,
|
|
@@ -1724,7 +1825,7 @@ function planMigration(input) {
|
|
|
1724
1825
|
if (!createKeys.has(key) || emitted.has(key))
|
|
1725
1826
|
continue;
|
|
1726
1827
|
emitted.add(key);
|
|
1727
|
-
const sql =
|
|
1828
|
+
const sql = createObjectSql2(object, schema);
|
|
1728
1829
|
const created = createKind(object, false);
|
|
1729
1830
|
if (sql === undefined || created === undefined)
|
|
1730
1831
|
continue;
|
|
@@ -1732,13 +1833,13 @@ function planMigration(input) {
|
|
|
1732
1833
|
}
|
|
1733
1834
|
}
|
|
1734
1835
|
for (const object of creationOrder2(request.after)) {
|
|
1735
|
-
if (!
|
|
1836
|
+
if (!ownedByView2(object))
|
|
1736
1837
|
continue;
|
|
1737
1838
|
const key = identityKey2(object.identity);
|
|
1738
1839
|
if (!createKeys.has(key) || emitted.has(key))
|
|
1739
1840
|
continue;
|
|
1740
1841
|
emitted.add(key);
|
|
1741
|
-
const sql =
|
|
1842
|
+
const sql = createObjectSql2(object, schema);
|
|
1742
1843
|
const kind = createKind(object, false);
|
|
1743
1844
|
if (sql === undefined || kind === undefined)
|
|
1744
1845
|
continue;
|
|
@@ -1751,7 +1852,7 @@ function planMigration(input) {
|
|
|
1751
1852
|
if (!createKeys.has(key))
|
|
1752
1853
|
continue;
|
|
1753
1854
|
assertConcurrentRefresh(object, request.after);
|
|
1754
|
-
steps.push(step(
|
|
1855
|
+
steps.push(step(refreshMaterializedViewSql2(object, schema, false), "refresh-matview", "backfill", ACCESS2));
|
|
1755
1856
|
}
|
|
1756
1857
|
for (const item of privileges.grant)
|
|
1757
1858
|
steps.push(step(item.sql, item.kind, "ddl", ACCESS2));
|
|
@@ -1942,7 +2043,7 @@ function renameSteps(source, renames, schema) {
|
|
|
1942
2043
|
if (rename.kind !== "table" || !hasTable(source, rename.from))
|
|
1943
2044
|
continue;
|
|
1944
2045
|
tables.set(rename.to, rename.from);
|
|
1945
|
-
steps.push(step(`alter table ${
|
|
2046
|
+
steps.push(step(`alter table ${qualify2(schema, rename.from)} rename to ${quoteIdent2(rename.to)}`, "rename-table", "ddl", ACCESS2));
|
|
1946
2047
|
steps.push(...sequenceRenames(source, rename, schema));
|
|
1947
2048
|
}
|
|
1948
2049
|
for (const rename of renames) {
|
|
@@ -1951,7 +2052,7 @@ function renameSteps(source, renames, schema) {
|
|
|
1951
2052
|
const previousTable = tables.get(rename.table) ?? rename.table;
|
|
1952
2053
|
if (!hasColumn(source, previousTable, rename.from))
|
|
1953
2054
|
continue;
|
|
1954
|
-
steps.push(step(`alter table ${
|
|
2055
|
+
steps.push(step(`alter table ${qualify2(schema, rename.table)} rename column ${quoteIdent2(rename.from)} to ${quoteIdent2(rename.to)}`, "rename-column", "ddl", ACCESS2));
|
|
1955
2056
|
}
|
|
1956
2057
|
return steps;
|
|
1957
2058
|
}
|
|
@@ -1969,7 +2070,7 @@ function sequenceRenames(source, rename, schema) {
|
|
|
1969
2070
|
const owned = source.objects.some((item) => item.kind === "sequence" && item.identity.name === fromName);
|
|
1970
2071
|
if (!owned)
|
|
1971
2072
|
continue;
|
|
1972
|
-
steps.push(step(`alter sequence ${
|
|
2073
|
+
steps.push(step(`alter sequence ${qualify2(schema, fromName)} rename to ${quoteIdent2(toName)}`, "rename-sequence", "ddl", ACCESS2));
|
|
1973
2074
|
}
|
|
1974
2075
|
return steps;
|
|
1975
2076
|
}
|
|
@@ -2018,14 +2119,14 @@ function withoutNameKey(value) {
|
|
|
2018
2119
|
}
|
|
2019
2120
|
function renameShapeStep(pair, schema) {
|
|
2020
2121
|
if (pair.from.kind === "index" && pair.to.kind === "index") {
|
|
2021
|
-
return step(`alter index ${
|
|
2122
|
+
return step(`alter index ${qualify2(schema, pair.from.identity.name)} rename to ${quoteIdent2(pair.to.identity.name)}`, "rename-index", "ddl", SHARE_UPDATE2);
|
|
2022
2123
|
}
|
|
2023
2124
|
if (pair.from.kind !== "constraint" || pair.to.kind !== "constraint") {
|
|
2024
2125
|
throw new OkmError2("invalid", "A same-shape rename is an index or a constraint.", {
|
|
2025
2126
|
fix: { summary: "The planner only renames an index or a constraint in place." }
|
|
2026
2127
|
});
|
|
2027
2128
|
}
|
|
2028
|
-
return step(`alter table ${
|
|
2129
|
+
return step(`alter table ${qualify2(schema, pair.from.identity.parent.name)} rename constraint ${quoteIdent2(pair.from.identity.name)} to ${quoteIdent2(pair.to.identity.name)}`, "rename-constraint", "ddl", ACCESS2);
|
|
2029
2130
|
}
|
|
2030
2131
|
function assertUnambiguous(beforeBy, afterBy) {
|
|
2031
2132
|
const dropped = new Map;
|
|
@@ -2211,8 +2312,8 @@ function contractSwaps(picklists, enums, replacements, schema, catalogs, batchSi
|
|
|
2211
2312
|
const steps = [];
|
|
2212
2313
|
steps.push(...dataSteps(picklists, enums, replacements, schema, catalogs, batchSize, "contract"));
|
|
2213
2314
|
for (const change of picklists) {
|
|
2214
|
-
const table =
|
|
2215
|
-
const name =
|
|
2315
|
+
const table = qualify2(schema, change.after.identity.parent.name);
|
|
2316
|
+
const name = quoteIdent2(change.after.identity.name);
|
|
2216
2317
|
const kind = change.removed.length > 0 ? "narrow-check" : "widen-check";
|
|
2217
2318
|
steps.push(step(`alter table ${table} drop constraint ${name}`, kind, "ddl", ACCESS2));
|
|
2218
2319
|
const expression = change.after.definition.expression ?? "true";
|
|
@@ -2222,17 +2323,17 @@ function contractSwaps(picklists, enums, replacements, schema, catalogs, batchSi
|
|
|
2222
2323
|
for (const change of enums) {
|
|
2223
2324
|
if (change.kind !== "replace")
|
|
2224
2325
|
continue;
|
|
2225
|
-
const type =
|
|
2226
|
-
const old =
|
|
2326
|
+
const type = qualify2(schema, change.name);
|
|
2327
|
+
const old = quoteIdent2(`${change.name}_old`);
|
|
2227
2328
|
const labels = change.labels.map((label) => quoteLiteral(label)).join(", ");
|
|
2228
2329
|
steps.push(step(`alter type ${type} rename to ${old}`, "rename-enum", "ddl", ACCESS2));
|
|
2229
2330
|
steps.push(step(`create type ${type} as enum (${labels})`, "recreate-enum", "ddl", ACCESS2));
|
|
2230
2331
|
for (const column of change.columns) {
|
|
2231
|
-
const table =
|
|
2232
|
-
const name =
|
|
2332
|
+
const table = qualify2(schema, column.table);
|
|
2333
|
+
const name = quoteIdent2(column.column);
|
|
2233
2334
|
steps.push(step(`alter table ${table} alter column ${name} type ${type} using ${name}::text::${type}`, "set-enum-column", "ddl", ACCESS2));
|
|
2234
2335
|
}
|
|
2235
|
-
steps.push(step(`drop type ${
|
|
2336
|
+
steps.push(step(`drop type ${qualify2(schema, `${change.name}_old`)}`, "drop-enum", "ddl", ACCESS2));
|
|
2236
2337
|
}
|
|
2237
2338
|
return steps;
|
|
2238
2339
|
}
|
|
@@ -2376,9 +2477,9 @@ function domainCheckSteps(beforeBy, afterBy, schema) {
|
|
|
2376
2477
|
if (previous.definition.check === next.definition.check)
|
|
2377
2478
|
continue;
|
|
2378
2479
|
const name = next.identity.name;
|
|
2379
|
-
const type =
|
|
2380
|
-
const current =
|
|
2381
|
-
const upcoming =
|
|
2480
|
+
const type = qualify2(schema, name);
|
|
2481
|
+
const current = quoteIdent2(fitIdentifier2(`${name}_check`));
|
|
2482
|
+
const upcoming = quoteIdent2(fitIdentifier2(`${name}_check_next`));
|
|
2382
2483
|
const expression = next.definition.check;
|
|
2383
2484
|
steps.push(step(`alter domain ${type} add constraint ${upcoming} check (${expression}) not valid`, "add-domain-check", "ddl", ACCESS2));
|
|
2384
2485
|
steps.push(step(`alter domain ${type} validate constraint ${upcoming}`, "validate-domain-check", "ddl", ACCESS2));
|
|
@@ -2454,7 +2555,7 @@ function labelSubsequence(before, after) {
|
|
|
2454
2555
|
function addValueStatements(schema, name, before, after) {
|
|
2455
2556
|
const present = new Set(before);
|
|
2456
2557
|
const statements = [];
|
|
2457
|
-
const type =
|
|
2558
|
+
const type = qualify2(schema, name);
|
|
2458
2559
|
for (let index = 0;index < after.length; index += 1) {
|
|
2459
2560
|
const label = after[index];
|
|
2460
2561
|
if (label === undefined || present.has(label))
|
|
@@ -2538,8 +2639,8 @@ function columnAlterable(before, after) {
|
|
|
2538
2639
|
function identityChangeSql(before, after, schema) {
|
|
2539
2640
|
if (stable(before.definition.identity) === stable(after.definition.identity))
|
|
2540
2641
|
return;
|
|
2541
|
-
const table =
|
|
2542
|
-
const name =
|
|
2642
|
+
const table = qualify2(schema, after.identity.parent.name);
|
|
2643
|
+
const name = quoteIdent2(after.identity.name);
|
|
2543
2644
|
const next = after.definition.identity;
|
|
2544
2645
|
const previous = before.definition.identity;
|
|
2545
2646
|
if (next === undefined)
|
|
@@ -2683,7 +2784,7 @@ function folded(object, source) {
|
|
|
2683
2784
|
return true;
|
|
2684
2785
|
if (object.kind !== "sequence")
|
|
2685
2786
|
return false;
|
|
2686
|
-
if (
|
|
2787
|
+
if (identitySequence2(object, source))
|
|
2687
2788
|
return true;
|
|
2688
2789
|
const name = object.identity.name;
|
|
2689
2790
|
return source.objects.some((column) => {
|
|
@@ -2703,9 +2804,9 @@ function overall(steps) {
|
|
|
2703
2804
|
}
|
|
2704
2805
|
function updateSql(schema, table, column, from, to, catalogs, batchSize, cast = false) {
|
|
2705
2806
|
const key = primaryKeyColumns(catalogs, table);
|
|
2706
|
-
const qualified =
|
|
2807
|
+
const qualified = qualify2(schema, table);
|
|
2707
2808
|
const value = to === null ? "null" : quoteLiteral(to);
|
|
2708
|
-
const compare = cast ? `${
|
|
2809
|
+
const compare = cast ? `${quoteIdent2(column)}::text` : quoteIdent2(column);
|
|
2709
2810
|
const where = `${compare} = ${quoteLiteral(from)}`;
|
|
2710
2811
|
const backfill = {
|
|
2711
2812
|
table: qualified,
|
|
@@ -2713,7 +2814,7 @@ function updateSql(schema, table, column, from, to, catalogs, batchSize, cast =
|
|
|
2713
2814
|
batch: batchSize
|
|
2714
2815
|
};
|
|
2715
2816
|
return {
|
|
2716
|
-
sql: `update ${qualified} set ${
|
|
2817
|
+
sql: `update ${qualified} set ${quoteIdent2(column)} = ${value} where ${where} and ${keyRangePredicate(key)}`,
|
|
2717
2818
|
backfill
|
|
2718
2819
|
};
|
|
2719
2820
|
}
|
|
@@ -2804,7 +2905,7 @@ function readIdent(text, start) {
|
|
|
2804
2905
|
return;
|
|
2805
2906
|
}
|
|
2806
2907
|
function pushDrop(steps, object, schema) {
|
|
2807
|
-
const sql =
|
|
2908
|
+
const sql = dropObjectSql2(object, schema);
|
|
2808
2909
|
const kind = dropKind(object);
|
|
2809
2910
|
if (sql === undefined || kind === undefined)
|
|
2810
2911
|
return;
|
|
@@ -3021,14 +3122,36 @@ function assertDirectConnection(url, allowPooler) {
|
|
|
3021
3122
|
throw new OkmError2("invalid", `Refusing pooler host ${host}. Apply needs a direct connection.`, { fix: { summary: "Use a direct connection, or pass --allow-pooler." } });
|
|
3022
3123
|
}
|
|
3023
3124
|
}
|
|
3024
|
-
async function assertStableBackend(readPid, allowPooler) {
|
|
3125
|
+
async function assertStableBackend(readPid, allowPooler, options) {
|
|
3025
3126
|
if (allowPooler)
|
|
3026
3127
|
return;
|
|
3027
|
-
const
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3128
|
+
const seen = new Set;
|
|
3129
|
+
let first = "";
|
|
3130
|
+
let release;
|
|
3131
|
+
try {
|
|
3132
|
+
for (let i = 0;i < 8; i += 1) {
|
|
3133
|
+
const pid = await readPid();
|
|
3134
|
+
if (first.length === 0)
|
|
3135
|
+
first = pid;
|
|
3136
|
+
seen.add(pid);
|
|
3137
|
+
if (seen.size >= 2) {
|
|
3138
|
+
const second = [...seen].find((value) => value !== first) ?? pid;
|
|
3139
|
+
throw new OkmError2("OKM1854", `The backend pid changed from ${first} to ${second}. A pooler is handing out a new session between statements.`, { fix: { summary: "Use a direct connection, or pass --allow-pooler." } });
|
|
3140
|
+
}
|
|
3141
|
+
if (release !== undefined) {
|
|
3142
|
+
await release();
|
|
3143
|
+
release = undefined;
|
|
3144
|
+
}
|
|
3145
|
+
if (i < 7 && options?.holdBackend !== undefined) {
|
|
3146
|
+
release = await options.holdBackend();
|
|
3147
|
+
}
|
|
3148
|
+
}
|
|
3149
|
+
} finally {
|
|
3150
|
+
if (release !== undefined)
|
|
3151
|
+
await release().catch(() => {
|
|
3152
|
+
return;
|
|
3153
|
+
});
|
|
3154
|
+
}
|
|
3032
3155
|
}
|
|
3033
3156
|
function listTargets(config) {
|
|
3034
3157
|
if (config.database !== undefined && config.targets !== undefined) {
|
|
@@ -3118,4 +3241,4 @@ function endpointOf(url) {
|
|
|
3118
3241
|
};
|
|
3119
3242
|
}
|
|
3120
3243
|
|
|
3121
|
-
export { sqlStatements, transactionControl, canonicalTypeName, prepareMigrationText, assertMigrationSteps, columnPrivilege, createdRoleName, createRoleOnce, changesRole, DEFAULT_BACKFILL_PAUSE_MS, DEFAULT_BACKFILL_STATEMENT_TIMEOUT_MS, batchSizeField, aboutBatchCount, boundaryQuery, checkedCast, classOf, strictestClass, assertExtensionsAvailable, omitManagedObjects, parseReplace, planMigration, formatPlan, parsePlan, staleRenames, sessionFailure, finishQuiet, assertTargetPolicy, assertTargetAlias, assertDirectConnection, assertStableBackend, listTargets, selectTarget };
|
|
3244
|
+
export { driverUrl, sqlStatements, transactionControl, sqlIdentifiers, canonicalTypeName, prepareMigrationText, assertMigrationSteps, columnPrivilege, createdRoleName, createRoleOnce, changesRole, DEFAULT_BACKFILL_PAUSE_MS, DEFAULT_BACKFILL_STATEMENT_TIMEOUT_MS, batchSizeField, aboutBatchCount, boundaryQuery, checkedCast, classOf, strictestClass, assertExtensionsAvailable, omitManagedObjects, parseReplace, planMigration, formatPlan, parsePlan, staleRenames, sessionFailure, finishQuiet, assertTargetPolicy, assertTargetAlias, assertDirectConnection, assertStableBackend, listTargets, selectTarget };
|