Skip to content

Commit

Permalink
root: only set the schema version once, at the end
Browse files Browse the repository at this point in the history
This avouds a bit of duplication.
  • Loading branch information
vmiklos committed Oct 4, 2024
1 parent 281b973 commit f1c1955
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,6 @@ func initDatabase(ctx *Context) error {
if err != nil {
return fmt.Errorf("db.Exec() failed: %s", err)
}

query, err = ctx.Database.Prepare("pragma user_version = 1")
if err != nil {
return fmt.Errorf("db.Prepare() failed: %s", err)
}
_, err = query.Exec()
if err != nil {
return fmt.Errorf("db.Exec() failed: %s", err)
}
ctx.DatabaseMigrated = true
}

Expand All @@ -203,16 +194,18 @@ func initDatabase(ctx *Context) error {
if err != nil {
return fmt.Errorf("db.Exec() failed: %s", err)
}
ctx.DatabaseMigrated = true
}

query, err = ctx.Database.Prepare("pragma user_version = 2")
if ctx.DatabaseMigrated {
query, err := ctx.Database.Prepare("pragma user_version = 2")
if err != nil {
return fmt.Errorf("db.Prepare() failed: %s", err)
}
_, err = query.Exec()
if err != nil {
return fmt.Errorf("db.Exec() failed: %s", err)
}
ctx.DatabaseMigrated = true
}

return nil
Expand Down

0 comments on commit f1c1955

Please sign in to comment.