Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions internal/actions/local/migrate/command/ensure_db.go
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions internal/actions/local/migrate/command/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package command

import (
"fmt"

"github.com/Drafteame/draft/internal/pkg/log"
)

func (a *Action) Exec() error {
Expand All @@ -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)
Expand Down