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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user