Skip to content

Commit

Permalink
postgres: fix SetVersion. All requests were executed in different con…
Browse files Browse the repository at this point in the history
…nections so commit/rollback doesn't work correctly
  • Loading branch information
kshvakov committed Jun 23, 2017
1 parent 8cd9761 commit 94056e5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,14 @@ func (p *Postgres) SetVersion(version int, dirty bool) error {
}

query := `TRUNCATE "` + p.config.MigrationsTable + `"`
if _, err := p.db.Exec(query); err != nil {
if _, err := tx.Exec(query); err != nil {
tx.Rollback()
return &database.Error{OrigErr: err, Query: []byte(query)}
}

if version >= 0 {
query = `INSERT INTO "` + p.config.MigrationsTable + `" (version, dirty) VALUES ($1, $2)`
if _, err := p.db.Exec(query, version, dirty); err != nil {
if _, err := tx.Exec(query, version, dirty); err != nil {
tx.Rollback()
return &database.Error{OrigErr: err, Query: []byte(query)}
}
Expand Down

0 comments on commit 94056e5

Please sign in to comment.