From 6ecc142fae0b5f080f9e8b1288066e9cb3bd7ad0 Mon Sep 17 00:00:00 2001 From: mancalvo Date: Wed, 21 Jan 2026 13:42:33 -0300 Subject: [PATCH] chore: run init.sql on migrate up command --- internal/actions/local/migrate/command/ensure_db.go | 11 +++++++++++ internal/actions/local/migrate/command/exec.go | 8 ++++++++ 2 files changed, 19 insertions(+) create mode 100644 internal/actions/local/migrate/command/ensure_db.go diff --git a/internal/actions/local/migrate/command/ensure_db.go b/internal/actions/local/migrate/command/ensure_db.go new file mode 100644 index 0000000..3aacd1a --- /dev/null +++ b/internal/actions/local/migrate/command/ensure_db.go @@ -0,0 +1,11 @@ +package command + +import ( + "github.com/Drafteame/draft/internal/pkg/exec" +) + +func runInitSQL() error { + cmd := `docker exec -i api-local-postgres psql -U root -d postgres -f /docker-entrypoint-initdb.d/init.sql` + _, err := exec.Command(cmd) + return err +} diff --git a/internal/actions/local/migrate/command/exec.go b/internal/actions/local/migrate/command/exec.go index 5885fc1..5c6bd40 100644 --- a/internal/actions/local/migrate/command/exec.go +++ b/internal/actions/local/migrate/command/exec.go @@ -2,6 +2,8 @@ package command import ( "fmt" + + "github.com/Drafteame/draft/internal/pkg/log" ) func (a *Action) Exec() error { @@ -10,6 +12,12 @@ func (a *Action) Exec() error { return fmt.Errorf("failed to load local migrations config: %w", err) } + if a.Input.Command == "up" { + if err := runInitSQL(); err != nil { + log.Warnf("failed to run init sql: %v", err) + } + } + if a.Input.All { if errAll := a.migrateAll(config); errAll != nil { return fmt.Errorf("failed to execute '%s' migration on all databases: %w", a.Input.Command, errAll)