1
0
mirror of https://github.com/beego/bee.git synced 2024-11-25 20:10:55 +00:00

change directory

This commit is contained in:
ZhengYang 2014-08-12 16:04:50 +08:00
parent 4c735647c3
commit 9a728714aa

View File

@ -48,10 +48,6 @@ bee migrate refresh
`, `,
} }
const (
TMP_DIR = "temp"
)
var mDriver docValue var mDriver docValue
var mConn docValue var mConn docValue
@ -218,9 +214,9 @@ func runMigrationBinary(filename string) {
} }
} }
func cleanUpMigrationFiles(tmpPath string) { func removeMigrationBinary(path string) {
if err := os.RemoveAll(tmpPath); err != nil { if err := os.Remove(path); err != nil {
ColorLog("[ERRO] Could not remove temporary migration directory: %s\n", err) ColorLog("[ERRO] Could not remove migration binary: %s\n", err)
os.Exit(2) os.Exit(2)
} }
} }
@ -242,7 +238,7 @@ func migrateRefresh(driver, connStr string) {
} }
func migrate(goal, driver, connStr string) { func migrate(goal, driver, connStr string) {
filename := path.Join(TMP_DIR, "migrate") filepath := path.Join("database", "migrations", "migrate")
// connect to database // connect to database
db, err := sql.Open(driver, connStr) db, err := sql.Open(driver, connStr)
if err != nil { if err != nil {
@ -252,11 +248,10 @@ func migrate(goal, driver, connStr string) {
defer db.Close() defer db.Close()
checkForSchemaUpdateTable(db) checkForSchemaUpdateTable(db)
latestName, latestTime := getLatestMigration(db) latestName, latestTime := getLatestMigration(db)
createTempMigrationDir(TMP_DIR) writeMigrationSourceFile(filepath, driver, connStr, latestTime, latestName, goal)
writeMigrationSourceFile(filename, driver, connStr, latestTime, latestName, goal) buildMigrationBinary(filepath)
buildMigrationBinary(filename) runMigrationBinary(filepath)
runMigrationBinary(filename) removeMigrationBinary(filepath)
cleanUpMigrationFiles(TMP_DIR)
} }
const ( const (