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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _$pqb_internal0 from "pqb/internal";
2
- import { Adapter, Column as Column$1, ColumnSchemaConfig, ColumnTypeSchemaArg, ColumnsByType, ColumnsShape, DbDomainArg, DbResult, DbStructureDomainsMap, DefaultColumnTypes, DefaultPrivileges, DefaultSchemaConfig, EmptyObject, EnumColumn, Grant, MaybeArray, MaybePromise, NoPrimaryKeyOption, NonUniqDataItem, QueryLogObject, QueryLogOptions, QueryLogger, QuerySchema, RawSqlBase, RecordOptionalString, RecordString, RlsPolicy, SearchWeight, TableData, TableDataFn, TableDataItem, TableDataMethods, raw } from "pqb/internal";
2
+ import { Adapter, Column as Column$1, ColumnSchemaConfig, ColumnTypeSchemaArg, ColumnsByType, ColumnsShape, DbDomainArg, DbResult, DbStructureDomainsMap, DefaultColumnTypes, DefaultPrivileges, DefaultSchemaConfig, EmptyObject, EnumColumn, Grant, MaybeArray, MaybePromise, NoPrimaryKeyOption, NonUniqDataItem, PickQueryQ, QueryData, QueryLogObject, QueryLogOptions, QueryLogger, QuerySchema, RawSqlBase, RecordOptionalString, RecordString, RlsPolicy, SearchWeight, TableData, TableDataFn, TableDataItem, TableDataMethods, raw } from "pqb/internal";
3
3
  import { Db } from "pqb";
4
4
  declare namespace DbStructure {
5
5
  interface TableNameAndSchemaName {
@@ -1635,6 +1635,8 @@ interface MigrationChange {
1635
1635
  }
1636
1636
  type ChangeCallback<ColumnTypes> = (db: DbMigration<ColumnTypes>, up: boolean) => Promise<void>;
1637
1637
  interface OrmParam {
1638
+ $qb?: PickQueryQ;
1639
+ q?: QueryData;
1638
1640
  $getAdapter(): Adapter;
1639
1641
  }
1640
1642
  type DbParam = OrmParam | Adapter;
package/dist/index.js CHANGED
@@ -3157,8 +3157,12 @@ const migrateConfigDefaults = {
3157
3157
  migrationsTable: "schemaMigrations",
3158
3158
  transaction: "single"
3159
3159
  };
3160
- const handleConfigLogger = (config) => {
3161
- return config.log === true ? config.logger || console : config.log === false ? void 0 : config.logger;
3160
+ const handleConfigLogger = (config, db) => {
3161
+ const q = db ? "$qb" in db && db.$qb ? db.$qb.q : "q" in db ? db.q : void 0 : void 0;
3162
+ return {
3163
+ log: config.log ?? q?.log,
3164
+ logger: config.log === true ? config.logger || q?.logger || console : config.log === false ? void 0 : config.logger || q?.logger
3165
+ };
3162
3166
  };
3163
3167
  /**
3164
3168
  * Process a PublicRakeDbConfig into RakeDbConfig by handling the `log` option.
@@ -3170,9 +3174,10 @@ const handleConfigLogger = (config) => {
3170
3174
  * - `log: undefined` → preserves existing `logger`
3171
3175
  *
3172
3176
  * @param config - the public config with optional `log` setting
3177
+ * @param db - optionally provided by `migrate` to get the logger from it
3173
3178
  * @returns a processed RakeDbConfig ready for internal use
3174
3179
  */
3175
- const processMigrateConfig = (config) => {
3180
+ const processMigrateConfig = (config, db) => {
3176
3181
  let migrationsPath;
3177
3182
  if (!("migrations" in config)) {
3178
3183
  migrationsPath = config.migrationsPath ? config.migrationsPath : node_path.default.join("src", "db", "migrations");
@@ -3182,7 +3187,7 @@ const processMigrateConfig = (config) => {
3182
3187
  ...migrateConfigDefaults,
3183
3188
  ...config,
3184
3189
  migrationsPath,
3185
- logger: handleConfigLogger(config)
3190
+ ...handleConfigLogger(config, db)
3186
3191
  };
3187
3192
  if ("baseTable" in config && config.baseTable) {
3188
3193
  const { snakeCase, language } = config.baseTable.prototype;
@@ -3196,7 +3201,7 @@ const transactionIfSingle = (adapter, config, fn) => {
3196
3201
  };
3197
3202
  function makeMigrateFn(up, defaultCount, fn) {
3198
3203
  return async (db, publicConfig, params) => {
3199
- const config = processMigrateConfig(publicConfig);
3204
+ const config = processMigrateConfig(publicConfig, db);
3200
3205
  const ctx = params?.ctx || {};
3201
3206
  const set = await getMigrations(ctx, config, up);
3202
3207
  const count = params?.count ?? defaultCount;
@@ -3244,7 +3249,7 @@ async function runMigration(db, ...args) {
3244
3249
  const [rawConfig, migration] = args.length === 1 ? [{}, args[0]] : [args[0], args[1]];
3245
3250
  const config = {
3246
3251
  ...rawConfig,
3247
- logger: handleConfigLogger(rawConfig)
3252
+ ...handleConfigLogger(rawConfig)
3248
3253
  };
3249
3254
  await transaction(getMaybeTransactionAdapter(db), config, async (trx) => {
3250
3255
  clearChanges();