Commits

Anonymous committed 0315f87

Kinda fixed eric the fish for new migrations. Kinda not because i have no
idea why this works. db.query_property is session bound yet it sortof
works if db.basic_mapper (orm.mapper) is used.

  • Participants
  • Parent commits 5f51725

Comments (0)

Files changed (5)

File external-plugins/eric_the_fish/versions/001_Move_fortunes_to_the_database.py

     session = scoped_session(lambda: create_session(migrate_engine,
                                                     autoflush=True,
                                                     autocommit=False))
-    map_tables(session.mapper)
+    map_tables(db.basic_mapper)
     metadata.bind = migrate_engine
     if not fortunes.exists():
         fortunes.create(migrate_engine)
     session = scoped_session(lambda: create_session(migrate_engine,
                                                     autoflush=True,
                                                     autocommit=False))
-    map_tables(session.mapper)
+    map_tables(db.basic_mapper)
     yield '<p>Removing the fortunes from the database</p>\n'
 
     metadata.bind = migrate_engine

File zine/database.py

         cls.query = session.query_property(Query)
     old_init = getattr(cls, '__init__', None)
     def register_init(self, *args, **kwargs):
-        old_init(self, *args, **kwargs)
+        if old_init is not None:
+            old_init(self, *args, **kwargs)
         session.add(self)
     cls.__init__ = register_init
     return orm.mapper(cls, *args, **kwargs)
 del key, mod, value
 
 #: forward some session methods to the module as well
-for name in 'delete', 'flush', 'execute', 'begin', 'mapper', \
-            'commit', 'rollback', 'refresh', 'expire', \
-            'query_property':
+for name in 'delete', 'flush', 'execute', 'begin',  'commit', 'rollback', \
+            'refresh', 'expire', 'query_property':
     setattr(db, name, getattr(session, name))
 
 #: and finally hook our own implementations of various objects in
 db.session = session
 db.ZEMLParserData = ZEMLParserData
 db.mapper = mapper
+db.basic_mapper = orm.mapper
 db.association_proxy = association_proxy
 db.attribute_loaded = attribute_loaded
 db.AttributeExtension = AttributeExtension

File zine/templates/admin/perform_upgrade.html

         <strong>Do not hit cancel!</strong>{% endtrans %}</p>
       {%- for event in live_log %}{{ event }}{%- endfor %}
       <p class="finish">{% trans %}Database upgrade finished.{% endtrans %}</p>
-      <br/>
+      <br>
       <div class="message">{% trans %}Zine maintenance mode has been switched on.
           Please <a href="{{ blog_url }}">check your blog</a> to see if the
           blog works fine with the upgraded database.

File zine/upgrades/__init__.py

 from migrate.versioning.util import construct_engine
 from migrate.versioning.exceptions import KnownError
 
+from werkzeug.utils import escape
+
 from zine import __version__ as VERSION, setup
 # imported for side-effects
 from zine.upgrades import customisation
                     yield message
             except Exception, msg:
                 yield '<p>error upgrading %s: ' % sv.repository_id
-                yield str(msg)
+                yield escape(str(msg).decode('utf-8', 'ignore'))
                 yield '</p>\n'
 
     def cmd_downgrade(self, repo_id, version=None, **opts):
                 yield message
         except Exception, msg:
             yield '<p>error downgrading %s: ' % repo_id
-            yield str(msg)
+            yield escape(str(msg).decode('utf-8', 'ignore'))
             yield '</p>\n'
 
     def _migrate(self, repository, version, upgrade, **opts):

File zine/upgrades/customisation.py

 from os import listdir
 from os.path import dirname, join
 
-from migrate.versioning import api, base, exceptions
+from migrate.versioning import api, exceptions
+from migrate.versioning.config import operations as migrate_ops
 from migrate.versioning.repository import Repository as MigrateRepository
 from migrate.versioning.script.py import PythonScript as MigratePythonScript
 from migrate.versioning.schema import (ControlledSchema as
             op = 'downgrade'
         else:
             raise exceptions.ScriptError("%d is not a valid step" % step)
-        funcname = base.operations[op]
+        funcname = migrate_ops[op]
         script_func = self._func(funcname)
         try:
             #script_func(engine)