Skip to content

Commit dcba639

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 a549794 commit dcba639

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

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

database/pgx/v5/pgx.go

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

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

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

0 commit comments

Comments
 (0)