adjust to new xorm structures
This commit is contained in:
parent
561cd0b753
commit
55afb620e8
|
@ -140,8 +140,8 @@ func (session *Session) dropTableCols(beanOrTableName interface{}, cols []string
|
||||||
|
|
||||||
// TODO: This will not work if there are foreign keys
|
// TODO: This will not work if there are foreign keys
|
||||||
|
|
||||||
switch session.engine.dialect.DBType() {
|
switch session.engine.dialect.URI().DBType {
|
||||||
case core.SQLITE:
|
case schemas.SQLITE:
|
||||||
// First drop the indexes on the columns
|
// First drop the indexes on the columns
|
||||||
res, errIndex := session.Query(fmt.Sprintf("PRAGMA index_list(`%s`)", tableName))
|
res, errIndex := session.Query(fmt.Sprintf("PRAGMA index_list(`%s`)", tableName))
|
||||||
if errIndex != nil {
|
if errIndex != nil {
|
||||||
|
@ -216,7 +216,7 @@ func (session *Session) dropTableCols(beanOrTableName interface{}, cols []string
|
||||||
if _, err := session.Exec(fmt.Sprintf("ALTER TABLE `new_%s_new` RENAME TO `%s`", tableName, tableName)); err != nil {
|
if _, err := session.Exec(fmt.Sprintf("ALTER TABLE `new_%s_new` RENAME TO `%s`", tableName, tableName)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case core.POSTGRES:
|
case schemas.POSTGRES:
|
||||||
columns := ""
|
columns := ""
|
||||||
for _, col := range cols {
|
for _, col := range cols {
|
||||||
if columns != "" {
|
if columns != "" {
|
||||||
|
@ -227,7 +227,7 @@ func (session *Session) dropTableCols(beanOrTableName interface{}, cols []string
|
||||||
if _, err := session.Exec(fmt.Sprintf("ALTER TABLE `%s` %s", tableName, columns)); err != nil {
|
if _, err := session.Exec(fmt.Sprintf("ALTER TABLE `%s` %s", tableName, columns)); err != nil {
|
||||||
return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, cols, err)
|
return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, cols, err)
|
||||||
}
|
}
|
||||||
case core.MYSQL:
|
case schemas.MYSQL:
|
||||||
// Drop indexes on columns first
|
// Drop indexes on columns first
|
||||||
sql := fmt.Sprintf("SHOW INDEX FROM %s WHERE column_name IN ('%s')", tableName, strings.Join(cols, "','"))
|
sql := fmt.Sprintf("SHOW INDEX FROM %s WHERE column_name IN ('%s')", tableName, strings.Join(cols, "','"))
|
||||||
res, err := session.Query(sql)
|
res, err := session.Query(sql)
|
||||||
|
@ -255,7 +255,7 @@ func (session *Session) dropTableCols(beanOrTableName interface{}, cols []string
|
||||||
if _, err := session.Exec(fmt.Sprintf("ALTER TABLE `%s` %s", tableName, columns)); err != nil {
|
if _, err := session.Exec(fmt.Sprintf("ALTER TABLE `%s` %s", tableName, columns)); err != nil {
|
||||||
return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, cols, err)
|
return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, cols, err)
|
||||||
}
|
}
|
||||||
case core.MSSQL:
|
case schemas.MSSQL:
|
||||||
columns := ""
|
columns := ""
|
||||||
for _, col := range cols {
|
for _, col := range cols {
|
||||||
if columns != "" {
|
if columns != "" {
|
||||||
|
@ -282,7 +282,7 @@ func (session *Session) dropTableCols(beanOrTableName interface{}, cols []string
|
||||||
}
|
}
|
||||||
|
|
||||||
return session.Commit()
|
return session.Commit()
|
||||||
case core.ORACLE:
|
case schemas.ORACLE:
|
||||||
return fmt.Errorf("not implemented for oracle")
|
return fmt.Errorf("not implemented for oracle")
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unrecognized DB")
|
return fmt.Errorf("unrecognized DB")
|
||||||
|
|
Loading…
Reference in New Issue