console/patches/@slonik__migrator@0.11.3.patch

44 lines
2.2 KiB
Diff
Raw Normal View History

diff --git a/dist/index.js b/dist/index.js
index 65ddf2942ab6f9ad969cdc5bbac36977c91fc984..df9cbe372f5c4034b51f8c22434778d87e2a152b 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -53,7 +53,7 @@ class SlonikMigrator extends umzug.Umzug {
}
/** Glob pattern with `migrationsPath` as `cwd`. Could be overridden to support nested directories */
migrationsGlob() {
- return './*.{js,ts,sql}';
+ return './*.{js,ts,mts,mjs,sql}';
}
/** Gets a hexadecimal integer to pass to postgres's `select pg_advisory_lock()` function */
advisoryLockId() {
@@ -66,10 +66,10 @@ class SlonikMigrator extends umzug.Umzug {
return slonik_1.sql.identifier(Array.isArray(table) ? table : [table]);
}
template(filepath) {
- if (filepath.endsWith('.ts')) {
+ if (filepath.endsWith('.ts') || filepath.endsWith('.mts')) {
return [[filepath, templates.typescript]];
}
- if (filepath.endsWith('.js')) {
+ if (filepath.endsWith('.js') || filepath.endsWith('.mjs')) {
return [[filepath, templates.javascript]];
}
const downPath = path.join(path.dirname(filepath), 'down', path.basename(filepath));
@@ -93,12 +93,14 @@ class SlonikMigrator extends umzug.Umzug {
};
}
const { connection: slonik } = params.context;
- const migrationModule = require(params.path);
+ // returns a Promise, but we'll await it later
+ const migrationModule = import(params.path);
+
return {
name: params.name,
path: params.path,
- up: async (upParams) => migrationModule.up({ slonik, sql: slonik_1.sql, ...upParams }),
- down: async (downParams) => { var _a; return (_a = migrationModule.down) === null || _a === void 0 ? void 0 : _a.call(migrationModule, { slonik, sql: slonik_1.sql, ...downParams }); },
+ up: async (upParams) => (await migrationModule).up({ slonik, sql: slonik_1.sql, ...upParams }),
+ down: async (downParams) => { var _a; return (_a = (await migrationModule).down) === null || _a === void 0 ? void 0 : _a.call(migrationModule, { slonik, sql: slonik_1.sql, ...downParams }); },
};
}
async getOrCreateMigrationsTable(context) {