Skip to content

Commit

Permalink
Merge pull request #3589 from nichwall/migration_table_check_fix
Browse files Browse the repository at this point in the history
Check that `migrationsMeta` table is well formed instead of just existing
  • Loading branch information
advplyr authored Nov 7, 2024
2 parents 0c244cb + 41fe537 commit a8ec07c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions server/managers/MigrationManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,21 @@ class MigrationManager {
const queryInterface = this.sequelize.getQueryInterface()
let migrationsMetaTableExists = await queryInterface.tableExists(MigrationManager.MIGRATIONS_META_TABLE)

// If the table exists, check that the `version` and `maxVersion` rows exist
if (migrationsMetaTableExists) {
const [{ count }] = await this.sequelize.query("SELECT COUNT(*) as count FROM :migrationsMeta WHERE key IN ('version', 'maxVersion')", {
replacements: { migrationsMeta: MigrationManager.MIGRATIONS_META_TABLE },
type: Sequelize.QueryTypes.SELECT
})
if (count < 2) {
Logger.warn(`[MigrationManager] migrationsMeta table exists but is missing 'version' or 'maxVersion' row. Dropping it...`)
await queryInterface.dropTable(MigrationManager.MIGRATIONS_META_TABLE)
migrationsMetaTableExists = false
}
}

if (this.isDatabaseNew && migrationsMetaTableExists) {
Logger.warn(`[MigrationManager] migrationsMeta table already exists. Dropping it...`)
// This can happen if database was initialized with force: true
await queryInterface.dropTable(MigrationManager.MIGRATIONS_META_TABLE)
migrationsMetaTableExists = false
Expand Down

0 comments on commit a8ec07c

Please sign in to comment.