Fix migration statements
This commit is contained in:
parent
c11e2df9ca
commit
1b8b1c0539
|
@ -24,7 +24,7 @@ import (
|
|||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func changeColumnToBigint(x *xorm.Engine, table, column string, nullable, defaultValue bool) (err error) {
|
||||
func changeColumnToBigint(x *xorm.Session, table, column string, nullable, defaultValue bool) (err error) {
|
||||
switch config.DatabaseType.GetString() {
|
||||
case "sqlite":
|
||||
// Sqlite only has one "INTEGER" type which is at the same time int and int64
|
||||
|
@ -39,17 +39,17 @@ func changeColumnToBigint(x *xorm.Engine, table, column string, nullable, defaul
|
|||
def = " DEFAULT 0"
|
||||
}
|
||||
|
||||
_, err := x.Exec("ALTER TABLE " + table + " MODIFY " + column + " BIGINT" + notnull + def)
|
||||
_, err := x.Exec("ALTER TABLE " + table + " MODIFY `" + column + "` BIGINT" + def + notnull)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case "postgres":
|
||||
var notnull = " ALTER COLUMN " + column + " SET "
|
||||
var notnull = " ALTER COLUMN `" + column + "` SET "
|
||||
if !nullable {
|
||||
notnull = "NOT"
|
||||
}
|
||||
notnull += " NULL"
|
||||
_, err := x.Exec("ALTER TABLE " + table + " ALTER COLUMN " + column + " TYPE BIGINT" + notnull)
|
||||
_, err := x.Exec("ALTER TABLE " + table + " ALTER COLUMN `" + column + "` TYPE BIGINT" + notnull)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -180,6 +180,7 @@ func init() {
|
|||
},
|
||||
}
|
||||
|
||||
s := tx.NewSession()
|
||||
for table, cols := range columns {
|
||||
for _, col := range cols {
|
||||
var nullable = false
|
||||
|
@ -195,14 +196,14 @@ func init() {
|
|||
}
|
||||
|
||||
log.Debugf("Migrating %s.%s to bigint", table, col)
|
||||
err := changeColumnToBigint(tx, table, col, nullable, defaultValue)
|
||||
err := changeColumnToBigint(s, table, col, nullable, defaultValue)
|
||||
if err != nil {
|
||||
_ = s.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return s.Commit()
|
||||
},
|
||||
Rollback: func(tx *xorm.Engine) error {
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue