Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(migrations): CREATE EXTENSION deadlocks inside migrations global lock #210

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions storage/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ func (d *Database) MigrateSchemaTo(ctx context.Context, target int) error {
return xerrors.Errorf("acquiring schema lock: %w", err)
}

// CREATE EXTENSION cannot run inside a transaction (as part of
hsanjuan marked this conversation as resolved.
Show resolved Hide resolved
// migration), so we run it explicitally here and only when setting
// things up for the first time (#179).
if dbVersion == 0 {
if _, err := d.DB.Exec(`CREATE EXTENSION IF NOT EXISTS timescaledb WITH SCHEMA public`); err != nil {
return xerrors.Errorf("creating timescaledb extension: %w", err)
}
}

// Remember to release the lock
defer func() {
err := SchemaLock.UnlockExclusive(ctx, db)
Expand Down
6 changes: 0 additions & 6 deletions storage/migrations/1_chainwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ import (
func init() {

up := batch(`
--
-- Name: timescaledb; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS timescaledb WITH SCHEMA public;

--
-- Name: miner_sector_event_type; Type: TYPE; Schema: public; Owner: postgres
--
Expand Down