rake-db 2.36.1 → 2.36.3
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.d.ts +3 -1
- package/dist/index.js +11 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -3134,8 +3134,12 @@ const migrateConfigDefaults = {
|
|
|
3134
3134
|
migrationsTable: "schemaMigrations",
|
|
3135
3135
|
transaction: "single"
|
|
3136
3136
|
};
|
|
3137
|
-
const handleConfigLogger = (config) => {
|
|
3138
|
-
|
|
3137
|
+
const handleConfigLogger = (config, db) => {
|
|
3138
|
+
const q = db ? "$qb" in db && db.$qb ? db.$qb.q : "q" in db ? db.q : void 0 : void 0;
|
|
3139
|
+
return {
|
|
3140
|
+
log: config.log ?? q?.log,
|
|
3141
|
+
logger: config.log === true ? config.logger || q?.logger || console : config.log === false ? void 0 : config.logger || q?.logger
|
|
3142
|
+
};
|
|
3139
3143
|
};
|
|
3140
3144
|
/**
|
|
3141
3145
|
* Process a PublicRakeDbConfig into RakeDbConfig by handling the `log` option.
|
|
@@ -3147,9 +3151,10 @@ const handleConfigLogger = (config) => {
|
|
|
3147
3151
|
* - `log: undefined` → preserves existing `logger`
|
|
3148
3152
|
*
|
|
3149
3153
|
* @param config - the public config with optional `log` setting
|
|
3154
|
+
* @param db - optionally provided by `migrate` to get the logger from it
|
|
3150
3155
|
* @returns a processed RakeDbConfig ready for internal use
|
|
3151
3156
|
*/
|
|
3152
|
-
const processMigrateConfig = (config) => {
|
|
3157
|
+
const processMigrateConfig = (config, db) => {
|
|
3153
3158
|
let migrationsPath;
|
|
3154
3159
|
if (!("migrations" in config)) {
|
|
3155
3160
|
migrationsPath = config.migrationsPath ? config.migrationsPath : path.join("src", "db", "migrations");
|
|
@@ -3159,7 +3164,7 @@ const processMigrateConfig = (config) => {
|
|
|
3159
3164
|
...migrateConfigDefaults,
|
|
3160
3165
|
...config,
|
|
3161
3166
|
migrationsPath,
|
|
3162
|
-
|
|
3167
|
+
...handleConfigLogger(config, db)
|
|
3163
3168
|
};
|
|
3164
3169
|
if ("baseTable" in config && config.baseTable) {
|
|
3165
3170
|
const { snakeCase, language } = config.baseTable.prototype;
|
|
@@ -3173,7 +3178,7 @@ const transactionIfSingle = (adapter, config, fn) => {
|
|
|
3173
3178
|
};
|
|
3174
3179
|
function makeMigrateFn(up, defaultCount, fn) {
|
|
3175
3180
|
return async (db, publicConfig, params) => {
|
|
3176
|
-
const config = processMigrateConfig(publicConfig);
|
|
3181
|
+
const config = processMigrateConfig(publicConfig, db);
|
|
3177
3182
|
const ctx = params?.ctx || {};
|
|
3178
3183
|
const set = await getMigrations(ctx, config, up);
|
|
3179
3184
|
const count = params?.count ?? defaultCount;
|
|
@@ -3221,7 +3226,7 @@ async function runMigration(db, ...args) {
|
|
|
3221
3226
|
const [rawConfig, migration] = args.length === 1 ? [{}, args[0]] : [args[0], args[1]];
|
|
3222
3227
|
const config = {
|
|
3223
3228
|
...rawConfig,
|
|
3224
|
-
|
|
3229
|
+
...handleConfigLogger(rawConfig)
|
|
3225
3230
|
};
|
|
3226
3231
|
await transaction(getMaybeTransactionAdapter(db), config, async (trx) => {
|
|
3227
3232
|
clearChanges();
|