Skip to content

Commit

Permalink
Use Postgres.conn rather than Postgres.db to handle table locking
Browse files Browse the repository at this point in the history
  • Loading branch information
bclarkx2 committed Jan 30, 2024
1 parent d44e9a5 commit e37c47a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions database/pgx/pgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func (p *Postgres) releaseTableLock() error {
}

query := "DELETE FROM " + pq.QuoteIdentifier(p.config.LockTable) + " WHERE lock_id = $1"
if _, err := p.db.Exec(query, aid); err != nil {
if _, err := p.conn.ExecContext(context.Background(), query, aid); err != nil {
return database.Error{OrigErr: err, Err: "failed to release migration lock", Query: []byte(query)}
}

Expand Down Expand Up @@ -615,15 +615,15 @@ func (p *Postgres) ensureLockTable() error {

var count int
query := `SELECT COUNT(1) FROM information_schema.tables WHERE table_name = $1 AND table_schema = (SELECT current_schema()) LIMIT 1`
if err := p.db.QueryRow(query, p.config.LockTable).Scan(&count); err != nil {
if err := p.conn.QueryRowContext(context.Background(), query, p.config.LockTable).Scan(&count); err != nil {
return &database.Error{OrigErr: err, Query: []byte(query)}
}
if count == 1 {
return nil
}

query = `CREATE TABLE ` + pq.QuoteIdentifier(p.config.LockTable) + ` (lock_id BIGINT NOT NULL PRIMARY KEY)`
if _, err := p.db.Exec(query); err != nil {
if _, err := p.conn.ExecContext(context.Background(), query); err != nil {
return &database.Error{OrigErr: err, Query: []byte(query)}
}

Expand Down

0 comments on commit e37c47a

Please sign in to comment.