mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
server-esm: Handle migrations asynchronously
This commit is contained in:
parent
3852753a89
commit
86808c07bd
@ -67,12 +67,12 @@ async function migrate() {
|
|||||||
|
|
||||||
cls.setMigrationRunning(true);
|
cls.setMigrationRunning(true);
|
||||||
|
|
||||||
sql.transactional(() => {
|
sql.transactional(async () => {
|
||||||
for (const mig of migrations) {
|
for (const mig of migrations) {
|
||||||
try {
|
try {
|
||||||
log.info(`Attempting migration to version ${mig.dbVersion}`);
|
log.info(`Attempting migration to version ${mig.dbVersion}`);
|
||||||
|
|
||||||
executeMigration(mig);
|
await executeMigration(mig);
|
||||||
|
|
||||||
sql.execute(`UPDATE options
|
sql.execute(`UPDATE options
|
||||||
SET value = ?
|
SET value = ?
|
||||||
@ -96,7 +96,7 @@ async function migrate() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeMigration(mig: MigrationInfo) {
|
async function executeMigration(mig: MigrationInfo) {
|
||||||
if (mig.type === 'sql') {
|
if (mig.type === 'sql') {
|
||||||
const migrationSql = fs.readFileSync(`${resourceDir.MIGRATIONS_DIR}/${mig.file}`).toString('utf8');
|
const migrationSql = fs.readFileSync(`${resourceDir.MIGRATIONS_DIR}/${mig.file}`).toString('utf8');
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ function executeMigration(mig: MigrationInfo) {
|
|||||||
} else if (mig.type === 'js') {
|
} else if (mig.type === 'js') {
|
||||||
console.log("Migration with JS module");
|
console.log("Migration with JS module");
|
||||||
|
|
||||||
const migrationModule = require(`${resourceDir.MIGRATIONS_DIR}/${mig.file}`);
|
const migrationModule = await import(`${resourceDir.MIGRATIONS_DIR}/${mig.file}`);
|
||||||
migrationModule();
|
migrationModule();
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Unknown migration type '${mig.type}'`);
|
throw new Error(`Unknown migration type '${mig.type}'`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user