fase(2): shared infrastructure layer
This commit is contained in:
31
dist/db/migrator.js
vendored
Normal file
31
dist/db/migrator.js
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.runMigrations = runMigrations;
|
||||
const kysely_1 = require("kysely");
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const promises_1 = __importDefault(require("fs/promises"));
|
||||
async function runMigrations(db) {
|
||||
const migrator = new kysely_1.Migrator({
|
||||
db,
|
||||
provider: new kysely_1.FileMigrationProvider({
|
||||
fs: promises_1.default,
|
||||
path: path_1.default,
|
||||
migrationFolder: path_1.default.join(__dirname, 'migrations'),
|
||||
}),
|
||||
});
|
||||
const { error, results } = await migrator.migrateToLatest();
|
||||
results?.forEach(result => {
|
||||
if (result.status === 'Success') {
|
||||
console.log(`Migration "${result.migrationName}" executed successfully`);
|
||||
}
|
||||
else if (result.status === 'Error') {
|
||||
console.error(`Migration "${result.migrationName}" failed`);
|
||||
}
|
||||
});
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user