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(bootstrap): fix bug in bootstrap from scratch #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions datamodelutils/postgres_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from collections import namedtuple
import sqlalchemy as sa
from sqlalchemy import MetaData, Table
from sqlalchemy.exc import OperationalError
from sqlalchemy.exc import OperationalError, NoSuchTableError

from . import models

Expand Down Expand Up @@ -160,7 +160,10 @@ def migrate_transaction_snapshots(driver):
"""
md = MetaData(bind=driver.engine)
tablename = models.submission.TransactionSnapshot.__tablename__
snapshots_table = Table(tablename, md, autoload=True)
try:
snapshots_table = Table(tablename, md, autoload=True)
except NoSuchTableError:
return
if "entity_id" not in snapshots_table.c:
# change existing `id` column to `entity_id` which is just node UUID, doesn't
# have to be unique, should not be used as primary key
Expand Down Expand Up @@ -298,6 +301,7 @@ def _create_tables(driver, create_all, timeout):
logger.info('Creating tables (timeout: %d)', timeout)
with driver.session_scope() as session:
connection = session.connection()
connection.execute("SELECT pg_advisory_lock(%s)", hash(create_all) % 2 ** 63)
logger.info("Setting lock_timeout to %d", timeout)

timeout_str = '{}s'.format(int(timeout+1))
Expand Down