rake-db 2.36.19 → 2.37.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/dist/bun.js.map +1 -1
- package/dist/bun.mjs.map +1 -1
- package/dist/index.d.ts +94 -39
- package/dist/index.js +119 -44
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +119 -45
- package/dist/index.mjs.map +1 -1
- package/dist/node-postgres.js.map +1 -1
- package/dist/node-postgres.mjs.map +1 -1
- package/dist/postgres-js.js.map +1 -1
- package/dist/postgres-js.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ArrayColumn, Column, CustomTypeColumn, DomainColumn, EnumColumn, PostgisGeographyPointColumn, RawSql, TimestampColumn, TimestampTZColumn, UnknownColumn, addCode, assignDbDataToColumn, backtickQuote, codeToString, colors, constraintInnerToCode, consumeColumnName, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getColumnTypes, getDriverErrorCode, getImportPath, getStackTrace, indexInnerToCode, isRawSQL, logParamToLogObject, makeColumnTypes, makeColumnsByType, parseTableData, parseTableDataInput, pathToLog, primaryKeyInnerToCode, pushTableDataCode, quoteIdentifier, quoteObjectKey, raw, rawSqlToCode, referencesArgsToCode, setCurrentColumnName, setDefaultLanguage, singleQuote, tableDataMethods, toArray, toCamelCase, toSnakeCase } from "pqb/internal";
|
|
1
|
+
import { ArrayColumn, Column, CustomTypeColumn, DomainColumn, EnumColumn, PostgisGeographyPointColumn, RawSql, TimestampColumn, TimestampTZColumn, UnknownColumn, addCode, assignDbDataToColumn, backtickQuote, codeToString, colors, constraintInnerToCode, consumeColumnName, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getColumnTypes, getDriverErrorCode, getForeignKeyTableInstance, getImportPath, getStackTrace, indexInnerToCode, isRawSQL, logParamToLogObject, makeColumnTypes, makeColumnsByType, parseTableData, parseTableDataInput, pathToLog, primaryKeyInnerToCode, pushTableDataCode, quoteIdentifier, quoteObjectKey, raw, rawSqlToCode, referencesArgsToCode, setCurrentColumnName, setDefaultLanguage, singleQuote, tableDataMethods, toArray, toCamelCase, toSnakeCase } from "pqb/internal";
|
|
2
2
|
import path, { join } from "node:path";
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
4
|
import { createDbWithAdapter } from "pqb";
|
|
@@ -182,7 +182,7 @@ const addColumnComment = (comments, name, item) => {
|
|
|
182
182
|
};
|
|
183
183
|
const getForeignKeyTable = (schema, fnOrTable) => {
|
|
184
184
|
if (typeof fnOrTable === "string") return getSchemaAndTableFromName(schema, fnOrTable);
|
|
185
|
-
const item =
|
|
185
|
+
const item = getForeignKeyTableInstance(fnOrTable());
|
|
186
186
|
return [item.schema, item.table];
|
|
187
187
|
};
|
|
188
188
|
const getConstraintName = (table, constraint, snakeCase) => {
|
|
@@ -371,7 +371,8 @@ const primaryKeyToSql = (primaryKey) => {
|
|
|
371
371
|
};
|
|
372
372
|
const interpolateSqlValues = ({ text, values }) => {
|
|
373
373
|
return values?.length ? text.replace(/\$(\d+)/g, (_, n) => {
|
|
374
|
-
|
|
374
|
+
const i = +n - 1;
|
|
375
|
+
return escapeForMigration(values[i]);
|
|
375
376
|
}) : text;
|
|
376
377
|
};
|
|
377
378
|
const nameColumnChecks = (table, column, checks) => checks.map((check, i) => ({
|
|
@@ -409,6 +410,33 @@ const migrationsSchemaTableSql = (adapter, config) => {
|
|
|
409
410
|
};
|
|
410
411
|
var RakeDbError = class extends Error {};
|
|
411
412
|
var NoPrimaryKey = class extends RakeDbError {};
|
|
413
|
+
const getTableFactoryConfig = ({ baseTable, defineTable }) => {
|
|
414
|
+
if (baseTable && defineTable) throw new Error("Configure either baseTable or defineTable, not both");
|
|
415
|
+
if (defineTable) {
|
|
416
|
+
if (!defineTable.types) throw new Error("defineTable is missing types");
|
|
417
|
+
if (!defineTable.exportAs) throw new Error("defineTable is missing exportAs");
|
|
418
|
+
if (typeof defineTable.getFilePath !== "function") throw new Error("defineTable is missing getFilePath");
|
|
419
|
+
return {
|
|
420
|
+
columnTypes: defineTable.types,
|
|
421
|
+
exportAs: defineTable.exportAs,
|
|
422
|
+
getFilePath: defineTable.getFilePath,
|
|
423
|
+
nowSQL: defineTable.nowSQL,
|
|
424
|
+
snakeCase: defineTable.snakeCase,
|
|
425
|
+
language: defineTable.language
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
if (baseTable) {
|
|
429
|
+
const { types, snakeCase, language } = baseTable.prototype || {};
|
|
430
|
+
return {
|
|
431
|
+
columnTypes: types,
|
|
432
|
+
exportAs: baseTable.exportAs,
|
|
433
|
+
getFilePath: baseTable.getFilePath,
|
|
434
|
+
nowSQL: baseTable.nowSQL,
|
|
435
|
+
snakeCase,
|
|
436
|
+
language
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
};
|
|
412
440
|
const createTable$1 = async (migration, tableMethods, up, tableName, first, second, third) => {
|
|
413
441
|
let options;
|
|
414
442
|
let fn;
|
|
@@ -428,7 +456,8 @@ const createTable$1 = async (migration, tableMethods, up, tableName, first, seco
|
|
|
428
456
|
let shape;
|
|
429
457
|
let tableData;
|
|
430
458
|
if (fn) {
|
|
431
|
-
|
|
459
|
+
const tableFactory = getTableFactoryConfig(migration.options);
|
|
460
|
+
shape = getColumnTypes(types, fn, tableFactory?.nowSQL, language);
|
|
432
461
|
tableData = parseTableData(dataFn);
|
|
433
462
|
tableData.constraints?.forEach((x, i) => {
|
|
434
463
|
if (x.name || !x.check) return;
|
|
@@ -465,7 +494,7 @@ const makeAst$5 = (schema, up, tableName, shape, tableData, options, noPrimaryKe
|
|
|
465
494
|
...tableData,
|
|
466
495
|
primaryKey: shapePKeys.length <= 1 ? primaryKey : primaryKey ? {
|
|
467
496
|
...primaryKey,
|
|
468
|
-
columns: [
|
|
497
|
+
columns: [.../* @__PURE__ */ new Set([...shapePKeys, ...primaryKey.columns])]
|
|
469
498
|
} : { columns: shapePKeys },
|
|
470
499
|
...options,
|
|
471
500
|
noPrimaryKey: options.noPrimaryKey ? "ignore" : noPrimaryKey || "error"
|
|
@@ -851,6 +880,25 @@ const makeTableChangeMethods = (tableMethods) => ({
|
|
|
851
880
|
to: { comment }
|
|
852
881
|
};
|
|
853
882
|
},
|
|
883
|
+
/**
|
|
884
|
+
* Rename a column:
|
|
885
|
+
*
|
|
886
|
+
* ```ts
|
|
887
|
+
* import { change } from '../dbScript';
|
|
888
|
+
*
|
|
889
|
+
* change(async (db) => {
|
|
890
|
+
* await db.changeTable('table', (t) => ({
|
|
891
|
+
* oldColumnName: t.rename('newColumnName'),
|
|
892
|
+
* }));
|
|
893
|
+
* });
|
|
894
|
+
* ```
|
|
895
|
+
*
|
|
896
|
+
* Note that the renaming `ALTER TABLE` is executed before the rest of alterations,
|
|
897
|
+
* so if you're also adding a new constraint on this column inside the same `changeTable`,
|
|
898
|
+
* refer to it with a new name.
|
|
899
|
+
*
|
|
900
|
+
* @param name
|
|
901
|
+
*/
|
|
854
902
|
rename(name) {
|
|
855
903
|
return {
|
|
856
904
|
type: "rename",
|
|
@@ -869,7 +917,8 @@ const changeTable = async (migration, tableChangeMethods, up, tableName, options
|
|
|
869
917
|
standaloneCheckChanges.length = 0;
|
|
870
918
|
const changeData = fn?.(tableChanger) || {};
|
|
871
919
|
const schema = migration.adapter.getSchema();
|
|
872
|
-
const
|
|
920
|
+
const ast = makeAst$4(schema, up, tableName, changeData, changeTableData, options);
|
|
921
|
+
const queries = astToQueries(schema, ast, snakeCase, language);
|
|
873
922
|
for (const query of queries) {
|
|
874
923
|
const result = await migration.adapter.arrays(interpolateSqlValues(query));
|
|
875
924
|
query.then?.(result);
|
|
@@ -1148,7 +1197,9 @@ const renameColumnSql = (from, to) => {
|
|
|
1148
1197
|
return `RENAME COLUMN "${from}" TO "${to}"`;
|
|
1149
1198
|
};
|
|
1150
1199
|
const createView = async (migration, up, name, options, sql) => {
|
|
1151
|
-
const
|
|
1200
|
+
const schema = migration.adapter.getSchema();
|
|
1201
|
+
const ast = makeAst$3(schema, up, name, options, sql);
|
|
1202
|
+
const query = astToQuery$2(ast);
|
|
1152
1203
|
await migration.adapter.arrays(interpolateSqlValues(query));
|
|
1153
1204
|
};
|
|
1154
1205
|
const makeAst$3 = (schema, up, fullName, options, sql) => {
|
|
@@ -1195,12 +1246,15 @@ const astToQuery$2 = (ast) => {
|
|
|
1195
1246
|
};
|
|
1196
1247
|
};
|
|
1197
1248
|
const createMaterializedView = async (migration, up, name, options, sql) => {
|
|
1198
|
-
const
|
|
1249
|
+
const schema = migration.adapter.getSchema();
|
|
1250
|
+
const ast = makeAst$2(schema, up, name, options, sql);
|
|
1251
|
+
const query = astToQuery$1(ast);
|
|
1199
1252
|
await migration.adapter.arrays(interpolateSqlValues(query));
|
|
1200
1253
|
};
|
|
1201
1254
|
const refreshMaterializedView = async (migration, name, options = {}) => {
|
|
1202
1255
|
if (options.concurrently && options.withData === false) throw new Error("Cannot refresh a materialized view concurrently with WITH NO DATA");
|
|
1203
|
-
const
|
|
1256
|
+
const schema = migration.adapter.getSchema();
|
|
1257
|
+
const [s, viewName] = getSchemaAndTableFromName(schema, name);
|
|
1204
1258
|
const sql = ["REFRESH MATERIALIZED VIEW"];
|
|
1205
1259
|
if (options.concurrently) sql.push("CONCURRENTLY");
|
|
1206
1260
|
sql.push(`${s ? `"${s}".` : ""}"${viewName}"`);
|
|
@@ -1258,7 +1312,8 @@ const serializers = {
|
|
|
1258
1312
|
validUntil: (value) => `VALID UNTIL '${value === void 0 ? "infinity" : value}'`
|
|
1259
1313
|
};
|
|
1260
1314
|
const createOrDropRole = async (migration, up, name, params) => {
|
|
1261
|
-
const
|
|
1315
|
+
const ast = makeAst$1(up, name, params);
|
|
1316
|
+
const sql = astToQuery(ast);
|
|
1262
1317
|
await migration.adapter.arrays(sql);
|
|
1263
1318
|
};
|
|
1264
1319
|
const makeAst$1 = (up, name, params) => {
|
|
@@ -1310,7 +1365,8 @@ const changeRole = async (migration, up, name, from, to) => {
|
|
|
1310
1365
|
for (const key in from.config) if (!(key in config)) config[key] = void 0;
|
|
1311
1366
|
}
|
|
1312
1367
|
}
|
|
1313
|
-
const
|
|
1368
|
+
const ast = makeChangeAst(name, from, to);
|
|
1369
|
+
const sql = changeAstToQuery(ast);
|
|
1314
1370
|
if (sql) await migration.adapter.arrays(sql);
|
|
1315
1371
|
};
|
|
1316
1372
|
const makeChangeAst = (name, from, to) => {
|
|
@@ -1349,7 +1405,8 @@ const renameRole = async (migration, up, from, to) => {
|
|
|
1349
1405
|
from = to;
|
|
1350
1406
|
to = f;
|
|
1351
1407
|
}
|
|
1352
|
-
const
|
|
1408
|
+
const ast = makeRenameAst(from, to);
|
|
1409
|
+
const sql = renameAstToQuery(ast);
|
|
1353
1410
|
if (sql) await migration.adapter.arrays(sql);
|
|
1354
1411
|
};
|
|
1355
1412
|
const makeRenameAst = (from, to) => ({
|
|
@@ -1401,7 +1458,8 @@ const filterAndTransformConfig = (config, schema) => {
|
|
|
1401
1458
|
return Object.keys(result).length ? result : void 0;
|
|
1402
1459
|
};
|
|
1403
1460
|
const changeDefaultPrivileges = async (migration, up, arg) => {
|
|
1404
|
-
const
|
|
1461
|
+
const ast = makeAst(up, arg);
|
|
1462
|
+
const sql = astToSql(ast);
|
|
1405
1463
|
if (sql.length) await migration.adapter.arrays(sql.join(";\n"));
|
|
1406
1464
|
};
|
|
1407
1465
|
const makeAst = (up, arg) => {
|
|
@@ -1554,7 +1612,9 @@ const recreatePolicy = async (migration, tableName, policyName, from, to) => {
|
|
|
1554
1612
|
const fromTable = from.table ?? tableName;
|
|
1555
1613
|
const fromName = from.name ?? policyName;
|
|
1556
1614
|
await migration.adapter.arrays(dropPolicySql(migration, fromTable, fromName));
|
|
1557
|
-
const
|
|
1615
|
+
const toTable = to.table ?? tableName;
|
|
1616
|
+
const toName = to.name ?? policyName;
|
|
1617
|
+
const { text, values } = createPolicySql(migration, toTable, toName, to);
|
|
1558
1618
|
await migration.adapter.arrays(text, values);
|
|
1559
1619
|
};
|
|
1560
1620
|
const changePolicy = async (migration, up, tableName, policyName, params) => {
|
|
@@ -1582,18 +1642,19 @@ const schemaOrDatabaseTargetKeyToSql = {
|
|
|
1582
1642
|
schemas: "SCHEMA",
|
|
1583
1643
|
databases: "DATABASE"
|
|
1584
1644
|
};
|
|
1585
|
-
const specialRoleSpecs = new Set([
|
|
1645
|
+
const specialRoleSpecs = /* @__PURE__ */ new Set([
|
|
1586
1646
|
"PUBLIC",
|
|
1587
1647
|
"CURRENT_ROLE",
|
|
1588
1648
|
"CURRENT_USER",
|
|
1589
1649
|
"SESSION_USER"
|
|
1590
1650
|
]);
|
|
1591
1651
|
const changeGrant = async (migration, up, params) => {
|
|
1592
|
-
const
|
|
1652
|
+
const ast = {
|
|
1593
1653
|
...params,
|
|
1594
1654
|
to: typeof params.to === "string" ? [params.to] : params.to,
|
|
1595
1655
|
action: up ? "grant" : "revoke"
|
|
1596
|
-
}
|
|
1656
|
+
};
|
|
1657
|
+
const sql = privilegeToSql(migration, ast);
|
|
1597
1658
|
if (sql.length) await migration.adapter.arrays(sql.join(";\n"));
|
|
1598
1659
|
};
|
|
1599
1660
|
const privilegeToSql = (migration, ast) => {
|
|
@@ -1718,7 +1779,10 @@ const createMigrationInterface = (tx, up, config) => {
|
|
|
1718
1779
|
var Migration = class {
|
|
1719
1780
|
getTableMethods() {
|
|
1720
1781
|
let { tableMethods } = this;
|
|
1721
|
-
if (!tableMethods)
|
|
1782
|
+
if (!tableMethods) {
|
|
1783
|
+
const schemaConfig = defaultSchemaConfig();
|
|
1784
|
+
tableMethods = makeTableMethods(schemaConfig);
|
|
1785
|
+
}
|
|
1722
1786
|
return tableMethods;
|
|
1723
1787
|
}
|
|
1724
1788
|
getTableChangeMethods() {
|
|
@@ -2799,7 +2863,8 @@ const addOrDropEnumValues = async (migration, up, enumName, values, options) =>
|
|
|
2799
2863
|
return;
|
|
2800
2864
|
}
|
|
2801
2865
|
const { rows: valuesRows } = await migration.adapter.query(`SELECT unnest(enum_range(NULL::${quotedName}))::text value`);
|
|
2802
|
-
|
|
2866
|
+
const existingValues = valuesRows.map((r) => r.value);
|
|
2867
|
+
await recreateEnum(migration, ast, existingValues.filter((v) => !ast.values.includes(v)), (quotedName, table, column) => `Cannot drop ${quotedName} enum values [${ast.values.map(singleQuote).join(", ")}]: table ${table} has a row with such value in the column "${column}"`);
|
|
2803
2868
|
};
|
|
2804
2869
|
const changeEnumValues = async (migration, enumName, fromValues, toValues) => {
|
|
2805
2870
|
const [schema, name] = getSchemaAndTableFromName(migration.adapter.getSchema(), enumName);
|
|
@@ -2856,11 +2921,13 @@ GROUP BY n.nspname, c.relname`);
|
|
|
2856
2921
|
const writeMigrationFile = async (config, version, name, migrationCode) => {
|
|
2857
2922
|
await mkdir(config.migrationsPath, { recursive: true });
|
|
2858
2923
|
const filePath = path.resolve(config.migrationsPath, `${version}_${name.replaceAll(" ", "-")}.ts`);
|
|
2859
|
-
|
|
2924
|
+
const importPath = getImportPath(filePath, path.join(config.basePath, config.dbScript));
|
|
2925
|
+
await writeFile(filePath, `import { change } from '${importPath}';\n${migrationCode}`);
|
|
2860
2926
|
config.logger?.log(`Created ${pathToLog(filePath)}`);
|
|
2861
2927
|
};
|
|
2862
2928
|
const newMigration = async (config, name) => {
|
|
2863
|
-
|
|
2929
|
+
const version = await makeFileVersion({}, config);
|
|
2930
|
+
await writeMigrationFile(config, version, name, makeContent(name));
|
|
2864
2931
|
};
|
|
2865
2932
|
const makeFileVersion = async (ctx, config) => {
|
|
2866
2933
|
if (config.migrationId === "timestamp") return generateTimeStamp();
|
|
@@ -3175,7 +3242,8 @@ const saveMigratedVersion = async (db, version, name, config) => {
|
|
|
3175
3242
|
await db.silentArrays(`INSERT INTO ${migrationsSchemaTableSql(db, config)}(version, name) VALUES ($1, $2)`, [version, name]);
|
|
3176
3243
|
};
|
|
3177
3244
|
const createMigrationsSchemaAndTable = async (db, config) => {
|
|
3178
|
-
const
|
|
3245
|
+
const adapter = getMaybeTransactionAdapter(db);
|
|
3246
|
+
const { schema, table } = getMigrationsSchemaAndTable(adapter, config);
|
|
3179
3247
|
if (schema) {
|
|
3180
3248
|
if (await createSchema(db, schema) === "done") config.logger?.log(`Created schema "${schema}"`);
|
|
3181
3249
|
}
|
|
@@ -3267,10 +3335,10 @@ const processMigrateConfig = (config, db) => {
|
|
|
3267
3335
|
migrationsPath,
|
|
3268
3336
|
...handleConfigLogger(config, db)
|
|
3269
3337
|
};
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
if (snakeCase) result.snakeCase = true;
|
|
3273
|
-
if (language) result.language = language;
|
|
3338
|
+
const tableFactory = getTableFactoryConfig(config);
|
|
3339
|
+
if (tableFactory) {
|
|
3340
|
+
if (tableFactory.snakeCase) result.snakeCase = true;
|
|
3341
|
+
if (tableFactory.language) result.language = tableFactory.language;
|
|
3274
3342
|
}
|
|
3275
3343
|
return result;
|
|
3276
3344
|
};
|
|
@@ -3288,12 +3356,14 @@ function makeMigrateFn(up, defaultCount, fn) {
|
|
|
3288
3356
|
let migrations;
|
|
3289
3357
|
try {
|
|
3290
3358
|
await transactionIfSingle(adapter, config, async (trx) => {
|
|
3291
|
-
|
|
3359
|
+
const versions = await getMigratedVersionsMap(ctx, trx, config, set.renameTo);
|
|
3360
|
+
migrations = await fn(trx, config, set, versions, count, force);
|
|
3292
3361
|
});
|
|
3293
3362
|
} catch (err) {
|
|
3294
3363
|
if (err instanceof NoMigrationsTableError) await transactionIfSingle(adapter, config, async (trx) => {
|
|
3295
3364
|
await createMigrationsSchemaAndTable(trx, config);
|
|
3296
|
-
|
|
3365
|
+
const versions = await getMigratedVersionsMap(ctx, trx, config, set.renameTo);
|
|
3366
|
+
migrations = await fn(trx, config, set, versions, count, force);
|
|
3297
3367
|
});
|
|
3298
3368
|
else throw err;
|
|
3299
3369
|
}
|
|
@@ -3329,9 +3399,11 @@ async function runMigration(db, ...args) {
|
|
|
3329
3399
|
...rawConfig,
|
|
3330
3400
|
...handleConfigLogger(rawConfig)
|
|
3331
3401
|
};
|
|
3332
|
-
|
|
3402
|
+
const adapter = getMaybeTransactionAdapter(db);
|
|
3403
|
+
await transaction(adapter, config, async (trx) => {
|
|
3333
3404
|
clearChanges();
|
|
3334
|
-
|
|
3405
|
+
const changes = await getChanges({ load: migration });
|
|
3406
|
+
await applyMigration(trx, true, changes, config);
|
|
3335
3407
|
});
|
|
3336
3408
|
}
|
|
3337
3409
|
/**
|
|
@@ -3414,7 +3486,8 @@ const migrateOrRollback = async (trx, config, set, versions, count, up, redo, fo
|
|
|
3414
3486
|
loggedAboutStarting = true;
|
|
3415
3487
|
config.logger?.log(`${redo ? "Reapplying migrations for" : up ? "Migrating" : "Rolling back"} database ${getAdapterDatabase$1(trx)}\n`);
|
|
3416
3488
|
}
|
|
3417
|
-
|
|
3489
|
+
const adapter = await migrationRunner(trx, up, await getChanges(file, config), config);
|
|
3490
|
+
await changeMigratedVersion(adapter, up, file, config);
|
|
3418
3491
|
(migrations ??= []).push(file);
|
|
3419
3492
|
if (up) {
|
|
3420
3493
|
const name = path.basename(file.path);
|
|
@@ -3795,11 +3868,12 @@ const astToGenerateItem = (config, ast, currentSchema) => {
|
|
|
3795
3868
|
const keys = ast.action === "create" ? add : drop;
|
|
3796
3869
|
keys.push(table);
|
|
3797
3870
|
deps.push(schema);
|
|
3798
|
-
|
|
3871
|
+
const columns = Object.entries(ast.shape).map(([name, column]) => [
|
|
3799
3872
|
keys,
|
|
3800
3873
|
name,
|
|
3801
3874
|
{ column }
|
|
3802
|
-
])
|
|
3875
|
+
]);
|
|
3876
|
+
analyzeTableColumns(config, currentSchema, schema, table, deps, resolveType, columns);
|
|
3803
3877
|
if (ast.type === "table") analyzeTableData(config, currentSchema, schema, table, keys, deps, ast);
|
|
3804
3878
|
else deps.push(...ast.deps.map(({ schemaName, name }) => `${schemaName}.${name}`));
|
|
3805
3879
|
} else {
|
|
@@ -5659,9 +5733,7 @@ const viewToAst = (ctx, data, domains, view) => {
|
|
|
5659
5733
|
case "securityBarrier":
|
|
5660
5734
|
options.securityBarrier = value === "true";
|
|
5661
5735
|
break;
|
|
5662
|
-
case "securityInvoker":
|
|
5663
|
-
options.securityInvoker = value === "true";
|
|
5664
|
-
break;
|
|
5736
|
+
case "securityInvoker": options.securityInvoker = value === "true";
|
|
5665
5737
|
}
|
|
5666
5738
|
}
|
|
5667
5739
|
return {
|
|
@@ -5809,14 +5881,16 @@ const checkIfIsOuterRecursiveFkey = (data, table, references) => {
|
|
|
5809
5881
|
const pullDbStructure = async (adapter, config) => {
|
|
5810
5882
|
const currentSchema = adapter.getSearchPath?.() ?? adapter.searchPath ?? "public";
|
|
5811
5883
|
const ctx = makeStructureToAstCtx(config, currentSchema);
|
|
5812
|
-
const
|
|
5884
|
+
const ast = await structureToAst(ctx, adapter, config);
|
|
5885
|
+
const result = astToMigration(currentSchema, config, ast);
|
|
5813
5886
|
if (!result) return;
|
|
5814
5887
|
const version = await makeFileVersion({}, config);
|
|
5815
5888
|
await writeMigrationFile(config, version, "pull", result);
|
|
5816
|
-
|
|
5889
|
+
const silentQueries = Object.assign(adapter, {
|
|
5817
5890
|
silentQuery: adapter.query,
|
|
5818
5891
|
silentArrays: adapter.arrays
|
|
5819
|
-
})
|
|
5892
|
+
});
|
|
5893
|
+
await saveMigratedVersion(silentQueries, version, "pull", config);
|
|
5820
5894
|
const unsupportedEntries = Object.entries(ctx.unsupportedTypes);
|
|
5821
5895
|
if (unsupportedEntries.length) {
|
|
5822
5896
|
let count = 0;
|
|
@@ -6066,7 +6140,8 @@ const rakeDbCommands = {
|
|
|
6066
6140
|
},
|
|
6067
6141
|
status: {
|
|
6068
6142
|
run(adapters, config, args) {
|
|
6069
|
-
|
|
6143
|
+
const showUrl = args.includes("p") || args.includes("path");
|
|
6144
|
+
return listMigrationsStatuses(adapters, config, { showUrl });
|
|
6070
6145
|
},
|
|
6071
6146
|
help: "list migrations statuses",
|
|
6072
6147
|
helpArguments: {
|
|
@@ -6125,6 +6200,7 @@ const ensureBasePathAndDbScript = (config, intermediateCallers = 0) => {
|
|
|
6125
6200
|
const makeRakeDbConfig = (config, args) => {
|
|
6126
6201
|
const ic = intermediateCallers;
|
|
6127
6202
|
intermediateCallers = 0;
|
|
6203
|
+
const tableFactory = getTableFactoryConfig(config);
|
|
6128
6204
|
const result = {
|
|
6129
6205
|
...rakeDbConfigDefaults,
|
|
6130
6206
|
...config,
|
|
@@ -6134,10 +6210,8 @@ const makeRakeDbConfig = (config, args) => {
|
|
|
6134
6210
|
Object.assign(result, processMigrateConfig(result));
|
|
6135
6211
|
if (!result.recurrentPath && result.migrationsPath) result.recurrentPath = path.join(result.migrationsPath, "recurrent");
|
|
6136
6212
|
if (result.recurrentPath && !path.isAbsolute(result.recurrentPath)) result.recurrentPath = path.resolve(result.basePath, result.recurrentPath);
|
|
6137
|
-
if (
|
|
6138
|
-
|
|
6139
|
-
result.columnTypes = types || makeColumnTypes(defaultSchemaConfig());
|
|
6140
|
-
} else {
|
|
6213
|
+
if (tableFactory) result.columnTypes = tableFactory.columnTypes || makeColumnTypes(defaultSchemaConfig());
|
|
6214
|
+
else {
|
|
6141
6215
|
const ct = "columnTypes" in config && config.columnTypes;
|
|
6142
6216
|
result.columnTypes = (typeof ct === "function" ? ct(makeColumnTypes(defaultSchemaConfig())) : ct) || makeColumnTypes(defaultSchemaConfig());
|
|
6143
6217
|
}
|
|
@@ -6245,6 +6319,6 @@ ${commandsHelp.map(([key, help, helpArguments]) => {
|
|
|
6245
6319
|
`);
|
|
6246
6320
|
}
|
|
6247
6321
|
};
|
|
6248
|
-
export { RakeDbError, astToMigration, concatSchemaAndName, createDatabase, createMigrationChangeFn, createMigrationInterface, createMigrationsSchemaAndTable, createSchema, createTable, dbColumnToAst, dropDatabase, dropSchema, dropTable, encodeColumnDefault, getConstraintName, getDbStructureTableData, getDbTableColumnsChecks, getDbVersion, getExcludeName, getIndexName, getMigrationsSchemaAndTable, getSchemaAndTableFromName, incrementIntermediateCaller, instantiateDbColumn, introspectDbSchema, makeDomainsMap, makeFileVersion, makeStructureToAstCtx, migrate, migrateAndClose, promptSelect, rakeDbCliWithAdapter, rakeDbCommands, rakeDbConfigDefaults, redo, rollback, runMigration, saveMigratedVersion, setRakeDbCliRunFn, structureToAst, tableToAst, writeMigrationFile };
|
|
6322
|
+
export { RakeDbError, astToMigration, concatSchemaAndName, createDatabase, createMigrationChangeFn, createMigrationInterface, createMigrationsSchemaAndTable, createSchema, createTable, dbColumnToAst, dropDatabase, dropSchema, dropTable, encodeColumnDefault, getConstraintName, getDbStructureTableData, getDbTableColumnsChecks, getDbVersion, getExcludeName, getIndexName, getMigrationsSchemaAndTable, getSchemaAndTableFromName, getTableFactoryConfig, incrementIntermediateCaller, instantiateDbColumn, introspectDbSchema, makeDomainsMap, makeFileVersion, makeStructureToAstCtx, migrate, migrateAndClose, promptSelect, rakeDbCliWithAdapter, rakeDbCommands, rakeDbConfigDefaults, redo, rollback, runMigration, saveMigratedVersion, setRakeDbCliRunFn, structureToAst, tableToAst, writeMigrationFile };
|
|
6249
6323
|
|
|
6250
6324
|
//# sourceMappingURL=index.mjs.map
|