Exemple #1
0
def run_migrations_online():
    if DBSESSION.bind is None:
        raise ValueError(
            "\nYou must do Autonomie migrations using the 'autonomie-migrate' script"
            "\nand not through 'alembic' directly.")

    transaction.begin()
    connection = DBSESSION.connection()

    context.configure(
        connection=connection,
        target_metadata=DBBASE.metadata,
        compare_type=True,
    )

    try:
        context.run_migrations()
    except:
        traceback.print_exc()
        transaction.abort()
    else:
        transaction.commit()
    finally:
        #connection.close()
        pass
Exemple #2
0
def force_rename_table(old, new):
    from autonomie_base.models.base import DBSESSION
    conn = DBSESSION.connection()
    if table_exists(old):
        if table_exists(new):
            op.drop_table(new)
        op.rename_table(old, new)
Exemple #3
0
def force_rename_table(old, new):
    from autonomie_base.models.base import DBSESSION
    conn = DBSESSION.connection()
    if table_exists(old):
        if table_exists(new):
            op.drop_table(new)
        op.rename_table(old, new)
Exemple #4
0
def run_migrations_online():
    if DBSESSION.bind is None:
        raise ValueError(
"\nYou must do Autonomie migrations using the 'autonomie-migrate' script"
"\nand not through 'alembic' directly."
            )

    transaction.begin()
    connection = DBSESSION.connection()

    context.configure(
        connection=connection,
        target_metadata=DBBASE.metadata,
        compare_type=True,
    )

    try:
        context.run_migrations()
    except Exception as migration_e:
        traceback.print_exc()
        try:
            transaction.abort()
        except Exception as rollback_e:
            traceback.print_exc()
            raise RollbackError(rollback_e)
        else:
            raise MigrationError(migration_e)
    else:
        transaction.commit()
    finally:
        #connection.close()
        pass
Exemple #5
0
def column_exists(tbl, column_name):
    from autonomie_base.models.base import DBSESSION
    conn = DBSESSION.connection()
    ret = False
    try:
        conn.execute("select %s from %s" % (column_name, tbl))
        ret = True
    except:
        pass
    return ret
Exemple #6
0
def table_exists(tbl):
    from autonomie_base.models.base import DBSESSION
    conn = DBSESSION.connection()
    ret = False
    try:
        conn.execute("select * from `%s`" % tbl)
        ret = True
    except:
        pass
    return ret
Exemple #7
0
def column_exists(tbl, column_name):
    from autonomie_base.models.base import DBSESSION
    conn = DBSESSION.connection()
    ret = False
    try:
        conn.execute("select %s from %s" % (column_name, tbl))
        ret = True
    except:
        pass
    return ret
Exemple #8
0
def table_exists(tbl):
    from autonomie_base.models.base import DBSESSION
    conn = DBSESSION.connection()
    ret = False
    try:
        conn.execute("select * from `%s`" % tbl)
        ret = True
    except:
        pass
    return ret