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