zine-main / zine / upgrades / versions / __init__.py

"""
    zine.upgrades.versions
    ~~~~~~~~~~~~~~~~~~~~~~

    This package contains the necessary upgrade/downgrade scripts to maintain
    the database schema changes.

    This __init__ contains often used helpers for the individual upgrade
    scripts.  Do not import it outside of upgrade scripts as it replaces
    some SQLAlchemy APIs with migrate's.

    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
"""
from sqlalchemy.exceptions import InternalError
from sqlalchemy.orm import scoped_session, create_session, clear_mappers
from sqlalchemy.sql import text, and_, or_

import migrate
from migrate import *
from migrate import changeset, versioning

from zine.database import db


for mod in versioning, changeset:
    for key, value in mod.__dict__.iteritems():
        # Override SQLA stuff with migrate's stuff
        if key in dir(mod):
            setattr(db, key, value)
del key, mod, value

db.and_ = and_
db.or_ = or_

def drop_table(table, migrate_engine):
    if migrate_engine.url.drivername == 'postgres':
        # PSQL prefers/requires a cascade at the end
        migrate_engine.execute(text("DROP TABLE %s CASCADE" % table.name))
    else:
        table.drop(migrate_engine)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.