@jsgurucompany/jsg-nestjs-common
Version:
Initial README.md
55 lines • 1.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Migrator = void 0;
const umzug_1 = require("umzug");
const fs = require("fs");
const path = require("path");
class Migrator {
constructor(options) {
this.migrationsPath = '';
this.setMigrationsPath(options.migrationsPath);
this.initDriver(options);
}
initDriver(options) {
this.driver = new umzug_1.Umzug({
migrations: {
glob: options.migrationsGlob,
},
context: options.context,
storage: options.storage,
logger: options.logger,
create: {
template: (filepath) => [
[
filepath,
fs
.readFileSync(path.join(__dirname, 'sample-migration.template'))
.toString(),
],
],
},
});
}
getMigrationsPath() {
return this.migrationsPath;
}
setMigrationsPath(path) {
this.migrationsPath = path;
}
async create({ name, folder }) {
return this.driver.create({
name: `${name}.migration.ts`,
folder: folder !== null && folder !== void 0 ? folder : this.getMigrationsPath(),
prefix: 'TIMESTAMP',
allowConfusingOrdering: true,
});
}
async up() {
return this.driver.up();
}
async down(options) {
return this.driver.down(options);
}
}
exports.Migrator = Migrator;
//# sourceMappingURL=migrator.js.map