Prepare statement on an existing transaction (#3144)

This should fix an issue with the database being locked for SQLite.
This commit is contained in:
Till 2023-07-07 13:09:39 +02:00 committed by GitHub
parent cc9b695c1e
commit c08c7405db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 { func (m *Migrator) insertMigration(ctx context.Context, txn *sql.Tx, migrationName string) error {
if m.insertStmt == nil { 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 { if err != nil {
return fmt.Errorf("unable to prepare insert statement: %w", err) return fmt.Errorf("unable to prepare insert statement: %w", err)
} }