Beispiel #1
0
    def downgrade(self, revision, **kwargs):
        def downgrade(rev, context):
            # noinspection PyProtectedMember
            return self.scr._downgrade_revs(destination=revision,
                                            current_rev=rev)

        downgrade_bound_ctx = self._new_context(opts={'fn': downgrade})
        with Operations.context(downgrade_bound_ctx):
            with downgrade_bound_ctx.begin_transaction():
                downgrade_bound_ctx.run_migrations(**kwargs)
Beispiel #2
0
    def upgrade(self, revision='head', **kwargs):
        def upgrade(rev, context):
            # noinspection PyProtectedMember
            return self.scr._upgrade_revs(destination=revision,
                                          current_rev=rev)

        # early binding of the upgrade function (i.e., in self.ctx) is not possible because it is
        # bound to the target revision.
        upgrade_bound_ctx = self._new_context(opts={'fn': upgrade})
        # Configure alembic.op to use our upgrade context
        with Operations.context(upgrade_bound_ctx):
            with upgrade_bound_ctx.begin_transaction():
                upgrade_bound_ctx.run_migrations(**kwargs)
Beispiel #3
0
def upgrade():
    """Do database upgrade"""
    mc, lines = current_migration()
    op = Operations(mc)
    if not lines:
        print("Already up-to-date.")
    else:
        print("Start Migration")
        print('-' * 79)
        with mc.begin_transaction():
            for line in lines:
                print(line)
                exec(line, {"sa": sa, "op": op})
        print('-' * 79)
        print("OK")