postgres: fix SetVersion. All requests were executed in different connections so commit/rollback doesn't work correctly

This commit is contained in:
kshvakov 2017-06-23 11:13:54 +03:00
parent 8cd9761d29
commit 94056e51cc
1 changed files with 2 additions and 2 deletions

View File

@ -176,14 +176,14 @@ func (p *Postgres) SetVersion(version int, dirty bool) error {
} }
query := `TRUNCATE "` + p.config.MigrationsTable + `"` query := `TRUNCATE "` + p.config.MigrationsTable + `"`
if _, err := p.db.Exec(query); err != nil { if _, err := tx.Exec(query); err != nil {
tx.Rollback() tx.Rollback()
return &database.Error{OrigErr: err, Query: []byte(query)} return &database.Error{OrigErr: err, Query: []byte(query)}
} }
if version >= 0 { if version >= 0 {
query = `INSERT INTO "` + p.config.MigrationsTable + `" (version, dirty) VALUES ($1, $2)` 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() tx.Rollback()
return &database.Error{OrigErr: err, Query: []byte(query)} return &database.Error{OrigErr: err, Query: []byte(query)}
} }