separate atlas command

This commit is contained in:
dpurbosakti
2025-09-12 08:57:05 +07:00
parent dfaf6e8d29
commit 20bc8419d0
10 changed files with 155 additions and 130 deletions
@@ -7,7 +7,7 @@ type Patient struct {
Active bool `json:"active"`
// Name []HumanName `json:"name"`
// Telecom []ContactPoint `json:"telecom"`
Gender string `json:"gender"`
Gender string `json:"gender" gorm:"size:10"`
BirthDate string `json:"birthDate"`
DeceasedBool bool `json:"deceasedBoolean"`
// Address []Address `json:"address"`
-24
View File
@@ -4,7 +4,6 @@ import (
"fmt"
"io"
"os"
"os/exec"
"ariga.io/atlas-provider-gorm/gormschema"
"gorm.io/gorm"
@@ -36,30 +35,7 @@ func getEntities(input string) []any {
return nil
}
func runAtlas(args ...string) error {
cmd := exec.Command("atlas", args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
func logMsg(msg string) {
fmt.Fprintln(os.Stderr, msg)
}
func Migrate(input string) {
loader(input)
logMsg("Running atlas migrate diff...")
if err := runAtlas("migrate", "diff", "--env", "gorm"); err != nil {
logMsg(fmt.Sprintf("Failed to run diff: %v", err))
return
}
logMsg("Running atlas migrate apply...")
if err := runAtlas("migrate", "apply", "--env", "gorm"); err != nil {
logMsg(fmt.Sprintf("Failed to run apply: %v", err))
return
}
logMsg("Migration complete")
}