Skip to content

Commit

Permalink
Change migrator Status to accept a custom io.Writer (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislas-m committed Dec 9, 2019
1 parent 589293a commit 4e59167
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 26 deletions.
2 changes: 1 addition & 1 deletion config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func Test_LoadsConnectionsFromConfig(t *testing.T) {
r := require.New(t)

r.NoError(LoadConfigFile())
if DialectSupported("sqlite3") {
r.Equal(5, len(Connections))
Expand Down
9 changes: 5 additions & 4 deletions migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pop

import (
"fmt"
"io"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -197,13 +198,13 @@ func (m Migrator) CreateSchemaMigrations() error {
}

// Status prints out the status of applied/pending migrations.
func (m Migrator) Status() error {
func (m Migrator) Status(out io.Writer) error {
err := m.CreateSchemaMigrations()
if err != nil {
return err
}
w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', tabwriter.TabIndent)
fmt.Fprintln(w, "Version\tName\tStatus\t")
w := tabwriter.NewWriter(out, 0, 0, 3, ' ', tabwriter.TabIndent)
_, _ = fmt.Fprintln(w, "Version\tName\tStatus\t")
for _, mf := range m.Migrations["up"] {
exists, err := m.Connection.Where("version = ?", mf.Version).Exists(m.Connection.MigrationTableName())
if err != nil {
Expand All @@ -213,7 +214,7 @@ func (m Migrator) Status() error {
if exists {
state = "Applied"
}
fmt.Fprintf(w, "%s\t%s\t%s\t\n", mf.Version, mf.Name, state)
_, _ = fmt.Fprintf(w, "%s\t%s\t%s\t\n", mf.Version, mf.Name, state)
}
return w.Flush()
}
Expand Down
23 changes: 3 additions & 20 deletions packrd/packed-packr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion soda/cmd/migrate_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"github.com/gobuffalo/pop/v5"
"github.com/spf13/cobra"
"os"
)

var migrateStatusCmd = &cobra.Command{
Expand All @@ -13,7 +14,7 @@ var migrateStatusCmd = &cobra.Command{
if err != nil {
return err
}
return mig.Status()
return mig.Status(os.Stdout)
},
}

Expand Down

0 comments on commit 4e59167

Please sign in to comment.