Permalink
Browse files

Add support for sqlalchemy-migrate 0.5.4

ticket:153
  • Loading branch information...
1 parent 18ae2c2 commit d5df482b7c1042c6875c082ca2ada99ced7a1677 @ncjones ncjones committed Nov 15, 2011
View
@@ -24,7 +24,7 @@ libxslt >= 1.1.26
libxslt-python >= 1.1.26
sqlite >= 3.2.0 (sqlite is preferred to mysql as database, MySQL-python has been reported to be installed if so)
sqlalchemy >= 0.6.4
-sqlalchemy-migrate >= 0.6.0
+sqlalchemy-migrate >= 0.5.4
zenity >= 2.30
- Only needed if correspondent plugin or extension is enabled:
@@ -22,8 +22,9 @@ class UpgradeContext(object):
Provides access to the application base dir."""
- def __init__(self, conf_dir):
+ def __init__(self, conf_dir, db_url):
self.conf_dir = conf_dir
+ self.db_url = db_url
# sqlalchemy-migrate does not provide any means to inject the context object in
# to upgrade scripts so instead we provide access via this global which must be
@@ -28,7 +28,7 @@ def initialize_data(ddbb, conf_dir):
"""Initializes the installation's data."""
db_url = ddbb.get_connection_url()
migratable_db = MigratableDb(MIGRATE_REPOSITORY_PATH, db_url)
- InstalledData(migratable_db, ddbb, LegacyVersionProvider(conf_dir), UpgradeContext(conf_dir)).update_to_current()
+ InstalledData(migratable_db, ddbb, LegacyVersionProvider(conf_dir), UpgradeContext(conf_dir, db_url)).update_to_current()
class InstalledData(object):
@@ -17,6 +17,7 @@
#Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from migrate.versioning.api import db_version, upgrade, version, version_control
+from sqlalchemy.exc import NoSuchTableError
# sqlalchemy-migrate 0.6.1 broke backwards compatibility
# so we need to try importing exceptions from one of two packages
try:
@@ -59,6 +60,10 @@ def is_versioned(self):
self.get_version()
except DatabaseNotControlledError:
return False
+ except NoSuchTableError:
+ # prior to 0.6.0, sqlalchemy-migrate did not handle querying
+ # against unversioned databases.
+ return False
return True
def get_version(self):
@@ -1,9 +1,14 @@
+from pytrainer.upgrade.context import UPGRADE_CONTEXT
from sqlalchemy.sql.expression import text
import logging
+import sqlalchemy
# record duration added in version 1.8.0
-def upgrade(migrate_engine):
+def upgrade(migrate_engine=None):
+ if migrate_engine is None:
+ # sqlalchemy-migrate 0.5.4 does not provide migrate engine to upgrade scripts
+ migrate_engine = sqlalchemy.create_engine(UPGRADE_CONTEXT.db_url)
logging.info("Populating records.duration column")
records = migrate_engine.execute("select id_record, time from records where duration is null")
for record in records:
@@ -23,5 +28,5 @@ def upgrade(migrate_engine):
import migrate.versioning.exceptions as ex1
import migrate.changeset.exceptions as ex2
ex1.MigrateDeprecationWarning = ex2.MigrateDeprecationWarning
-except ImportError:
+except:
pass
@@ -1,11 +1,15 @@
-from pytrainer.upgrade.context import UPGRADE_CONTEXT
from pytrainer.lib import gpx
+from pytrainer.upgrade.context import UPGRADE_CONTEXT
from sqlalchemy.sql.expression import text
import logging
import os.path
+import sqlalchemy
# lap info added in version 1.9.0
-def upgrade(migrate_engine):
+def upgrade(migrate_engine=None):
+ if migrate_engine is None:
+ # sqlalchemy-migrate 0.5.4 does not provide migrate engine to upgrade scripts
+ migrate_engine = sqlalchemy.create_engine(UPGRADE_CONTEXT.db_url)
logging.info("Populating laps details columns")
resultset = migrate_engine.execute(text("select distinct record from laps where intensity is null"))
record_ids = []
@@ -50,5 +54,5 @@ def populate_lap_from_gpx(migrate_engine, lap_id, gpx_lap):
import migrate.versioning.exceptions as ex1
import migrate.changeset.exceptions as ex2
ex1.MigrateDeprecationWarning = ex2.MigrateDeprecationWarning
-except ImportError:
+except:
pass
@@ -1,7 +1,7 @@
from lxml import etree
from pytrainer.upgrade.context import UPGRADE_CONTEXT
-def upgrade(migrate_engine):
+def upgrade(migrate_engine=None):
config_file = UPGRADE_CONTEXT.conf_dir + "/conf.xml"
parser = etree.XMLParser(encoding="UTF8", recover=True)
xml_tree = etree.parse(config_file, parser=parser)
@@ -1,4 +1,9 @@
+from pytrainer.upgrade.context import UPGRADE_CONTEXT
import pytrainer.upgrade.versions.version014 as version14
+import sqlalchemy
-def upgrade(migrate_engine):
+def upgrade(migrate_engine=None):
+ if migrate_engine is None:
+ # sqlalchemy-migrate 0.5.4 does not provide migrate engine to upgrade scripts
+ migrate_engine = sqlalchemy.create_engine(UPGRADE_CONTEXT.db_url)
version14.upgrade(migrate_engine)

0 comments on commit d5df482

Please sign in to comment.