fix(migration): TypeScript migrations not run

This commit is contained in:
Elian Doran 2025-03-02 19:59:50 +02:00
parent a80c3e32f1
commit f04e747786
No known key found for this signature in database

View File

@ -36,7 +36,7 @@ async function migrate() {
const migrations = migrationFiles const migrations = migrationFiles
.map((file) => { .map((file) => {
const match = file.match(/^([0-9]{4})__([a-zA-Z0-9_ ]+)\.(sql|js)$/); const match = file.match(/^([0-9]{4})__([a-zA-Z0-9_ ]+)\.(sql|js|ts)$/);
if (!match) { if (!match) {
return null; return null;
} }
@ -82,6 +82,7 @@ async function migrate() {
log.info(`Migration to version ${mig.dbVersion} has been successful.`); log.info(`Migration to version ${mig.dbVersion} has been successful.`);
} catch (e: any) { } catch (e: any) {
console.error(e);
crash(t("migration.error_message", { version: mig.dbVersion, stack: e.stack })); crash(t("migration.error_message", { version: mig.dbVersion, stack: e.stack }));
break; // crash() is sometimes async break; // crash() is sometimes async
} }
@ -102,7 +103,7 @@ async function executeMigration(mig: MigrationInfo) {
console.log(`Migration with SQL script: ${migrationSql}`); console.log(`Migration with SQL script: ${migrationSql}`);
sql.executeScript(migrationSql); sql.executeScript(migrationSql);
} else if (mig.type === "js") { } else if (mig.type === "js" || mig.type === "ts") {
console.log("Migration with JS module"); console.log("Migration with JS module");
const migrationModule = await import(`${resourceDir.MIGRATIONS_DIR}/${mig.file}`); const migrationModule = await import(`${resourceDir.MIGRATIONS_DIR}/${mig.file}`);