@vertz/db 0.2.18 → 0.2.20
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/index.js
CHANGED
package/dist/internals.js
CHANGED
|
@@ -357,24 +357,22 @@ function isEnumType(col, enums) {
|
|
|
357
357
|
return false;
|
|
358
358
|
}
|
|
359
359
|
function getEnumValues(col, enums) {
|
|
360
|
-
if (!enums)
|
|
361
|
-
return;
|
|
362
360
|
for (const [enumName, values] of Object.entries(enums)) {
|
|
363
361
|
if (col.type.toLowerCase() === enumName.toLowerCase() || col.type === enumName) {
|
|
364
362
|
return values;
|
|
365
363
|
}
|
|
366
364
|
}
|
|
367
|
-
return;
|
|
365
|
+
return [];
|
|
368
366
|
}
|
|
369
367
|
function columnDef(name, col, dialect, enums) {
|
|
370
368
|
const snakeName = camelToSnake(name);
|
|
371
369
|
const isEnum = isEnumType(col, enums);
|
|
372
370
|
let sqlType;
|
|
373
371
|
let checkConstraint;
|
|
374
|
-
if (isEnum && dialect.name === "sqlite") {
|
|
372
|
+
if (isEnum && enums && dialect.name === "sqlite") {
|
|
375
373
|
sqlType = dialect.mapColumnType("text");
|
|
376
374
|
const enumValues = getEnumValues(col, enums);
|
|
377
|
-
if (enumValues
|
|
375
|
+
if (enumValues.length > 0) {
|
|
378
376
|
const escapedValues = enumValues.map((v) => `'${escapeSqlString(v)}'`).join(", ");
|
|
379
377
|
checkConstraint = `CHECK("${snakeName}" IN (${escapedValues}))`;
|
|
380
378
|
}
|
|
@@ -458,7 +456,7 @@ function generateMigrationSql(changes, ctx, dialect = defaultPostgresDialect) {
|
|
|
458
456
|
for (const [, col] of Object.entries(table.columns)) {
|
|
459
457
|
if (isEnumType(col, enums)) {
|
|
460
458
|
const enumValues = getEnumValues(col, enums);
|
|
461
|
-
if (enumValues
|
|
459
|
+
if (enumValues.length > 0) {
|
|
462
460
|
const enumSnakeName = camelToSnake(col.type);
|
|
463
461
|
const alreadyEmitted = statements.some((s) => s.includes(`CREATE TYPE "${enumSnakeName}"`));
|
|
464
462
|
if (!alreadyEmitted) {
|
|
@@ -617,11 +615,6 @@ async function autoMigrate(options) {
|
|
|
617
615
|
console.log("[auto-migrate] No previous snapshot found. Applying full schema...");
|
|
618
616
|
const diff = computeDiff({ version: 1, tables: {}, enums: {} }, currentSchema);
|
|
619
617
|
if (diff.changes.length > 0) {
|
|
620
|
-
for (const change of diff.changes) {
|
|
621
|
-
if (isDestructiveChange(change)) {
|
|
622
|
-
console.warn(`[auto-migrate] Warning: Destructive change detected on first run: ${change.type}`);
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
618
|
const sql = generateMigrationSql(diff.changes, {
|
|
626
619
|
tables: currentSchema.tables,
|
|
627
620
|
enums: currentSchema.enums
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vertz/db",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Database layer for Vertz — typed queries, migrations, codegen",
|
|
@@ -81,8 +81,8 @@
|
|
|
81
81
|
"node": ">=22"
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"@vertz/errors": "^0.2.
|
|
85
|
-
"@vertz/schema": "^0.2.
|
|
84
|
+
"@vertz/errors": "^0.2.18",
|
|
85
|
+
"@vertz/schema": "^0.2.18",
|
|
86
86
|
"@paralleldrive/cuid2": "^3.3.0",
|
|
87
87
|
"nanoid": "^5.1.5",
|
|
88
88
|
"uuid": "^13.0.0"
|