Fix bug where database migrations wouldn't occur
parent
ac30b71b48
commit
5d111df401
|
@ -40,7 +40,7 @@ async function checkForDatabaseInitialization() {
|
||||||
let latestMigration;
|
let latestMigration;
|
||||||
try {
|
try {
|
||||||
const latestMigrationQuery = `SELECT value FROM metadata WHERE property = 'latest_migration';`;
|
const latestMigrationQuery = `SELECT value FROM metadata WHERE property = 'latest_migration';`;
|
||||||
latestMigration = (await executeQuery(latestMigrationQuery))[0][0];
|
latestMigration = +((await executeQuery(latestMigrationQuery))[0][0]);
|
||||||
} catch {
|
} catch {
|
||||||
latestMigration = 0;
|
latestMigration = 0;
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ async function performMigrations(currentMigration) {
|
||||||
const migrationFileList = fs.readdirSync('database/migrations');
|
const migrationFileList = fs.readdirSync('database/migrations');
|
||||||
const latestMigration = +migrationFileList[migrationFileList.length - 1].slice(0, 1);
|
const latestMigration = +migrationFileList[migrationFileList.length - 1].slice(0, 1);
|
||||||
|
|
||||||
for(let i = currentMigration + 1; i <= latestMigration; i++) {
|
for(let i = +currentMigration + 1; i <= latestMigration; i++) {
|
||||||
const sql = fs.readFileSync(`database/migrations/${i}.sql`).toString();
|
const sql = fs.readFileSync(`database/migrations/${i}.sql`).toString();
|
||||||
await executeQuery(sql);
|
await executeQuery(sql);
|
||||||
console.log(`Performed database migration ${i}`);
|
console.log(`Performed database migration ${i}`);
|
||||||
|
|
Reference in New Issue