fix migration metadata table detection on postgres

This commit is contained in:
Kevin Gatera 2026-03-02 16:58:07 -05:00
parent 453cd2587b
commit f31826c256
No known key found for this signature in database
GPG key ID: F0D9F5932458CFB9

View file

@ -215,7 +215,7 @@ class MigrationManager {
async checkOrCreateMigrationsMetaTable() { async checkOrCreateMigrationsMetaTable() {
const queryInterface = this.sequelize.getQueryInterface() const queryInterface = this.sequelize.getQueryInterface()
let migrationsMetaTableExists = await queryInterface.tableExists(MigrationManager.MIGRATIONS_META_TABLE) let migrationsMetaTableExists = await this.tableExists(MigrationManager.MIGRATIONS_META_TABLE)
// If the table exists, check that the `version` and `maxVersion` rows exist // If the table exists, check that the `version` and `maxVersion` rows exist
if (migrationsMetaTableExists) { if (migrationsMetaTableExists) {
@ -255,6 +255,20 @@ class MigrationManager {
} }
} }
async tableExists(tableName) {
const queryInterface = this.sequelize.getQueryInterface()
if (typeof queryInterface.tableExists === 'function') {
return queryInterface.tableExists(tableName)
}
const tables = await queryInterface.showAllTables()
return tables.some((table) => {
if (typeof table === 'string') return table === tableName
if (table?.tableName) return table.tableName === tableName
return false
})
}
extractVersionFromTag(tag) { extractVersionFromTag(tag) {
if (!tag) return null if (!tag) return null
const versionMatch = tag.match(/^v?(\d+\.\d+\.\d+)/) const versionMatch = tag.match(/^v?(\d+\.\d+\.\d+)/)