fix: make migrations idempotent, pass checkColumnExists to all migrations
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import logger from '../utils/logger.js';
|
||||
import { checkColumnExists } from './runner.js';
|
||||
|
||||
export default async function migration008(db) {
|
||||
if (await checkColumnExists(db, 'users', 'language')) {
|
||||
export default async function migration008(db, checkColumnExists) {
|
||||
if (await checkColumnExists('users', 'language')) {
|
||||
logger.info('Migration 008: language column already exists, skipping');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import logger from '../utils/logger.js';
|
||||
import { checkColumnExists } from './runner.js';
|
||||
|
||||
export default async function migration009(db) {
|
||||
if (await checkColumnExists(db, 'users', 'language_set')) {
|
||||
export default async function migration009(db, checkColumnExists) {
|
||||
if (await checkColumnExists('users', 'language_set')) {
|
||||
logger.info('Migration 009: language_set column already exists, skipping');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -48,11 +48,7 @@ export async function runMigrations() {
|
||||
|
||||
for (let i = currentVersion; i < migrations.length; i++) {
|
||||
logger.info({ migration: i + 1, total: migrations.length }, 'Running migration');
|
||||
if (i === 1) {
|
||||
await migrations[i](db, checkColumnExists);
|
||||
} else {
|
||||
await migrations[i](db);
|
||||
}
|
||||
await migrations[i](db, checkColumnExists);
|
||||
await db.runAsync(
|
||||
`INSERT OR REPLACE INTO _meta (key, value) VALUES ('schema_version', ?)`,
|
||||
[String(i + 1)]
|
||||
|
||||
Reference in New Issue
Block a user