Skip to content

Commit 2168b7a

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 006d26f commit 2168b7a

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
@@ -447,7 +447,7 @@ func runesLastIndex(input []rune, target rune) int {
447447
}
448448

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

database/pgx/v5/pgx.go

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

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

346-
query := `TRUNCATE ` + quoteIdentifier(p.config.migrationsSchemaName) + `.` + quoteIdentifier(p.config.migrationsTableName)
346+
query := `DELETE FROM ` + quoteIdentifier(p.config.migrationsSchemaName) + `.` + quoteIdentifier(p.config.migrationsTableName)
347347
if _, err := tx.Exec(query); err != nil {
348348
if errRollback := tx.Rollback(); errRollback != nil {
349349
err = multierror.Append(err, errRollback)

0 commit comments

Comments
 (0)