@vibeorm/sql 2.3.0 → 2.4.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.
- package/dist/dialects/migration-replay-coverage.d.ts.map +1 -1
- package/dist/dialects/migration-shadow.d.ts.map +1 -1
- package/dist/dialects/mysql.d.ts.map +1 -1
- package/dist/dialects/postgres.d.ts.map +1 -1
- package/dist/dialects/sqlite.d.ts.map +1 -1
- package/dist/identifiers.d.ts +14 -0
- package/dist/identifiers.d.ts.map +1 -0
- package/dist/index.js +35 -20
- package/dist/index.js.map +10 -9
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration-replay-coverage.d.ts","sourceRoot":"","sources":["../../src/dialects/migration-replay-coverage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"migration-replay-coverage.d.ts","sourceRoot":"","sources":["../../src/dialects/migration-replay-coverage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAwBlD,iGAAiG;AACjG,wBAAgB,wBAAwB,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,aAAa,CAarI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration-shadow.d.ts","sourceRoot":"","sources":["../../src/dialects/migration-shadow.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OA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AE,MAAM,GAAG,QAAQ,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC/D;IAAE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAClF;IAAE,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAA;CAAE,GAClC;IAAE,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAChE;IAAE,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAExI,mFAAmF;AACnF,wBAAgB,qBAAqB,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,eAAe,CAAA;CAAE,GAAG,SAAS,aAAa,EAAE,CAyE3H"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../../src/dialects/mysql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../../src/dialects/mysql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAIhD,eAAO,MAAM,YAAY,EAAE,UA4F1B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/dialects/postgres.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/dialects/postgres.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAIhD,eAAO,MAAM,eAAe,EAAE,UA0F7B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/dialects/sqlite.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/dialects/sqlite.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAIhD,eAAO,MAAM,aAAa,EAAE,UAuF3B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identifier hygiene shared by every dialect's `quoteIdent`.
|
|
3
|
+
*
|
|
4
|
+
* Quoting doubles the quote character, which is the whole grammar for every
|
|
5
|
+
* other byte — except NUL: C-string servers stop reading an identifier at the
|
|
6
|
+
* first NUL, so `"users\0x"` would address `users`, and a quoted identifier
|
|
7
|
+
* containing one is not an identifier at all. Refused at render time, the
|
|
8
|
+
* earliest point every path (IR, raw `sql.ident`, extension DDL) shares.
|
|
9
|
+
*/
|
|
10
|
+
/** Return `name` unchanged, or throw `VIBE_VALIDATION` when it contains a NUL. */
|
|
11
|
+
export declare function assertNoNul(params: {
|
|
12
|
+
name: string;
|
|
13
|
+
}): string;
|
|
14
|
+
//# sourceMappingURL=identifiers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifiers.d.ts","sourceRoot":"","sources":["../src/identifiers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,kFAAkF;AAClF,wBAAgB,WAAW,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAS5D"}
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,8 @@ ORDER BY source_namespace, source_table, constraint_name`,
|
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
// packages/sql/src/dialects/migration-replay-coverage.ts
|
|
46
|
+
var extensionMember = (classid, objid) => `EXISTS (SELECT 1 FROM pg_catalog.pg_depend d WHERE d.classid = '${classid}'::regclass AND d.objid = ${objid} AND d.deptype = 'e')`;
|
|
47
|
+
var extensionOwnedNamespace = `(EXISTS (SELECT 1 FROM pg_catalog.pg_extension e WHERE e.extnamespace = n.oid) OR ${extensionMember("pg_namespace", "n.oid")}) AND NOT EXISTS (SELECT 1 FROM pg_catalog.pg_class c WHERE c.relnamespace = n.oid AND c.relkind IN ('r', 'p', 'v', 'm', 'f', 'S') AND NOT ${extensionMember("pg_class", "c.oid")}) AND NOT EXISTS (SELECT 1 FROM pg_catalog.pg_proc p WHERE p.pronamespace = n.oid AND NOT ${extensionMember("pg_proc", "p.oid")}) AND NOT EXISTS (SELECT 1 FROM pg_catalog.pg_type t WHERE t.typnamespace = n.oid AND (t.typrelid = 0 AND t.typelem = 0 OR t.typtype = 'c' AND EXISTS (SELECT 1 FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid AND c.relkind = 'c')) AND NOT ${extensionMember("pg_type", "t.oid")})`;
|
|
46
48
|
function renderReplayCoverageGaps(params) {
|
|
47
49
|
const { dialect } = params;
|
|
48
50
|
const collector = new ParamCollector(dialect);
|
|
@@ -51,8 +53,8 @@ function renderReplayCoverageGaps(params) {
|
|
|
51
53
|
return { text: `SELECT 'type' AS kind, t.typname::text AS name FROM pg_catalog.pg_type t JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace WHERE n.nspname = ${namespace} AND (t.typtype IN ('b', 'd', 'r', 'm') AND t.typelem = 0 OR t.typtype = 'c' AND EXISTS (SELECT 1 FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid AND c.relkind = 'c')) AND NOT EXISTS (SELECT 1 FROM pg_catalog.pg_depend d WHERE d.classid = 'pg_type'::regclass AND d.objid = t.oid AND d.deptype = 'e')
|
|
52
54
|
UNION ALL SELECT 'routine', p.proname::text FROM pg_catalog.pg_proc p JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace WHERE n.nspname = ${namespace} AND p.prokind <> 'f' AND NOT EXISTS (SELECT 1 FROM pg_catalog.pg_depend d WHERE d.classid = 'pg_proc'::regclass AND d.objid = p.oid AND d.deptype = 'e')
|
|
53
55
|
UNION ALL SELECT 'relation-layout', c.relname::text FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = ${namespace} AND (c.relkind IN ('p', 'f') OR c.relispartition OR EXISTS (SELECT 1 FROM pg_catalog.pg_inherits i WHERE i.inhrelid = c.oid)) AND NOT EXISTS (SELECT 1 FROM pg_catalog.pg_depend d WHERE d.classid = 'pg_class'::regclass AND d.objid = c.oid AND d.deptype = 'e')
|
|
54
|
-
UNION ALL SELECT 'rule', r.rulename::text FROM pg_catalog.pg_rewrite r JOIN pg_catalog.pg_class c ON c.oid = r.ev_class JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = ${namespace} AND r.rulename <> '_RETURN'
|
|
55
|
-
UNION ALL SELECT 'namespace', n.nspname::text FROM pg_catalog.pg_namespace n WHERE n.nspname <> ${namespace} AND n.nspname <> 'information_schema' AND n.nspname NOT LIKE 'pg\\_%' ESCAPE '\\'${params.privateNamespace === undefined ? "" : ` AND n.nspname <> ${collector.add(params.privateNamespace)}`}`, values: collector.values, returning: "none" };
|
|
56
|
+
UNION ALL SELECT 'rule', r.rulename::text FROM pg_catalog.pg_rewrite r JOIN pg_catalog.pg_class c ON c.oid = r.ev_class JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = ${namespace} AND r.rulename <> '_RETURN' AND NOT ${extensionMember("pg_class", "c.oid")}
|
|
57
|
+
UNION ALL SELECT 'namespace', n.nspname::text FROM pg_catalog.pg_namespace n WHERE n.nspname <> ${namespace} AND n.nspname <> 'information_schema' AND n.nspname NOT LIKE 'pg\\_%' ESCAPE '\\' AND NOT (${extensionOwnedNamespace})${params.privateNamespace === undefined ? "" : ` AND n.nspname <> ${collector.add(params.privateNamespace)}`}`, values: collector.values, returning: "none" };
|
|
56
58
|
if (dialect.name === "mysql")
|
|
57
59
|
return { text: `SELECT 'procedure' AS kind, ROUTINE_NAME AS name FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = ${namespace} AND ROUTINE_TYPE = 'PROCEDURE'
|
|
58
60
|
UNION ALL SELECT 'event', EVENT_NAME FROM information_schema.EVENTS WHERE EVENT_SCHEMA = ${collector.add(params.namespace)}
|
|
@@ -77,7 +79,7 @@ function renderShadowOperation(params) {
|
|
|
77
79
|
const result = (text) => [{ text, values: collector.values, returning: "none" }];
|
|
78
80
|
switch (operation.kind) {
|
|
79
81
|
case "createDatabase":
|
|
80
|
-
return result(`CREATE DATABASE ${dialect.quoteIdent({ name: operation.name })}`);
|
|
82
|
+
return result(`CREATE DATABASE ${dialect.quoteIdent({ name: operation.name })}${pg ? " TEMPLATE template0" : ""}`);
|
|
81
83
|
case "dropDatabase":
|
|
82
84
|
return result(`DROP DATABASE ${dialect.quoteIdent({ name: operation.name })}`);
|
|
83
85
|
case "identity":
|
|
@@ -1188,6 +1190,19 @@ import {
|
|
|
1188
1190
|
MYSQL_CAPABILITIES
|
|
1189
1191
|
} from "@vibeorm/schema";
|
|
1190
1192
|
|
|
1193
|
+
// packages/sql/src/identifiers.ts
|
|
1194
|
+
import { VibeError as VibeError6 } from "@vibeorm/schema";
|
|
1195
|
+
function assertNoNul(params) {
|
|
1196
|
+
if (params.name.includes("\x00")) {
|
|
1197
|
+
throw new VibeError6({
|
|
1198
|
+
code: "VIBE_VALIDATION",
|
|
1199
|
+
message: "an SQL identifier cannot contain a NUL character \u2014 the server would stop reading it there and address a different object",
|
|
1200
|
+
meta: { name: params.name.replaceAll("\x00", "\\0") }
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
return params.name;
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1191
1206
|
// packages/sql/src/dialects/postgres.ts
|
|
1192
1207
|
var postgresDialect = {
|
|
1193
1208
|
name: "postgres",
|
|
@@ -1243,7 +1258,7 @@ var postgresDialect = {
|
|
|
1243
1258
|
paramBudget: 30000,
|
|
1244
1259
|
booleanLiteral: { true: "true", false: "false" },
|
|
1245
1260
|
quoteIdent({ name }) {
|
|
1246
|
-
return `"${name.replaceAll('"', '""')}"`;
|
|
1261
|
+
return `"${assertNoNul({ name }).replaceAll('"', '""')}"`;
|
|
1247
1262
|
},
|
|
1248
1263
|
quoteStringLiteral({ value }) {
|
|
1249
1264
|
return `'${value.replaceAll("'", "''")}'`;
|
|
@@ -1294,7 +1309,7 @@ var sqliteDialect = {
|
|
|
1294
1309
|
paramBudget: 900,
|
|
1295
1310
|
booleanLiteral: { true: "1", false: "0" },
|
|
1296
1311
|
quoteIdent({ name }) {
|
|
1297
|
-
return `"${name.replaceAll('"', '""')}"`;
|
|
1312
|
+
return `"${assertNoNul({ name }).replaceAll('"', '""')}"`;
|
|
1298
1313
|
},
|
|
1299
1314
|
quoteStringLiteral({ value }) {
|
|
1300
1315
|
return `'${value.replaceAll("'", "''")}'`;
|
|
@@ -1349,7 +1364,7 @@ var mysqlDialect = {
|
|
|
1349
1364
|
paramBudget: 1e4,
|
|
1350
1365
|
booleanLiteral: { true: "1", false: "0" },
|
|
1351
1366
|
quoteIdent({ name }) {
|
|
1352
|
-
return `\`${name.replaceAll("`", "``")}\``;
|
|
1367
|
+
return `\`${assertNoNul({ name }).replaceAll("`", "``")}\``;
|
|
1353
1368
|
},
|
|
1354
1369
|
quoteStringLiteral({ value }) {
|
|
1355
1370
|
return `'${value.replaceAll("\\", "\\\\").replaceAll("'", "''")}'`;
|
|
@@ -1390,7 +1405,7 @@ function isFixedDiagnostic(params) {
|
|
|
1390
1405
|
}
|
|
1391
1406
|
|
|
1392
1407
|
// packages/sql/src/dialects/postgres-diagnostics.ts
|
|
1393
|
-
import { VibeError as
|
|
1408
|
+
import { VibeError as VibeError7, unsupportedCapability as unsupportedCapability6 } from "@vibeorm/schema";
|
|
1394
1409
|
function renderPostgresExplain(params) {
|
|
1395
1410
|
const { dialect, query, options } = params;
|
|
1396
1411
|
requirePostgres({ dialect, feature: "query plan inspection (EXPLAIN)" });
|
|
@@ -1443,7 +1458,7 @@ function renderPostgresWorkload(params) {
|
|
|
1443
1458
|
if (query === "statementSnapshot") {
|
|
1444
1459
|
const bounded = limit ?? 20;
|
|
1445
1460
|
if (!Number.isInteger(bounded) || bounded < POSTGRES_WORKLOAD_LIMITS.minLimit || bounded > POSTGRES_WORKLOAD_LIMITS.maxLimit) {
|
|
1446
|
-
throw new
|
|
1461
|
+
throw new VibeError7({
|
|
1447
1462
|
code: "VIBE_CONFIG",
|
|
1448
1463
|
message: `workload snapshot limit must be an integer between ${POSTGRES_WORKLOAD_LIMITS.minLimit} and ${POSTGRES_WORKLOAD_LIMITS.maxLimit}, got ${String(limit)}`,
|
|
1449
1464
|
meta: { limit }
|
|
@@ -1462,7 +1477,7 @@ function renderPostgresWorkload(params) {
|
|
|
1462
1477
|
function requireArg(params) {
|
|
1463
1478
|
const { value, name, query } = params;
|
|
1464
1479
|
if (value === undefined || value.length === 0) {
|
|
1465
|
-
throw new
|
|
1480
|
+
throw new VibeError7({
|
|
1466
1481
|
code: "VIBE_CONFIG",
|
|
1467
1482
|
message: `the "${query}" diagnostic read requires a ${name}`,
|
|
1468
1483
|
meta: { query, argument: name }
|
|
@@ -1475,7 +1490,7 @@ function requireArg(params) {
|
|
|
1475
1490
|
import { unsupportedCapability as unsupportedCapability8 } from "@vibeorm/schema";
|
|
1476
1491
|
|
|
1477
1492
|
// packages/sql/src/dialects/postgres-rls.ts
|
|
1478
|
-
import { RlsContextError, VibeError as
|
|
1493
|
+
import { RlsContextError, VibeError as VibeError8, assertValidSchemaIR, unsupportedCapability as unsupportedCapability7, validateRlsContextIR } from "@vibeorm/schema";
|
|
1479
1494
|
var NATIVE_RLS = Object.freeze({ policyName: "vibeorm_managed", tableSchema: "public", settingPrefix: "vibeorm.", parentAlias: "parent" });
|
|
1480
1495
|
var COLUMN_TYPES = {
|
|
1481
1496
|
String: { default: "text", native: { text: "text", varchar: "varchar", charactervarying: "varchar", uuid: "uuid" } },
|
|
@@ -1493,7 +1508,7 @@ function requireRls(params) {
|
|
|
1493
1508
|
}
|
|
1494
1509
|
function identifier2(params) {
|
|
1495
1510
|
if (typeof params.name !== "string" || params.name.length === 0 || params.name.includes("\x00") || new TextEncoder().encode(params.name).length > 63) {
|
|
1496
|
-
throw new
|
|
1511
|
+
throw new VibeError8({ code: "VIBE_SCHEMA_INVALID", message: "Native RLS identifiers must be nonempty PostgreSQL identifiers of at most 63 bytes" });
|
|
1497
1512
|
}
|
|
1498
1513
|
return params.dialect.quoteIdent({ name: params.name });
|
|
1499
1514
|
}
|
|
@@ -1547,7 +1562,7 @@ function protectedModel(params) {
|
|
|
1547
1562
|
assertValidSchemaIR({ schema: params.schema });
|
|
1548
1563
|
const model = params.schema.models.find((entry) => entry.name === params.model);
|
|
1549
1564
|
if (model === undefined || model.rls === undefined || model.rls === "unprotected") {
|
|
1550
|
-
throw new
|
|
1565
|
+
throw new VibeError8({ code: "VIBE_SCHEMA_INVALID", message: "Native RLS policy rendering requires a protected model", meta: { model: params.model } });
|
|
1551
1566
|
}
|
|
1552
1567
|
return model;
|
|
1553
1568
|
}
|
|
@@ -1580,7 +1595,7 @@ function predicate(params) {
|
|
|
1580
1595
|
}).join(" AND ");
|
|
1581
1596
|
return `EXISTS (SELECT 1 FROM ${tableRef({ dialect, table: parent.dbName ?? parent.name })} AS ${alias} WHERE ${join})`;
|
|
1582
1597
|
}
|
|
1583
|
-
throw new
|
|
1598
|
+
throw new VibeError8({ code: "VIBE_SCHEMA_INVALID", message: "Native RLS requires a protected policy rule" });
|
|
1584
1599
|
}
|
|
1585
1600
|
function renderRlsPolicy(params) {
|
|
1586
1601
|
const model = protectedModel(params);
|
|
@@ -1614,7 +1629,7 @@ function renderRlsContext(params) {
|
|
|
1614
1629
|
function renderRlsRole(params) {
|
|
1615
1630
|
requireRls(params);
|
|
1616
1631
|
if (typeof params.role !== "string" || params.role.trim().length === 0 || params.role.includes("\x00")) {
|
|
1617
|
-
throw new
|
|
1632
|
+
throw new VibeError8({ code: "VIBE_CONFIG", message: "PGlite native RLS requires a trusted nonempty runtime role name" });
|
|
1618
1633
|
}
|
|
1619
1634
|
const collector = new ParamCollector(params.dialect);
|
|
1620
1635
|
return query({ text: `SELECT set_config('role', ${collector.add(params.role)}, true)`, values: collector.values });
|
|
@@ -2121,7 +2136,7 @@ function jsonPathString(path) {
|
|
|
2121
2136
|
} else if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(segment)) {
|
|
2122
2137
|
out += `.${segment}`;
|
|
2123
2138
|
} else {
|
|
2124
|
-
out += `."${segment.replaceAll('"', "\\\"")}"`;
|
|
2139
|
+
out += `."${segment.replaceAll("\\", "\\\\").replaceAll('"', "\\\"")}"`;
|
|
2125
2140
|
}
|
|
2126
2141
|
}
|
|
2127
2142
|
return out;
|
|
@@ -2623,7 +2638,7 @@ function renderDelete(params) {
|
|
|
2623
2638
|
return { text: text + returning.suffix, values: collector.values, returning: returning.status };
|
|
2624
2639
|
}
|
|
2625
2640
|
// packages/sql/src/dialects/sqlite-table-definition.ts
|
|
2626
|
-
import { VibeError as
|
|
2641
|
+
import { VibeError as VibeError9 } from "@vibeorm/schema";
|
|
2627
2642
|
function tableDefinitionParts(params) {
|
|
2628
2643
|
const sql = params.sql;
|
|
2629
2644
|
if (!/^\s*CREATE\s+(?:TEMP(?:ORARY)?\s+)?TABLE\b/i.test(sql))
|
|
@@ -2684,7 +2699,7 @@ function tableDefinitionParts(params) {
|
|
|
2684
2699
|
throw unavailable();
|
|
2685
2700
|
}
|
|
2686
2701
|
function unavailable() {
|
|
2687
|
-
return new
|
|
2702
|
+
return new VibeError9({ code: "VIBE_MIGRATION", message: "Cannot preserve table definition", meta: { reason: "table-definition-unavailable" } });
|
|
2688
2703
|
}
|
|
2689
2704
|
function sqliteColumnClauses(params) {
|
|
2690
2705
|
const columns = [];
|
|
@@ -3108,7 +3123,7 @@ function renderCheckProbe(params) {
|
|
|
3108
3123
|
return { text: `ALTER TABLE ${q(params.table.namespace)}.${q(params.table.name)} ADD CONSTRAINT ${q(params.name)} CHECK (${params.expression}) NOT VALID`, values: [], returning: "none" };
|
|
3109
3124
|
}
|
|
3110
3125
|
// packages/sql/src/dialects/postgres-migration.ts
|
|
3111
|
-
import { VibeError as
|
|
3126
|
+
import { VibeError as VibeError10, unsupportedCapability as unsupportedCapability17 } from "@vibeorm/schema";
|
|
3112
3127
|
var SETTING_VALUE = /^[0-9]+(?:\.[0-9]+)?\s*(?:us|ms|s|min|h|d)?$/;
|
|
3113
3128
|
function requirePostgres2(params) {
|
|
3114
3129
|
if (params.dialect.name !== "postgres") {
|
|
@@ -3127,7 +3142,7 @@ function renderMigrationSessionSet(params) {
|
|
|
3127
3142
|
requirePostgres2({ dialect: params.dialect, feature: "migrationSessionSettings" });
|
|
3128
3143
|
const { milliseconds, setting } = params;
|
|
3129
3144
|
if (!Number.isSafeInteger(milliseconds) || milliseconds < 0) {
|
|
3130
|
-
throw new
|
|
3145
|
+
throw new VibeError10({
|
|
3131
3146
|
code: "VIBE_MIGRATION",
|
|
3132
3147
|
message: `${setting} must be a non-negative integer number of milliseconds (got ${String(milliseconds)})`,
|
|
3133
3148
|
meta: { reason: "execution-metadata-invalid", setting, value: milliseconds }
|
|
@@ -3333,4 +3348,4 @@ export {
|
|
|
3333
3348
|
toPgArrayLiteral
|
|
3334
3349
|
};
|
|
3335
3350
|
|
|
3336
|
-
//# debugId=
|
|
3351
|
+
//# debugId=B1F6683E5EF3B96D64756E2164756E21
|