Skip to content

Commit

Permalink
Merge pull request #2738 from ckan/2234-further-migration-checks
Browse files Browse the repository at this point in the history
[#2234] Improve datastore connection checks on migration
  • Loading branch information
wardi committed Nov 19, 2015
2 parents 0f50cbf + b040828 commit 9635971
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions ckan/migration/versions/081_set_datastore_active.py
@@ -1,6 +1,7 @@
import json
from sqlalchemy import create_engine
from sqlalchemy.sql import text
from sqlalchemy.exc import SQLAlchemyError
from pylons import config


Expand All @@ -12,11 +13,20 @@ def upgrade(migrate_engine):
if not datastore_connection_url:
return

datastore_engine = create_engine(datastore_connection_url)
try:
datastore_engine = create_engine(datastore_connection_url)
except SQLAlchemyError:
return

try:
datastore_connection = datastore_engine.connect()
except SQLAlchemyError:
datastore_engine.dispose()
return

try:

resources_in_datastore = datastore_engine.execute('''
resources_in_datastore = datastore_connection.execute('''
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
Expand Down Expand Up @@ -51,4 +61,5 @@ def upgrade(migrate_engine):
WHERE id = :id'''),
params)
finally:
datastore_connection.close()
datastore_engine.dispose()

0 comments on commit 9635971

Please sign in to comment.