예제 #1
0
def downgrade_heads(revisions):
    """
    Run migrations to available HEAD
    """
    from faq_migrations.source.alembic_wrapper import AlembicMigrations

    am = AlembicMigrations()
    am.downgrade(revisions.split(','))
예제 #2
0
def downgrade(amount):
    """
    Run migrations to available HEAD
    """
    from faq_migrations.source.alembic_wrapper import AlembicMigrations

    am = AlembicMigrations()
    am.downgrade(amount)
예제 #3
0
def last_revision():
    """
    Show last created migration from files. This may be not yet applied
    migration
    """
    from faq_migrations.source.alembic_wrapper import AlembicMigrations
    print(AlembicMigrations().__get_last_revision__())
예제 #4
0
def create(name):
    """
    Create new migration with fingerprint of current git branch name
    :param name: migration name
    """
    from faq_migrations.source.alembic_wrapper import AlembicMigrations
    AlembicMigrations().create(name)
예제 #5
0
파일: utils.py 프로젝트: symstu/git-alembic
    def __init__(self, db_name):
        self.db_name = db_name

        self.db = Database(db_name=db_name)
        self.db.create()

        self.alembic = AlembicMigrations(Database(db_name=db_name).url)
        self.repo = git.Repo('')
        self.set_active_branch()
        self.initial_revision = self.repo.index.version
        print(f'current {db_name} revision is {self.initial_revision}')
예제 #6
0
def heads(abnormal_termination):
    """
    Show current heads
    """
    from faq_migrations.source.alembic_wrapper import AlembicMigrations

    al = AlembicMigrations()
    migration_heads = list(al.heads)

    print('------------------------------------------')
    for head in migration_heads:
        print(head.longdoc)
        print('Branch: {}'.format(al.branch_name(head)))
        print('------------------------------------------')

    # Exit with status code 1 if exists more then one migration.
    # We need it for CI
    if abnormal_termination and (len(migration_heads) > 1):
        raise SystemExit(
            f'Current migrations have {len(migration_heads)} heads. Fix it!'
        )
예제 #7
0
def migrate():
    """
    Run migrations to available HEAD
    """
    from faq_migrations.source.alembic_wrapper import AlembicMigrations

    am = AlembicMigrations()

    if am.migrate() is False:
        print('\nYou must merge branches first\n')
        am.merge()
        am.migrate()
예제 #8
0
def history(limit=20, upper=True, verbose=False):
    """
    Show migration history
    :param limit: limit of output migrations
    :param upper: if True will be show new migrations (like DESC by datetime)
    :param verbose: show log entry of migration
    """
    from faq_migrations.source.alembic_wrapper import AlembicMigrations

    am = AlembicMigrations()
    revisions = am.history(limit, upper)

    for revision in revisions:

        if verbose:
            script = am.get_revision(revision.revision)
            print('{}({}): {}'.format(
                revision, am.branch_name(revision), script.log_entry
            ))
            continue

        print('{} ({})'.format(
            revision, am.branch_name(revision))
        )
예제 #9
0
def init():
    """
    Creates new directory for migrations, generates alembic.ini and mako-files
    """
    from faq_migrations.source.alembic_wrapper import AlembicMigrations
    AlembicMigrations().init()
예제 #10
0
def merge():
    """
    Start merging heads if there are more then one
    """
    from faq_migrations.source.alembic_wrapper import AlembicMigrations
    AlembicMigrations().merge()
예제 #11
0
def current():
    """
    Show current migration revision from database
    """
    from faq_migrations.source.alembic_wrapper import AlembicMigrations
    print(AlembicMigrations().current(True))
예제 #12
0
def upgrade_migrations():
    """
    Show not yet applied migrations
    """
    from faq_migrations.source.alembic_wrapper import AlembicMigrations
    print(AlembicMigrations().upgrade_revisions(AlembicMigrations().current()))