fix: file and file_meta migrations (#112611)

* fix file and file_meta migrations to check the database state to decide which migration to run
This commit is contained in:
Will Assis
2025-10-21 12:46:32 -04:00
committed by GitHub
parent 7678fc9de1
commit 545b7bf8ff
2 changed files with 160 additions and 0 deletions
@@ -46,3 +46,28 @@ type IfColumnNotExistsCondition struct {
func (c *IfColumnNotExistsCondition) SQL(dialect Dialect) (string, []interface{}) {
return dialect.ColumnCheckSQL(c.TableName, c.ColumnName)
}
type IfColumnExistsCondition struct {
ExistsMigrationCondition
TableName string
ColumnName string
}
func (c *IfColumnExistsCondition) SQL(dialect Dialect) (string, []interface{}) {
return dialect.ColumnCheckSQL(c.TableName, c.ColumnName)
}
type IfPrimaryKeyNotExistsCondition struct {
NotExistsMigrationCondition
TableName string
ColumnName string
}
func (c *IfPrimaryKeyNotExistsCondition) SQL(dialect Dialect) (string, []interface{}) {
// only use it with mysql
if dialect.DriverName() == "mysql" {
return "SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME=? AND COLUMN_KEY='PRI'", []interface{}{c.TableName}
}
return "", nil
}