Migration Automation
- Adding docker DB template, - migrationscript, - config update, . adding migration to bee rs
This commit is contained in:
@ -13,9 +13,17 @@ import (
|
||||
var conf companyDB.DBConfig
|
||||
|
||||
func main() {
|
||||
migrateSystem := false
|
||||
migType := ""
|
||||
if len(os.Args) > 1 {
|
||||
migType = os.Args[1]
|
||||
if os.Args[1] == "system" {
|
||||
migrateSystem = true
|
||||
if len(os.Args) > 2 {
|
||||
migType = os.Args[2]
|
||||
}
|
||||
} else {
|
||||
migType = os.Args[1]
|
||||
}
|
||||
}
|
||||
|
||||
companyDB.InitCompanyDBService()
|
||||
@ -28,6 +36,12 @@ func main() {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
if migrateSystem {
|
||||
fmt.Printf("SYSTEM DB: migrate %s\n", migType)
|
||||
migrateDbName("system", migType)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("migrate %s\n", migType)
|
||||
|
||||
for result.Next() {
|
||||
@ -58,21 +72,28 @@ func printOutput(outs []byte) {
|
||||
}
|
||||
|
||||
func migrateDbName(dbName, migType string) {
|
||||
connString := fmt.Sprintf("--conn=\"postgres://%s:%s@%s:%d/%s?sslmode=%s\"", conf.User, conf.Password, conf.Host, conf.Port, dbName, conf.Ssl)
|
||||
fmt.Println(connString)
|
||||
dir := ""
|
||||
if dbName == "system" {
|
||||
dir = "--dir=database/systemmigrations"
|
||||
}
|
||||
|
||||
connString := fmt.Sprintf("--conn=postgres://%s:%s@%s:%d/%s?sslmode=%s", conf.User, conf.Password, conf.Host, conf.Port, dbName, conf.Ssl)
|
||||
cmdString := fmt.Sprintf("%s%s", os.Getenv("GOPATH"), "/bin/bee")
|
||||
cmd := exec.Command(cmdString, "migrate", migType, connString)
|
||||
|
||||
var cmd *exec.Cmd
|
||||
if migType != "" {
|
||||
cmd = exec.Command(cmdString, "migrate", migType, connString, dir)
|
||||
} else {
|
||||
cmd = exec.Command(cmdString, "migrate", connString, dir)
|
||||
}
|
||||
|
||||
// Combine stdout and stderr
|
||||
printCommand(cmd)
|
||||
_, err := cmd.CombinedOutput()
|
||||
printError(err)
|
||||
// printOutput(output)
|
||||
|
||||
// check what migration type
|
||||
// query system table
|
||||
// //run all or single tenant, check if tenant exists
|
||||
// execute commands (blocking!)
|
||||
// print out all states in new lines with green or red and error
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
printError(err)
|
||||
printOutput(output)
|
||||
} else {
|
||||
fmt.Println("Success")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user