39 lines
529 B
Go
39 lines
529 B
Go
package api
|
|
|
|
import (
|
|
"log"
|
|
"strings"
|
|
)
|
|
|
|
var dropSQLString = `
|
|
drop table purchase;
|
|
|
|
drop table tags_on_goods;
|
|
|
|
drop table goods;
|
|
|
|
drop table tag;
|
|
|
|
drop table market;
|
|
|
|
drop table users;
|
|
`
|
|
|
|
func drop() {
|
|
sqls := strings.Split(dropSQLString, "\n\n")
|
|
tx, err := db.Begin()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
for _, sql := range sqls {
|
|
log.Println("Dropting table with SQL", sql)
|
|
_, err = tx.Exec(sql)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
tx.Commit()
|
|
log.Println("Successfully drop all tables")
|
|
}
|