Skip to content

Commit

Permalink
fix: cleanup routine order
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Aug 12, 2022
1 parent 8cba961 commit 68155b4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
3 changes: 0 additions & 3 deletions internal/db/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ func Run(ctx context.Context, dryRun bool, username, password, database string,
if err := utils.LoadConfigFS(fsys); err != nil {
return err
}
if err := utils.AssertIsLinkedFS(fsys); err != nil {
return err
}

projectRef, err := utils.LoadProjectRef(fsys)
if err != nil {
Expand Down
21 changes: 10 additions & 11 deletions internal/db/remote/changes/changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,15 @@ var (
)

func run(p utils.Program, ctx context.Context, username, password, database string, fsys afero.Fs) error {
defer cleanup()
projectRef, err := utils.LoadProjectRef(fsys)
if err != nil {
return err
}
conn, err := commit.ConnectRemotePostgres(ctx, username, password, database, projectRef)
if err != nil {
return err
}
defer conn.Close(context.Background())

_, _ = utils.Docker.NetworkCreate(
ctx,
Expand All @@ -85,16 +93,7 @@ func run(p utils.Program, ctx context.Context, username, password, database stri
},
},
)

projectRef, err := utils.LoadProjectRef(fsys)
if err != nil {
return err
}
conn, err := commit.ConnectRemotePostgres(ctx, username, password, database, projectRef)
if err != nil {
return err
}
defer conn.Close(context.Background())
defer cleanup()

p.Send(utils.StatusMsg("Pulling images..."))

Expand Down
24 changes: 10 additions & 14 deletions internal/db/remote/commit/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ func Run(ctx context.Context, username, password, database string, fsys afero.Fs
if err := utils.LoadConfigFS(fsys); err != nil {
return err
}
if err := utils.AssertIsLinkedFS(fsys); err != nil {
return err
}
}

ctx, cancel := context.WithCancel(ctx)
Expand Down Expand Up @@ -85,7 +82,15 @@ const (
)

func run(p utils.Program, ctx context.Context, username, password, database string, fsys afero.Fs) error {
defer cleanup()
projectRef, err := utils.LoadProjectRef(fsys)
if err != nil {
return err
}
conn, err := ConnectRemotePostgres(ctx, username, password, database, projectRef)
if err != nil {
return err
}
defer conn.Close(context.Background())

_, _ = utils.Docker.NetworkCreate(
ctx,
Expand All @@ -98,16 +103,7 @@ func run(p utils.Program, ctx context.Context, username, password, database stri
},
},
)

projectRef, err := utils.LoadProjectRef(fsys)
if err != nil {
return err
}
conn, err := ConnectRemotePostgres(ctx, username, password, database, projectRef)
if err != nil {
return err
}
defer conn.Close(context.Background())
defer cleanup()

p.Send(utils.StatusMsg("Pulling images..."))

Expand Down

0 comments on commit 68155b4

Please sign in to comment.