Skip to content

Commit

Permalink
Prepare statement on an existing transaction (#3144)
Browse files Browse the repository at this point in the history
This should fix an issue with the database being locked for SQLite.
  • Loading branch information
S7evinK authored Jul 7, 2023
1 parent cc9b695 commit c08c740
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/sqlutil/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,13 @@ func (m *Migrator) Up(ctx context.Context) error {

func (m *Migrator) insertMigration(ctx context.Context, txn *sql.Tx, migrationName string) error {
if m.insertStmt == nil {
stmt, err := m.db.Prepare(insertVersionSQL)
var stmt *sql.Stmt
var err error
if txn == nil {
stmt, err = m.db.PrepareContext(ctx, insertVersionSQL)
} else {
stmt, err = txn.PrepareContext(ctx, insertVersionSQL)
}
if err != nil {
return fmt.Errorf("unable to prepare insert statement: %w", err)
}
Expand Down

0 comments on commit c08c740

Please sign in to comment.