first commit
This commit is contained in:
38
pkg/api/drop.go
Normal file
38
pkg/api/drop.go
Normal file
@@ -0,0 +1,38 @@
|
||||
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")
|
||||
}
|
||||
Reference in New Issue
Block a user