Skip to content

Commit

Permalink
Remove trailing newline from log calls
Browse files Browse the repository at this point in the history
This way there is no need to clean up a newline when implementing your
own goose.Logger. The standard log package being used by default will
add a newline if it is not there.
  • Loading branch information
eest committed Dec 19, 2024
1 parent ca6f0b8 commit 1f07a9b
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions cmd/goose/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ func main() {
driver, dbstring, command := args[0], args[1], args[2]
db, err := goose.OpenDBWithDriver(driver, normalizeDBString(driver, dbstring, *certfile, *sslcert, *sslkey))
if err != nil {
log.Fatalf("-dbstring=%q: %v\n", dbstring, err)
log.Fatalf("-dbstring=%q: %v", dbstring, err)
}
defer func() {
if err := db.Close(); err != nil {
log.Fatalf("goose: failed to close DB: %v\n", err)
log.Fatalf("goose: failed to close DB: %v", err)
}
}()

Expand Down
2 changes: 1 addition & 1 deletion create.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func CreateWithTemplate(db *sql.DB, dir string, tmpl *template.Template, name, m
return fmt.Errorf("failed to execute tmpl: %w", err)
}

log.Printf("Created new file: %s\n", f.Name())
log.Printf("Created new file: %s", f.Name())
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions down.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ func DownToContext(ctx context.Context, db *sql.DB, dir string, version int64, o
}

if currentVersion == 0 {
log.Printf("goose: no migrations to run. current version: %d\n", currentVersion)
log.Printf("goose: no migrations to run. current version: %d", currentVersion)
return nil
}
current, err := migrations.Current(currentVersion)
if err != nil {
log.Printf("goose: migration file not found for current version (%d), error: %s\n", currentVersion, err)
log.Printf("goose: migration file not found for current version (%d), error: %s", currentVersion, err)
return err
}

if current.Version <= version {
log.Printf("goose: no migrations to run. current version: %d\n", currentVersion)
log.Printf("goose: no migrations to run. current version: %d", currentVersion)
return nil
}

Expand All @@ -102,6 +102,6 @@ func downToNoVersioning(ctx context.Context, db *sql.DB, migrations Migrations,
return err
}
}
log.Printf("goose: down to current file version: %d\n", finalVersion)
log.Printf("goose: down to current file version: %d", finalVersion)
return nil
}
4 changes: 2 additions & 2 deletions examples/go-migrations/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func main() {

db, err := goose.OpenDBWithDriver("sqlite", dbstring)
if err != nil {
log.Fatalf("goose: failed to open DB: %v\n", err)
log.Fatalf("goose: failed to open DB: %v", err)
}

defer func() {
if err := db.Close(); err != nil {
log.Fatalf("goose: failed to close DB: %v\n", err)
log.Fatalf("goose: failed to close DB: %v", err)
}
}()

Expand Down
8 changes: 4 additions & 4 deletions migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ func (m *Migration) run(ctx context.Context, db *sql.DB, direction bool) error {
finish := truncateDuration(time.Since(start))

if len(statements) > 0 {
log.Printf("OK %s (%s)\n", filepath.Base(m.Source), finish)
log.Printf("OK %s (%s)", filepath.Base(m.Source), finish)
} else {
log.Printf("EMPTY %s (%s)\n", filepath.Base(m.Source), finish)
log.Printf("EMPTY %s (%s)", filepath.Base(m.Source), finish)
}

case ".go":
Expand Down Expand Up @@ -280,9 +280,9 @@ func (m *Migration) run(ctx context.Context, db *sql.DB, direction bool) error {
}
finish := truncateDuration(time.Since(start))
if !empty {
log.Printf("OK %s (%s)\n", filepath.Base(m.Source), finish)
log.Printf("OK %s (%s)", filepath.Base(m.Source), finish)
} else {
log.Printf("EMPTY %s (%s)\n", filepath.Base(m.Source), finish)
log.Printf("EMPTY %s (%s)", filepath.Base(m.Source), finish)
}
}
return nil
Expand Down
12 changes: 6 additions & 6 deletions status.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ func StatusContext(ctx context.Context, db *sql.DB, dir string, opts ...OptionsF
return fmt.Errorf("failed to collect migrations: %w", err)
}
if option.noVersioning {
log.Printf(" Applied At Migration\n")
log.Printf(" =======================================\n")
log.Printf(" Applied At Migration")
log.Printf(" =======================================")
for _, current := range migrations {
log.Printf(" %-24s -- %v\n", "no versioning", filepath.Base(current.Source))
log.Printf(" %-24s -- %v", "no versioning", filepath.Base(current.Source))
}
return nil
}
Expand All @@ -39,8 +39,8 @@ func StatusContext(ctx context.Context, db *sql.DB, dir string, opts ...OptionsF
return fmt.Errorf("failed to ensure DB version: %w", err)
}

log.Printf(" Applied At Migration\n")
log.Printf(" =======================================\n")
log.Printf(" Applied At Migration")
log.Printf(" =======================================")
for _, migration := range migrations {
if err := printMigrationStatus(ctx, db, migration.Version, filepath.Base(migration.Source)); err != nil {
return fmt.Errorf("failed to print status: %w", err)
Expand All @@ -59,6 +59,6 @@ func printMigrationStatus(ctx context.Context, db *sql.DB, version int64, script
if m != nil && m.IsApplied {
appliedAt = m.Timestamp.Format(time.ANSIC)
}
log.Printf(" %-24s -- %v\n", appliedAt, script)
log.Printf(" %-24s -- %v", appliedAt, script)
return nil
}
6 changes: 3 additions & 3 deletions up.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ func UpToContext(ctx context.Context, db *sql.DB, dir string, version int64, opt
return err
}

log.Printf("goose: no migrations to run. current version: %d\n", current)
log.Printf("goose: no migrations to run. current version: %d", current)
} else {
log.Printf("goose: successfully migrated database to version: %d\n", current)
log.Printf("goose: successfully migrated database to version: %d", current)
}

// At this point there are no more migrations to apply. But we need to maintain
Expand Down Expand Up @@ -153,7 +153,7 @@ func upToNoVersioning(ctx context.Context, db *sql.DB, migrations Migrations, ve
}
finalVersion = current.Version
}
log.Printf("goose: up to current file version: %d\n", finalVersion)
log.Printf("goose: up to current file version: %d", finalVersion)
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ func VersionContext(ctx context.Context, db *sql.DB, dir string, opts ...Options
if len(migrations) > 0 {
current = migrations[len(migrations)-1].Version
}
log.Printf("goose: file version %v\n", current)
log.Printf("goose: file version %v", current)
return nil
}

current, err := GetDBVersionContext(ctx, db)
if err != nil {
return err
}
log.Printf("goose: version %v\n", current)
log.Printf("goose: version %v", current)
return nil
}

Expand Down

0 comments on commit 1f07a9b

Please sign in to comment.