@@ 62,7 62,7 @@ func (db *DB) init(ctx context.Context) error {
}
func (db *DB) upgrade(ctx context.Context) (version int, err error) {
- if err := db.db.QueryRow("PRAGMA user_version").Scan(&version); err != nil {
+ if err := db.db.QueryRowContext(ctx, "PRAGMA user_version").Scan(&version); err != nil {
return 0, fmt.Errorf("failed to query schema version: %v", err)
}
@@ 72,26 72,26 @@ func (db *DB) upgrade(ctx context.Context) (version int, err error) {
return version, fmt.Errorf("sinwon (version %d) older than schema (version %d)", len(migrations), version)
}
- tx, err := db.db.Begin()
+ tx, err := db.db.BeginTx(ctx, nil)
if err != nil {
return version, err
}
defer tx.Rollback()
if version == 0 {
- if _, err := tx.Exec(schema); err != nil {
+ if _, err := tx.ExecContext(ctx, schema); err != nil {
return version, fmt.Errorf("failed to initialize schema: %v", err)
}
} else {
for i := version; i < len(migrations); i++ {
- if _, err := tx.Exec(migrations[i]); err != nil {
+ if _, err := tx.ExecContext(ctx, migrations[i]); err != nil {
return version, fmt.Errorf("failed to execute migration #%v: %v", i, err)
}
}
}
// For some reason prepared statements don't work here
- _, err = tx.Exec(fmt.Sprintf("PRAGMA user_version = %d", len(migrations)))
+ _, err = tx.ExecContext(ctx, fmt.Sprintf("PRAGMA user_version = %d", len(migrations)))
if err != nil {
return version, fmt.Errorf("failed to bump schema version: %v", err)
}