0
0
Fork 0
mirror of https://github.com/matrix-org/dendrite synced 2024-06-13 09:58:59 +02:00

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 {
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)
}