Skip to content

Commit 0bb38a6

Browse files
Add pgx/v5 and set isolation to serializable level
Following this comment: #862 (comment) And reference PR: https://github.com/golang-migrate/migrate/pull/656/files
1 parent 3edd8b8 commit 0bb38a6

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

database/pgx/pgx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ func runesLastIndex(input []rune, target rune) int {
446446
}
447447

448448
func (p *Postgres) SetVersion(version int, dirty bool) error {
449-
tx, err := p.conn.BeginTx(context.Background(), &sql.TxOptions{})
449+
tx, err := p.conn.BeginTx(context.Background(), &sql.TxOptions{Isolation: sql.LevelSerializable})
450450
if err != nil {
451451
return &database.Error{OrigErr: err, Err: "transaction start failed"}
452452
}

database/pgx/v5/pgx.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,12 @@ func runesLastIndex(input []rune, target rune) int {
337337
}
338338

339339
func (p *Postgres) SetVersion(version int, dirty bool) error {
340-
tx, err := p.conn.BeginTx(context.Background(), &sql.TxOptions{})
340+
tx, err := p.conn.BeginTx(context.Background(), &sql.TxOptions{Isolation: sql.LevelSerializable})
341341
if err != nil {
342342
return &database.Error{OrigErr: err, Err: "transaction start failed"}
343343
}
344344

345-
query := `TRUNCATE ` + quoteIdentifier(p.config.migrationsSchemaName) + `.` + quoteIdentifier(p.config.migrationsTableName)
345+
query := `DELETE FROM ` + quoteIdentifier(p.config.migrationsSchemaName) + `.` + quoteIdentifier(p.config.migrationsTableName)
346346
if _, err := tx.Exec(query); err != nil {
347347
if errRollback := tx.Rollback(); errRollback != nil {
348348
err = errors.Join(err, errRollback)

0 commit comments

Comments
 (0)