Beispiel #1
0
def run_backwards(app, migrations, ignore=[], fake=False, db_dry_run=False, silent=False):
    """
    Runs the specified migrations backwards, in order, skipping those
    migrations in 'ignore'.
    """
    for migration in migrations:
        if migration not in ignore:
            app_name = get_app_name(app)
            if not silent:
                print " < %s: %s" % (app_name, migration)
            klass = get_migration(app, migration)
            if fake:
                if not silent:
                    print "   (faked)"
            else:
                if db_dry_run:
                    db.dry_run = True
                
                db.start_transaction()
                try:
                    klass().backwards()
                    db.execute_deferred_sql()
                except:
                    db.rollback_transaction()
                    raise
                else:
                    db.commit_transaction()

            if not db_dry_run:
                # Record us as having not done this
                record = MigrationHistory.for_migration(app_name, migration)
                record.delete()
Beispiel #2
0
def run_forwards(app, migrations, fake=False, db_dry_run=False, silent=False):
    """
    Runs the specified migrations forwards, in order.
    """
    for migration in migrations:
        app_name = get_app_name(app)
        if not silent:
            print " > %s: %s" % (app_name, migration)
        klass = get_migration(app, migration)

        if fake:
            if not silent:
                print "   (faked)"
        else:
            if db_dry_run:
                db.dry_run = True
                
            db.start_transaction()
            try:
                klass().forwards()
                db.execute_deferred_sql()
            except:
                db.rollback_transaction()
                raise
            else:
                db.commit_transaction()

        if not db_dry_run:
            # Record us as having done this
            record = MigrationHistory.for_migration(app_name, migration)
            record.applied = datetime.datetime.utcnow()
            record.save()
Beispiel #3
0
def migrate():
    histories = MigrationHistory.query().order(-MigrationHistory.performed_at).fetch(1)
    old_version = 0
    if len(histories) != 0:
        old_version = histories[0].version

    performed_migrations = []
    funcs = [(int(name[8:]), name, f) for name, f in inspect.getmembers(sys.modules[__name__]) if name.startswith('version_')]
    funcs.sort(key=lambda x: x[0])
    for i, name, f in funcs:
        if i <= old_version:
            continue
        f()

        history = MigrationHistory()
        history.version = i
        history.performed_at = datetime.now()
        history.put()

        performed_migrations.append(i)

    return performed_migrations
 def record(app_name, migration):
     # Record us as having not done this
     record = MigrationHistory.for_migration(app_name, migration)
     record.delete()
 def record(app_name, migration):
     # Record us as having done this
     record = MigrationHistory.for_migration(app_name, migration)
     record.applied = datetime.datetime.utcnow()
     record.save()
Beispiel #6
0
 def record(app_name, migration):
     # Record us as having not done this
     record = MigrationHistory.for_migration(app_name, migration)
     record.delete()
Beispiel #7
0
 def record(app_name, migration):
     # Record us as having done this
     record = MigrationHistory.for_migration(app_name, migration)
     record.applied = datetime.datetime.utcnow()
     record.save()