@mtg-tracker/common 1.0.24 → 1.0.25
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.
|
@@ -15,9 +15,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.runMigrations = runMigrations;
|
|
16
16
|
const fs_1 = __importDefault(require("fs"));
|
|
17
17
|
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const service_log_1 = require("../logs/service-log");
|
|
18
19
|
function runMigrations(pool, migrationsDir, service) {
|
|
19
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
|
|
21
|
+
const logger = new service_log_1.ServiceLogger(service);
|
|
22
|
+
logger.log(`Running database migrations for the ${service} service...`);
|
|
21
23
|
// Sanitize service name
|
|
22
24
|
const sanitizedService = service.replace(/[^a-zA-Z0-9_]/g, '');
|
|
23
25
|
const migrationsTable = `migrations_${sanitizedService}`;
|
|
@@ -31,7 +33,7 @@ function runMigrations(pool, migrationsDir, service) {
|
|
|
31
33
|
`);
|
|
32
34
|
// Check if migrations directory exists
|
|
33
35
|
if (!fs_1.default.existsSync(migrationsDir)) {
|
|
34
|
-
|
|
36
|
+
logger.log(`No migrations directory found at ${migrationsDir}, skipping migrations...`);
|
|
35
37
|
return;
|
|
36
38
|
}
|
|
37
39
|
// Get all migration files from the provided directory
|
|
@@ -44,10 +46,10 @@ function runMigrations(pool, migrationsDir, service) {
|
|
|
44
46
|
// Run pending migrations
|
|
45
47
|
for (const file of files) {
|
|
46
48
|
if (executedFiles.has(file)) {
|
|
47
|
-
|
|
49
|
+
logger.log(`Migration ${file} already executed, skipping...`);
|
|
48
50
|
continue;
|
|
49
51
|
}
|
|
50
|
-
|
|
52
|
+
logger.log(`Running migration: ${file}`);
|
|
51
53
|
const filePath = path_1.default.join(migrationsDir, file);
|
|
52
54
|
const sql = fs_1.default.readFileSync(filePath, 'utf-8');
|
|
53
55
|
try {
|
|
@@ -55,13 +57,13 @@ function runMigrations(pool, migrationsDir, service) {
|
|
|
55
57
|
yield pool.query(sql);
|
|
56
58
|
// Record that this migration was executed
|
|
57
59
|
yield pool.query(`INSERT INTO ${migrationsTable} (filename) VALUES (?)`, [file]);
|
|
58
|
-
|
|
60
|
+
logger.log(`Migration ${file} completed successfully`);
|
|
59
61
|
}
|
|
60
62
|
catch (error) {
|
|
61
|
-
|
|
63
|
+
logger.error(`Error running migration ${file}:`, error);
|
|
62
64
|
throw error;
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
|
-
|
|
67
|
+
logger.log('All migrations completed for the ' + service + ' service');
|
|
66
68
|
});
|
|
67
69
|
}
|