rake-db 2.3.6 → 2.3.8
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/CHANGELOG.md +15 -0
- package/dist/index.d.ts +214 -7
- package/dist/index.js +41 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/commands/migrateOrRollback.test.ts +4 -2
- package/src/commands/migrateOrRollback.ts +9 -3
- package/src/migration/changeTable.ts +3 -3
- package/src/migration/createTable.ts +3 -3
- package/src/migration/migration.ts +57 -43
- package/src/migration/migrationUtils.ts +2 -3
- package/src/test-utils.ts +3 -3
- package/src/pull/getColumnByType.ts +0 -15
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { singleQuote, quote, isRaw, getRaw, toArray, columnTypes, raw, getColumnTypes, getTableData, resetTableData, ColumnType, emptyObject, TransactionAdapter, logParamToLogObject, Adapter, columnsByType, instantiateColumn, codeToString, addCode, quoteObjectKey, primaryKeyToCode, indexToCode, foreignKeyToCode, TimestampColumn } from 'pqb';
|
|
1
|
+
import { singleQuote, quote, isRaw, getRaw, toArray, columnTypes, raw, getColumnTypes, getTableData, resetTableData, ColumnType, emptyObject, TransactionAdapter, logParamToLogObject, createDb as createDb$1, Adapter, columnsByType, instantiateColumn, codeToString, addCode, quoteObjectKey, primaryKeyToCode, indexToCode, foreignKeyToCode, TimestampColumn } from 'pqb';
|
|
2
2
|
import Enquirer from 'enquirer';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { readdir, mkdir, writeFile } from 'fs/promises';
|
|
@@ -427,7 +427,7 @@ const createTable$1 = async (migration, up, tableName, options, fn) => {
|
|
|
427
427
|
validatePrimaryKey(ast);
|
|
428
428
|
const queries = astToQueries$1(ast);
|
|
429
429
|
for (const query of queries) {
|
|
430
|
-
await migration.query(query);
|
|
430
|
+
await migration.adapter.query(query);
|
|
431
431
|
}
|
|
432
432
|
await runCodeUpdater(migration, ast);
|
|
433
433
|
};
|
|
@@ -661,7 +661,7 @@ const changeTable = async (migration, up, tableName, options, fn) => {
|
|
|
661
661
|
const ast = makeAst(up, tableName, changeData, changeTableData, options);
|
|
662
662
|
const queries = astToQueries(ast);
|
|
663
663
|
for (const query of queries) {
|
|
664
|
-
await migration.query(query);
|
|
664
|
+
await migration.adapter.query(query);
|
|
665
665
|
}
|
|
666
666
|
await runCodeUpdater(migration, ast);
|
|
667
667
|
};
|
|
@@ -890,21 +890,31 @@ var __spreadValues$2 = (a, b) => {
|
|
|
890
890
|
return a;
|
|
891
891
|
};
|
|
892
892
|
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
}
|
|
893
|
+
const createMigrationInterface = (tx, up, options, adapterOptions, appCodeUpdaterCache) => {
|
|
894
|
+
const adapter = new TransactionAdapter(tx, tx.client, tx.types);
|
|
895
|
+
const { query, arrays } = adapter;
|
|
896
|
+
const log = logParamToLogObject(options.logger || console, options.log);
|
|
897
|
+
adapter.query = (q, types) => {
|
|
898
|
+
return wrapWithLog(log, q, () => query.call(adapter, q, types));
|
|
899
|
+
};
|
|
900
|
+
adapter.arrays = (q, types) => {
|
|
901
|
+
return wrapWithLog(log, q, () => arrays.call(adapter, q, types));
|
|
902
|
+
};
|
|
903
|
+
const db = createDb$1({ adapter, columnTypes });
|
|
904
|
+
const { prototype: proto } = MigrationBase;
|
|
905
|
+
for (const key of Object.getOwnPropertyNames(proto)) {
|
|
906
|
+
db[key] = proto[key];
|
|
907
|
+
}
|
|
908
|
+
return Object.assign(db, {
|
|
909
|
+
adapter,
|
|
910
|
+
log,
|
|
911
|
+
up,
|
|
912
|
+
options,
|
|
913
|
+
adapterOptions,
|
|
914
|
+
appCodeUpdaterCache
|
|
915
|
+
});
|
|
916
|
+
};
|
|
917
|
+
class MigrationBase {
|
|
908
918
|
createTable(tableName, cbOrOptions, cb) {
|
|
909
919
|
const options = typeof cbOrOptions === "function" ? {} : cbOrOptions;
|
|
910
920
|
const fn = cb || cbOrOptions;
|
|
@@ -929,7 +939,7 @@ class Migration extends TransactionAdapter {
|
|
|
929
939
|
toSchema,
|
|
930
940
|
to: t
|
|
931
941
|
};
|
|
932
|
-
await this.query(
|
|
942
|
+
await this.adapter.query(
|
|
933
943
|
`ALTER TABLE ${quoteWithSchema({
|
|
934
944
|
schema: ast.fromSchema,
|
|
935
945
|
name: ast.from
|
|
@@ -1052,7 +1062,7 @@ const createSchema$1 = async (migration, up, name) => {
|
|
|
1052
1062
|
action: up ? "create" : "drop",
|
|
1053
1063
|
name
|
|
1054
1064
|
};
|
|
1055
|
-
await migration.query(
|
|
1065
|
+
await migration.adapter.query(
|
|
1056
1066
|
`${ast.action === "create" ? "CREATE" : "DROP"} SCHEMA "${name}"`
|
|
1057
1067
|
);
|
|
1058
1068
|
await runCodeUpdater(migration, ast);
|
|
@@ -1069,11 +1079,11 @@ const createExtension = async (migration, up, name, options) => {
|
|
|
1069
1079
|
} else {
|
|
1070
1080
|
query = `CREATE EXTENSION${ast.ifExists ? " IF NOT EXISTS" : ""} "${ast.name}"${ast.schema ? ` SCHEMA "${ast.schema}"` : ""}${ast.version ? ` VERSION '${ast.version}'` : ""}${ast.cascade ? " CASCADE" : ""}`;
|
|
1071
1081
|
}
|
|
1072
|
-
await migration.query(query);
|
|
1082
|
+
await migration.adapter.query(query);
|
|
1073
1083
|
await runCodeUpdater(migration, ast);
|
|
1074
1084
|
};
|
|
1075
1085
|
const queryExists = (db, sql) => {
|
|
1076
|
-
return db.query(sql).then(({ rowCount }) => rowCount > 0);
|
|
1086
|
+
return db.adapter.query(sql).then(({ rowCount }) => rowCount > 0);
|
|
1077
1087
|
};
|
|
1078
1088
|
const runCodeUpdater = (migration, ast) => {
|
|
1079
1089
|
var _a, _b;
|
|
@@ -1140,7 +1150,13 @@ const migrateOrRollback = async (options, config, args, up) => {
|
|
|
1140
1150
|
const changeCache = {};
|
|
1141
1151
|
const processMigration = async (db, up, file, config, options, appCodeUpdaterCache) => {
|
|
1142
1152
|
await db.transaction(async (tx) => {
|
|
1143
|
-
const db2 =
|
|
1153
|
+
const db2 = createMigrationInterface(
|
|
1154
|
+
tx,
|
|
1155
|
+
up,
|
|
1156
|
+
config,
|
|
1157
|
+
options,
|
|
1158
|
+
appCodeUpdaterCache
|
|
1159
|
+
);
|
|
1144
1160
|
setCurrentMigration(db2);
|
|
1145
1161
|
setCurrentMigrationUp(up);
|
|
1146
1162
|
const callback = changeCache[file.path];
|
|
@@ -1152,7 +1168,7 @@ const processMigration = async (db, up, file, config, options, appCodeUpdaterCac
|
|
|
1152
1168
|
}
|
|
1153
1169
|
await getCurrentPromise();
|
|
1154
1170
|
await (up ? saveMigratedVersion : removeMigratedVersion)(
|
|
1155
|
-
db2,
|
|
1171
|
+
db2.adapter,
|
|
1156
1172
|
file.version,
|
|
1157
1173
|
config
|
|
1158
1174
|
);
|
|
@@ -1941,5 +1957,5 @@ Generate arguments:
|
|
|
1941
1957
|
`
|
|
1942
1958
|
);
|
|
1943
1959
|
|
|
1944
|
-
export {
|
|
1960
|
+
export { MigrationBase, change, createDb, createMigrationInterface, dropDb, generate, migrate, rakeDb, resetDb, rollback, runCodeUpdater, writeMigrationFile };
|
|
1945
1961
|
//# sourceMappingURL=index.mjs.map
|