rake-db 2.8.0 → 2.8.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/index.d.ts CHANGED
@@ -293,8 +293,7 @@ type RakeDbConfig<CT extends ColumnTypesBase = DefaultColumnTypes> = {
293
293
  beforeRollback?(db: Db): Promise<void>;
294
294
  afterRollback?(db: Db): Promise<void>;
295
295
  } & QueryLogOptions;
296
- type AppCodeUpdater = (params: {
297
- ast: RakeDbAst;
296
+ type AppCodeUpdaterParams = {
298
297
  options: AdapterOptions;
299
298
  basePath: string;
300
299
  cache: object;
@@ -303,7 +302,13 @@ type AppCodeUpdater = (params: {
303
302
  filePath: string;
304
303
  name: string;
305
304
  };
306
- }) => Promise<void>;
305
+ };
306
+ type AppCodeUpdater = {
307
+ process(params: AppCodeUpdaterParams & {
308
+ ast: RakeDbAst;
309
+ }): Promise<void>;
310
+ afterAll(params: AppCodeUpdaterParams): Promise<void>;
311
+ };
307
312
 
308
313
  declare const createDb: <CT extends ColumnTypesBase>(arg: MaybeArray<AdapterOptions>, config: RakeDbConfig<CT>) => Promise<void>;
309
314
  declare const dropDb: (arg: MaybeArray<AdapterOptions>) => Promise<void>;
package/dist/index.js CHANGED
@@ -1629,7 +1629,7 @@ var __spreadValues$1 = (a, b) => {
1629
1629
  };
1630
1630
  const getDb = (adapter) => pqb.createDb({ adapter });
1631
1631
  const migrateOrRollback = async (options, config, args, up) => {
1632
- var _a, _b, _c, _d, _e;
1632
+ var _a, _b, _c, _d, _e, _f;
1633
1633
  config = __spreadValues$1({}, config);
1634
1634
  const files = await getMigrationFiles(config, up);
1635
1635
  let count = up ? Infinity : 1;
@@ -1680,6 +1680,14 @@ const migrateOrRollback = async (options, config, args, up) => {
1680
1680
  await ((_e = config.afterRollback) == null ? void 0 : _e.call(config, db != null ? db : db = getDb(adapter)));
1681
1681
  }
1682
1682
  } finally {
1683
+ await ((_f = config.appCodeUpdater) == null ? void 0 : _f.afterAll({
1684
+ options: opts,
1685
+ basePath: config.basePath,
1686
+ cache: appCodeUpdaterCache,
1687
+ logger: config.logger,
1688
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1689
+ baseTable: config.baseTable
1690
+ }));
1683
1691
  await adapter.close();
1684
1692
  }
1685
1693
  delete config.appCodeUpdater;
@@ -1718,7 +1726,7 @@ const processMigration = async (db, up, file, config, options, appCodeUpdaterCac
1718
1726
  return db2.migratedAsts;
1719
1727
  });
1720
1728
  for (const ast of asts) {
1721
- await ((_a = config.appCodeUpdater) == null ? void 0 : _a.call(config, {
1729
+ await ((_a = config.appCodeUpdater) == null ? void 0 : _a.process({
1722
1730
  ast,
1723
1731
  options,
1724
1732
  basePath: config.basePath,
@@ -2971,7 +2979,7 @@ const createView = (ast) => {
2971
2979
  };
2972
2980
 
2973
2981
  const pullDbStructure = async (options, config) => {
2974
- var _a, _b, _c;
2982
+ var _a, _b, _c, _d;
2975
2983
  const adapter = new pqb.Adapter(options);
2976
2984
  const currentSchema = adapter.schema || "public";
2977
2985
  const db = new DbStructure(adapter);
@@ -2994,7 +3002,7 @@ const pullDbStructure = async (options, config) => {
2994
3002
  await saveMigratedVersion(silentQueries, version, config);
2995
3003
  const cache = {};
2996
3004
  for (const item of ast) {
2997
- await ((_a = config == null ? void 0 : config.appCodeUpdater) == null ? void 0 : _a.call(config, {
3005
+ await ((_a = config == null ? void 0 : config.appCodeUpdater) == null ? void 0 : _a.process({
2998
3006
  ast: item,
2999
3007
  options,
3000
3008
  basePath: config.basePath,
@@ -3004,11 +3012,19 @@ const pullDbStructure = async (options, config) => {
3004
3012
  baseTable: config.baseTable
3005
3013
  }));
3006
3014
  }
3015
+ await ((_b = config == null ? void 0 : config.appCodeUpdater) == null ? void 0 : _b.afterAll({
3016
+ options,
3017
+ basePath: config.basePath,
3018
+ cache,
3019
+ logger: config.logger,
3020
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
3021
+ baseTable: config.baseTable
3022
+ }));
3007
3023
  const unsupportedEntries = Object.entries(ctx.unsupportedTypes);
3008
3024
  const len = unsupportedEntries.length;
3009
3025
  if (len) {
3010
3026
  let count = 0;
3011
- (_b = config.logger) == null ? void 0 : _b.warn(
3027
+ (_c = config.logger) == null ? void 0 : _c.warn(
3012
3028
  `Found unsupported types:
3013
3029
  ${unsupportedEntries.map(([type, columns]) => {
3014
3030
  count += columns.length;
@@ -3017,7 +3033,7 @@ ${unsupportedEntries.map(([type, columns]) => {
3017
3033
  Append \`as\` method manually to ${count > 1 ? "these" : "this"} column${count > 1 ? "s" : ""} to treat ${count > 1 ? "them" : "it"} as other column type`
3018
3034
  );
3019
3035
  }
3020
- (_c = config.logger) == null ? void 0 : _c.log("Database pulled successfully");
3036
+ (_d = config.logger) == null ? void 0 : _d.log("Database pulled successfully");
3021
3037
  adapter.close();
3022
3038
  };
3023
3039