rake-db 2.35.1 → 2.36.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.d.ts +5 -0
- package/dist/bun.js +24 -0
- package/dist/bun.js.map +1 -0
- package/dist/bun.mjs +23 -0
- package/dist/bun.mjs.map +1 -0
- package/dist/index.d.ts +7 -5
- package/dist/index.js +69 -70
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +70 -71
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -3
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, 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, 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";
|
|
@@ -77,11 +77,10 @@ const getCliParam = (args, name) => {
|
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
const createMigrationChangeFn = (config) => {
|
|
80
|
-
const conf = config.columnTypes ? config : { columnTypes: makeColumnTypes(defaultSchemaConfig) };
|
|
81
80
|
return (fn) => {
|
|
82
81
|
const change = {
|
|
83
82
|
fn,
|
|
84
|
-
config
|
|
83
|
+
config
|
|
85
84
|
};
|
|
86
85
|
pushChange(change);
|
|
87
86
|
return change;
|
|
@@ -126,9 +125,15 @@ const columnToSql = (schema, name, item, values, hasMultiplePrimaryKeys, snakeCa
|
|
|
126
125
|
}
|
|
127
126
|
return line.join(" ");
|
|
128
127
|
};
|
|
128
|
+
const getDefaultEncode = (column) => {
|
|
129
|
+
return column.data.encode ?? (column.dataType === "jsonb" ? JSON.stringify : void 0);
|
|
130
|
+
};
|
|
129
131
|
const encodeColumnDefault = (def, values, column) => {
|
|
130
132
|
if (def !== void 0 && def !== null && typeof def !== "function") if (isRawSQL(def)) return `(${def.toSQL({ values })})`;
|
|
131
|
-
else
|
|
133
|
+
else {
|
|
134
|
+
let encode;
|
|
135
|
+
return escapeForMigration(column instanceof ArrayColumn && Array.isArray(def) ? "{" + ((encode = getDefaultEncode(column.data.item)) ? def.map((x) => encode(x)) : def).join(",") + "}" : column && (encode = getDefaultEncode(column)) ? encode(def) : def);
|
|
136
|
+
}
|
|
132
137
|
return null;
|
|
133
138
|
};
|
|
134
139
|
const identityToSql = (schema, identity) => {
|
|
@@ -370,12 +375,9 @@ const migrationsSchemaTableSql = (adapter, config) => {
|
|
|
370
375
|
const { schema, table } = getMigrationsSchemaAndTable(adapter, config);
|
|
371
376
|
return `${schema ? `"${schema}".` : ""}"${table}"`;
|
|
372
377
|
};
|
|
373
|
-
const tableMethods = { enum(name) {
|
|
374
|
-
return new EnumColumn(defaultSchemaConfig, name, [], void 0);
|
|
375
|
-
} };
|
|
376
378
|
var RakeDbError = class extends Error {};
|
|
377
379
|
var NoPrimaryKey = class extends RakeDbError {};
|
|
378
|
-
const createTable$1 = async (migration, up, tableName, first, second, third) => {
|
|
380
|
+
const createTable$1 = async (migration, tableMethods, up, tableName, first, second, third) => {
|
|
379
381
|
let options;
|
|
380
382
|
let fn;
|
|
381
383
|
let dataFn;
|
|
@@ -763,7 +765,7 @@ function exclude(...args) {
|
|
|
763
765
|
options: { ...options }
|
|
764
766
|
} };
|
|
765
767
|
}
|
|
766
|
-
const
|
|
768
|
+
const makeTableChangeMethods = (tableMethods) => ({
|
|
767
769
|
...tableMethods,
|
|
768
770
|
...tableDataMethods,
|
|
769
771
|
name(name) {
|
|
@@ -823,8 +825,8 @@ const tableChangeMethods = {
|
|
|
823
825
|
name
|
|
824
826
|
};
|
|
825
827
|
}
|
|
826
|
-
};
|
|
827
|
-
const changeTable = async (migration, up, tableName, options, fn) => {
|
|
828
|
+
});
|
|
829
|
+
const changeTable = async (migration, tableChangeMethods, up, tableName, options, fn) => {
|
|
828
830
|
const snakeCase = "snakeCase" in options ? options.snakeCase : migration.options.snakeCase;
|
|
829
831
|
const language = "language" in options ? options.language : migration.options.language;
|
|
830
832
|
setDefaultLanguage(language);
|
|
@@ -1579,6 +1581,9 @@ const buildQuery = (ast, privileges, targetSql, grantable, isRevoke) => {
|
|
|
1579
1581
|
const formatRoleSpec = (role) => {
|
|
1580
1582
|
return specialRoleSpecs.has(role) ? role : `"${role}"`;
|
|
1581
1583
|
};
|
|
1584
|
+
const makeTableMethods = (schemaConfig) => ({ enum(name) {
|
|
1585
|
+
return new EnumColumn(schemaConfig, name, [], void 0);
|
|
1586
|
+
} });
|
|
1582
1587
|
/**
|
|
1583
1588
|
* Creates a new `db` instance that is an instance of `pqb` with mixed in migration methods from the `Migration` class.
|
|
1584
1589
|
* It overrides `query` and `array` db adapter methods to intercept SQL for the logging.
|
|
@@ -1628,15 +1633,25 @@ const createMigrationInterface = (tx, up, config) => {
|
|
|
1628
1633
|
};
|
|
1629
1634
|
};
|
|
1630
1635
|
var Migration = class {
|
|
1636
|
+
getTableMethods() {
|
|
1637
|
+
let { tableMethods } = this;
|
|
1638
|
+
if (!tableMethods) tableMethods = makeTableMethods(defaultSchemaConfig());
|
|
1639
|
+
return tableMethods;
|
|
1640
|
+
}
|
|
1641
|
+
getTableChangeMethods() {
|
|
1642
|
+
let { tableChangeMethods } = this;
|
|
1643
|
+
if (!tableChangeMethods) tableChangeMethods = makeTableChangeMethods(this.getTableMethods());
|
|
1644
|
+
return tableChangeMethods;
|
|
1645
|
+
}
|
|
1631
1646
|
createTable(tableName, first, second, third) {
|
|
1632
|
-
return createTable$1(this, this.up, tableName, first, second, third);
|
|
1647
|
+
return createTable$1(this, this.getTableMethods(), this.up, tableName, first, second, third);
|
|
1633
1648
|
}
|
|
1634
1649
|
dropTable(tableName, first, second, third) {
|
|
1635
|
-
return createTable$1(this, !this.up, tableName, first, second, third);
|
|
1650
|
+
return createTable$1(this, this.getTableMethods(), !this.up, tableName, first, second, third);
|
|
1636
1651
|
}
|
|
1637
1652
|
changeTable(tableName, cbOrOptions, cb) {
|
|
1638
1653
|
const [fn, options] = typeof cbOrOptions === "function" ? [cbOrOptions, {}] : [cb, cbOrOptions];
|
|
1639
|
-
return changeTable(this, this.up, tableName, options, fn);
|
|
1654
|
+
return changeTable(this, this.getTableChangeMethods(), this.up, tableName, options, fn);
|
|
1640
1655
|
}
|
|
1641
1656
|
/**
|
|
1642
1657
|
* Rename a table:
|
|
@@ -1703,7 +1718,7 @@ var Migration = class {
|
|
|
1703
1718
|
* @param fn - function returning a type of the column
|
|
1704
1719
|
*/
|
|
1705
1720
|
addColumn(tableName, columnName, fn) {
|
|
1706
|
-
return addColumn(this, this.up, tableName, columnName, fn);
|
|
1721
|
+
return addColumn(this, this.getTableChangeMethods(), this.up, tableName, columnName, fn);
|
|
1707
1722
|
}
|
|
1708
1723
|
/**
|
|
1709
1724
|
* Drop the schema, create it on rollback. See {@link addColumn}.
|
|
@@ -1713,7 +1728,7 @@ var Migration = class {
|
|
|
1713
1728
|
* @param fn - function returning a type of the column
|
|
1714
1729
|
*/
|
|
1715
1730
|
dropColumn(tableName, columnName, fn) {
|
|
1716
|
-
return addColumn(this, !this.up, tableName, columnName, fn);
|
|
1731
|
+
return addColumn(this, this.getTableChangeMethods(), !this.up, tableName, columnName, fn);
|
|
1717
1732
|
}
|
|
1718
1733
|
/**
|
|
1719
1734
|
* Add an index to the table on migrating, and remove it on rollback.
|
|
@@ -1741,7 +1756,7 @@ var Migration = class {
|
|
|
1741
1756
|
* @param args - index options
|
|
1742
1757
|
*/
|
|
1743
1758
|
addIndex(tableName, columns, ...args) {
|
|
1744
|
-
return addIndex(this, this.up, tableName, columns, ...args);
|
|
1759
|
+
return addIndex(this, this.getTableChangeMethods(), this.up, tableName, columns, ...args);
|
|
1745
1760
|
}
|
|
1746
1761
|
/**
|
|
1747
1762
|
* Drop the schema, create it on rollback. See {@link addIndex}.
|
|
@@ -1751,7 +1766,7 @@ var Migration = class {
|
|
|
1751
1766
|
* @param args - index options
|
|
1752
1767
|
*/
|
|
1753
1768
|
dropIndex(tableName, columns, ...args) {
|
|
1754
|
-
return addIndex(this, !this.up, tableName, columns, ...args);
|
|
1769
|
+
return addIndex(this, this.getTableChangeMethods(), !this.up, tableName, columns, ...args);
|
|
1755
1770
|
}
|
|
1756
1771
|
/**
|
|
1757
1772
|
* Rename index:
|
|
@@ -1816,7 +1831,7 @@ var Migration = class {
|
|
|
1816
1831
|
* @param options - foreign key options
|
|
1817
1832
|
*/
|
|
1818
1833
|
addForeignKey(tableName, columns, foreignTable, foreignColumns, options) {
|
|
1819
|
-
return addForeignKey(this, this.up, tableName, columns, foreignTable, foreignColumns, options);
|
|
1834
|
+
return addForeignKey(this, this.getTableChangeMethods(), this.up, tableName, columns, foreignTable, foreignColumns, options);
|
|
1820
1835
|
}
|
|
1821
1836
|
/**
|
|
1822
1837
|
* Drop the schema, create it on rollback. See {@link addForeignKey}.
|
|
@@ -1828,7 +1843,7 @@ var Migration = class {
|
|
|
1828
1843
|
* @param options - foreign key options
|
|
1829
1844
|
*/
|
|
1830
1845
|
dropForeignKey(tableName, columns, foreignTable, foreignColumns, options) {
|
|
1831
|
-
return addForeignKey(this, !this.up, tableName, columns, foreignTable, foreignColumns, options);
|
|
1846
|
+
return addForeignKey(this, this.getTableChangeMethods(), !this.up, tableName, columns, foreignTable, foreignColumns, options);
|
|
1832
1847
|
}
|
|
1833
1848
|
/**
|
|
1834
1849
|
* Add a primary key to a table on migrate, and remove it on rollback.
|
|
@@ -1853,7 +1868,7 @@ var Migration = class {
|
|
|
1853
1868
|
* @param name - optionally, set a primary key constraint name
|
|
1854
1869
|
*/
|
|
1855
1870
|
addPrimaryKey(tableName, columns, name) {
|
|
1856
|
-
return addPrimaryKey(this, this.up, tableName, columns, name);
|
|
1871
|
+
return addPrimaryKey(this, this.getTableChangeMethods(), this.up, tableName, columns, name);
|
|
1857
1872
|
}
|
|
1858
1873
|
/**
|
|
1859
1874
|
* Drop the schema, create it on rollback. See {@link addPrimaryKey}.
|
|
@@ -1863,7 +1878,7 @@ var Migration = class {
|
|
|
1863
1878
|
* @param name - optionally, set a primary key constraint name
|
|
1864
1879
|
*/
|
|
1865
1880
|
dropPrimaryKey(tableName, columns, name) {
|
|
1866
|
-
return addPrimaryKey(this, !this.up, tableName, columns, name);
|
|
1881
|
+
return addPrimaryKey(this, this.getTableChangeMethods(), !this.up, tableName, columns, name);
|
|
1867
1882
|
}
|
|
1868
1883
|
/**
|
|
1869
1884
|
* Add or drop a check for multiple columns.
|
|
@@ -1880,7 +1895,7 @@ var Migration = class {
|
|
|
1880
1895
|
* @param check - raw SQL for the check
|
|
1881
1896
|
*/
|
|
1882
1897
|
addCheck(tableName, check) {
|
|
1883
|
-
return addCheck(this, this.up, tableName, check);
|
|
1898
|
+
return addCheck(this, this.getTableChangeMethods(), this.up, tableName, check);
|
|
1884
1899
|
}
|
|
1885
1900
|
/**
|
|
1886
1901
|
* Drop the schema, create it on rollback. See {@link addCheck}.
|
|
@@ -1889,7 +1904,7 @@ var Migration = class {
|
|
|
1889
1904
|
* @param check - raw SQL for the check
|
|
1890
1905
|
*/
|
|
1891
1906
|
dropCheck(tableName, check) {
|
|
1892
|
-
return addCheck(this, !this.up, tableName, check);
|
|
1907
|
+
return addCheck(this, this.getTableChangeMethods(), !this.up, tableName, check);
|
|
1893
1908
|
}
|
|
1894
1909
|
/**
|
|
1895
1910
|
* Rename a table constraint such as a primary key or a database check.
|
|
@@ -2472,10 +2487,7 @@ const wrapWithEnhancingError = async (text, values, promise) => {
|
|
|
2472
2487
|
try {
|
|
2473
2488
|
return await promise;
|
|
2474
2489
|
} catch (err) {
|
|
2475
|
-
if (err && typeof err === "object" && "message" in err && typeof err.message === "string" && (err.constructor.name === "PostgresError" || err.constructor.name === "DatabaseError")) {
|
|
2476
|
-
err.message += `\nSQL: ${text}${values ? `\nVariables: ${JSON.stringify(values)}` : ""}`;
|
|
2477
|
-
throw new err.constructor(err);
|
|
2478
|
-
}
|
|
2490
|
+
if (err && typeof err === "object" && "message" in err && typeof err.message === "string" && (err.constructor.name === "PostgresError" || err.constructor.name === "DatabaseError")) err.message += `\nSQL: ${text}${values ? `\nVariables: ${JSON.stringify(values)}` : ""}`;
|
|
2479
2491
|
throw err;
|
|
2480
2492
|
}
|
|
2481
2493
|
};
|
|
@@ -2508,32 +2520,32 @@ const wrapWithLog = async (log, text, values, fn) => {
|
|
|
2508
2520
|
/**
|
|
2509
2521
|
* See {@link Migration.prototype.addColumn}
|
|
2510
2522
|
*/
|
|
2511
|
-
const addColumn = (migration, up, tableName, columnName, fn) => {
|
|
2512
|
-
return changeTable(migration, up, tableName, {}, (t) => ({ [columnName]: t.add(fn(t)) }));
|
|
2523
|
+
const addColumn = (migration, tableChangeMethods, up, tableName, columnName, fn) => {
|
|
2524
|
+
return changeTable(migration, tableChangeMethods, up, tableName, {}, (t) => ({ [columnName]: t.add(fn(t)) }));
|
|
2513
2525
|
};
|
|
2514
2526
|
/**
|
|
2515
2527
|
* See {@link Migration.prototype.addIndex}
|
|
2516
2528
|
*/
|
|
2517
|
-
const addIndex = (migration, up, tableName, columns, ...args) => {
|
|
2518
|
-
return changeTable(migration, up, tableName, {}, (t) => ({ ...t.add(t.index(columns, ...args)) }));
|
|
2529
|
+
const addIndex = (migration, tableChangeMethods, up, tableName, columns, ...args) => {
|
|
2530
|
+
return changeTable(migration, tableChangeMethods, up, tableName, {}, (t) => ({ ...t.add(t.index(columns, ...args)) }));
|
|
2519
2531
|
};
|
|
2520
2532
|
/**
|
|
2521
2533
|
* See {@link Migration.prototype.addForeignKey}
|
|
2522
2534
|
*/
|
|
2523
|
-
const addForeignKey = (migration, up, tableName, columns, foreignTable, foreignColumns, options) => {
|
|
2524
|
-
return changeTable(migration, up, tableName, {}, (t) => ({ ...t.add(t.foreignKey(columns, foreignTable, foreignColumns, options)) }));
|
|
2535
|
+
const addForeignKey = (migration, tableChangeMethods, up, tableName, columns, foreignTable, foreignColumns, options) => {
|
|
2536
|
+
return changeTable(migration, tableChangeMethods, up, tableName, {}, (t) => ({ ...t.add(t.foreignKey(columns, foreignTable, foreignColumns, options)) }));
|
|
2525
2537
|
};
|
|
2526
2538
|
/**
|
|
2527
2539
|
* See {@link Migration.prototype.addPrimaryKey}
|
|
2528
2540
|
*/
|
|
2529
|
-
const addPrimaryKey = (migration, up, tableName, columns, name) => {
|
|
2530
|
-
return changeTable(migration, up, tableName, {}, (t) => ({ ...t.add(t.primaryKey(columns, name)) }));
|
|
2541
|
+
const addPrimaryKey = (migration, tableChangeMethods, up, tableName, columns, name) => {
|
|
2542
|
+
return changeTable(migration, tableChangeMethods, up, tableName, {}, (t) => ({ ...t.add(t.primaryKey(columns, name)) }));
|
|
2531
2543
|
};
|
|
2532
2544
|
/**
|
|
2533
2545
|
* See {@link Migration.prototype.addCheck}
|
|
2534
2546
|
*/
|
|
2535
|
-
const addCheck = (migration, up, tableName, check) => {
|
|
2536
|
-
return changeTable(migration, up, tableName, {}, (t) => ({ ...t.add(t.check(check)) }));
|
|
2547
|
+
const addCheck = (migration, tableChangeMethods, up, tableName, check) => {
|
|
2548
|
+
return changeTable(migration, tableChangeMethods, up, tableName, {}, (t) => ({ ...t.add(t.check(check)) }));
|
|
2537
2549
|
};
|
|
2538
2550
|
/**
|
|
2539
2551
|
* See {@link Migration.prototype.createSchema}
|
|
@@ -2937,11 +2949,6 @@ To keep using timestamp ids, set \`migrationId\` option of rake-db to 'timestamp
|
|
|
2937
2949
|
function getMigrationVersion(config, name) {
|
|
2938
2950
|
return (config.migrationId === "timestamp" ? name.match(/^(\d{14})(_|\b)/) : name.match(/^(\d{4})(_|\b)/))?.[1];
|
|
2939
2951
|
}
|
|
2940
|
-
function getDigitsPrefix(name) {
|
|
2941
|
-
const value = name.match(/^(\d+)\D/)?.[1];
|
|
2942
|
-
if (!value) throw new Error(`Migration file should be prefixed with a serial number, received ${name}`);
|
|
2943
|
-
return value;
|
|
2944
|
-
}
|
|
2945
2952
|
const getMaybeTransactionAdapter = (db) => "$getAdapter" in db ? db.$getAdapter() : db;
|
|
2946
2953
|
const runSqlInSavePoint = async (db, sql, code) => {
|
|
2947
2954
|
const adapter = getMaybeTransactionAdapter(db);
|
|
@@ -3078,39 +3085,22 @@ const deleteMigratedVersion = async (adapter, version, name, config) => {
|
|
|
3078
3085
|
if ((await adapter.silentArrays(`DELETE FROM ${migrationsSchemaTableSql(adapter, config)} WHERE version = $1 AND name = $2`, [version, name])).rowCount === 0) throw new Error(`Migration ${version}_${name} was not found in db`);
|
|
3079
3086
|
};
|
|
3080
3087
|
var NoMigrationsTableError = class extends Error {};
|
|
3081
|
-
const getMigratedVersionsMap = async (
|
|
3088
|
+
const getMigratedVersionsMap = async (_ctx, adapter, config, renameTo) => {
|
|
3082
3089
|
const table = migrationsSchemaTableSql(adapter, config);
|
|
3083
|
-
const queryVersion = () => adapter.
|
|
3090
|
+
const queryVersion = () => adapter.query(`SELECT * FROM ${table} ORDER BY version`);
|
|
3084
3091
|
let result;
|
|
3085
3092
|
try {
|
|
3086
3093
|
if (adapter.isInTransaction()) result = await adapter.savepoint("check_migrations_table", queryVersion);
|
|
3087
3094
|
else result = await queryVersion();
|
|
3088
3095
|
} catch (err) {
|
|
3089
|
-
if (err
|
|
3096
|
+
if (err && typeof err === "object" && getDriverErrorCode(err) === "42P01") throw new NoMigrationsTableError();
|
|
3090
3097
|
else throw err;
|
|
3091
3098
|
}
|
|
3092
|
-
|
|
3093
|
-
const { migrations } = await getMigrations(ctx, config, true);
|
|
3094
|
-
const map = {};
|
|
3095
|
-
for (const item of migrations) {
|
|
3096
|
-
const name = path.basename(item.path);
|
|
3097
|
-
map[item.version] = name.slice(getDigitsPrefix(name).length + 1);
|
|
3098
|
-
}
|
|
3099
|
-
for (const row of result.rows) {
|
|
3100
|
-
const [version] = row;
|
|
3101
|
-
const name = map[version];
|
|
3102
|
-
if (!name) throw new Error(`Migration for version ${version} is stored in db but is not found among available migrations`);
|
|
3103
|
-
row[1] = name;
|
|
3104
|
-
}
|
|
3105
|
-
await adapter.arrays(`ALTER TABLE ${table} ADD COLUMN name TEXT`);
|
|
3106
|
-
await Promise.all(result.rows.map(([version, name]) => adapter.arrays(`UPDATE ${table} SET name = $2 WHERE version = $1`, [version, name])));
|
|
3107
|
-
await adapter.arrays(`ALTER TABLE ${table} ALTER COLUMN name SET NOT NULL`);
|
|
3108
|
-
}
|
|
3109
|
-
let versions = Object.fromEntries(result.rows);
|
|
3099
|
+
let versions = Object.fromEntries(result.rows.map(({ version, name }) => [version, name]));
|
|
3110
3100
|
if (renameTo) versions = await renameMigrations(config, adapter, versions, renameTo);
|
|
3111
3101
|
return {
|
|
3112
3102
|
map: versions,
|
|
3113
|
-
sequence: result.rows.map((row) => +row
|
|
3103
|
+
sequence: result.rows.map((row) => +row.version)
|
|
3114
3104
|
};
|
|
3115
3105
|
};
|
|
3116
3106
|
async function renameMigrations(config, trx, versions, renameTo) {
|
|
@@ -3415,7 +3405,7 @@ const getAdapterDatabase$1 = (adapter) => {
|
|
|
3415
3405
|
};
|
|
3416
3406
|
const rakeDbConfigDefaults = {
|
|
3417
3407
|
...migrateConfigDefaults,
|
|
3418
|
-
schemaConfig: defaultSchemaConfig,
|
|
3408
|
+
schemaConfig: defaultSchemaConfig(),
|
|
3419
3409
|
snakeCase: false,
|
|
3420
3410
|
commands: {},
|
|
3421
3411
|
log: true,
|
|
@@ -4728,8 +4718,11 @@ const constraintsSql = `SELECT
|
|
|
4728
4718
|
t.relname AS "tableName",
|
|
4729
4719
|
c.conname AS "name",
|
|
4730
4720
|
(
|
|
4731
|
-
SELECT json_agg(ccu.column_name)
|
|
4721
|
+
SELECT json_agg(ccu.column_name ORDER BY a.attnum)
|
|
4732
4722
|
FROM information_schema.constraint_column_usage ccu
|
|
4723
|
+
JOIN pg_catalog.pg_attribute a
|
|
4724
|
+
ON a.attrelid = c.conrelid
|
|
4725
|
+
AND a.attname = ccu.column_name
|
|
4733
4726
|
WHERE contype = 'p'
|
|
4734
4727
|
AND ccu.constraint_name = c.conname
|
|
4735
4728
|
AND ccu.table_schema = s.nspname
|
|
@@ -4743,15 +4736,21 @@ const constraintsSql = `SELECT
|
|
|
4743
4736
|
ft.relname,
|
|
4744
4737
|
'columns',
|
|
4745
4738
|
(
|
|
4746
|
-
SELECT json_agg(ccu.column_name)
|
|
4739
|
+
SELECT json_agg(ccu.column_name ORDER BY a.attnum)
|
|
4747
4740
|
FROM information_schema.key_column_usage ccu
|
|
4741
|
+
JOIN pg_catalog.pg_attribute a
|
|
4742
|
+
ON a.attrelid = c.conrelid
|
|
4743
|
+
AND a.attname = ccu.column_name
|
|
4748
4744
|
WHERE ccu.constraint_name = c.conname
|
|
4749
4745
|
AND ccu.table_schema = cs.nspname
|
|
4750
4746
|
),
|
|
4751
4747
|
'foreignColumns',
|
|
4752
4748
|
(
|
|
4753
|
-
SELECT json_agg(ccu.column_name)
|
|
4749
|
+
SELECT json_agg(ccu.column_name ORDER BY a.attnum)
|
|
4754
4750
|
FROM information_schema.constraint_column_usage ccu
|
|
4751
|
+
JOIN pg_catalog.pg_attribute a
|
|
4752
|
+
ON a.attrelid = c.confrelid
|
|
4753
|
+
AND a.attname = ccu.column_name
|
|
4755
4754
|
WHERE ccu.constraint_name = c.conname
|
|
4756
4755
|
AND ccu.table_schema = cs.nspname
|
|
4757
4756
|
),
|
|
@@ -5903,10 +5902,10 @@ const makeRakeDbConfig = (config, args) => {
|
|
|
5903
5902
|
if (result.recurrentPath && !path.isAbsolute(result.recurrentPath)) result.recurrentPath = path.resolve(result.basePath, result.recurrentPath);
|
|
5904
5903
|
if ("baseTable" in config && config.baseTable) {
|
|
5905
5904
|
const { types } = config.baseTable.prototype;
|
|
5906
|
-
result.columnTypes = types || makeColumnTypes(defaultSchemaConfig);
|
|
5905
|
+
result.columnTypes = types || makeColumnTypes(defaultSchemaConfig());
|
|
5907
5906
|
} else {
|
|
5908
5907
|
const ct = "columnTypes" in config && config.columnTypes;
|
|
5909
|
-
result.columnTypes = (typeof ct === "function" ? ct(makeColumnTypes(defaultSchemaConfig)) : ct) || makeColumnTypes(defaultSchemaConfig);
|
|
5908
|
+
result.columnTypes = (typeof ct === "function" ? ct(makeColumnTypes(defaultSchemaConfig())) : ct) || makeColumnTypes(defaultSchemaConfig());
|
|
5910
5909
|
}
|
|
5911
5910
|
if (config.migrationId === "serial") result.migrationId = { serial: 4 };
|
|
5912
5911
|
const transaction = getCliParam(args, "transaction");
|