Ejemplo n.º 1
0
def upgrade(migrate_engine):
    """
    Upgrade operations go here.
    Don't create your own engine; bind migrate_engine to your metadata.
    """
    meta.bind = migrate_engine

    table = meta.tables['USERS']
    drop_column(COLUMN_N1, table)
    table = meta.tables['BURST_CONFIGURATIONS']
    drop_column(COLUMN_N2, table)
    table = meta.tables['OPERATIONS']
    alter_column(COLUMN_N3_OLD, table=table, name=COLUMN_N3_NEW.name)

    try:
        meta.bind = migrate_engine
        session = SA_SESSIONMAKER()
        session.execute(text("""UPDATE "DATA_TYPES" SET module='tvb.datatypes.region_mapping' WHERE "type" = 'RegionMapping' """))
        session.execute(text("""UPDATE "DATA_TYPES" SET module='tvb.datatypes.local_connectivity' WHERE "type" = 'LocalConnectivity' """))
        session.execute(text("""UPDATE "DATA_TYPES" SET module='tvb.datatypes.cortex' WHERE "type" = 'Cortex' """))
        session.commit()
        session.close()

    except Exception:
        LOGGER.exception("Cold not update datatypes")
        raise
Ejemplo n.º 2
0
def downgrade(migrate_engine):
    """Operations to reverse the above upgrade go here."""
    meta.bind = migrate_engine

    table = meta.tables['DATA_TYPES_GROUPS']
    drop_column(COL_RANGES_1, table)
    drop_column(COL_RANGES_2, table)
Ejemplo n.º 3
0
def upgrade(migrate_engine):
    """
    Upgrade operations go here.
    Don't create your own engine; bind migrate_engine to your metadata.
    """
    meta.bind = migrate_engine

    table = meta.tables['USERS']
    drop_column(COLUMN_N1, table)
    table = meta.tables['BURST_CONFIGURATIONS']
    drop_column(COLUMN_N2, table)
    table = meta.tables['OPERATIONS']
    alter_column(COLUMN_N3_OLD, table=table, name=COLUMN_N3_NEW.name)

    try:
        meta.bind = migrate_engine
        session = SA_SESSIONMAKER()
        session.execute(text("""UPDATE "DATA_TYPES" SET module='tvb.datatypes.region_mapping' WHERE "type" = 'RegionMapping' """))
        session.execute(text("""UPDATE "DATA_TYPES" SET module='tvb.datatypes.local_connectivity' WHERE "type" = 'LocalConnectivity' """))
        session.execute(text("""UPDATE "DATA_TYPES" SET module='tvb.datatypes.cortex' WHERE "type" = 'Cortex' """))
        session.commit()
        session.close()

    except Exception:
        LOGGER.exception("Cold not update datatypes")
        raise
Ejemplo n.º 4
0
def downgrade(migrate_engine):
    """
    Operations to reverse the above upgrade go here.
    """
    try:
        meta.bind = migrate_engine
        table = meta.tables['MAPPED_CONNECTIVITY_DATA']
        drop_column(COL_NR_OF_CONNECTIONS, table)
    except Exception:
        LOGGER.warning("Cold not remove column as required by the downgrade")
        raise
Ejemplo n.º 5
0
def downgrade(migrate_engine):
    """
    Operations to reverse the above upgrade go here.
    """
    try:
        meta.bind = migrate_engine
        table = meta.tables['MAPPED_CONNECTIVITY_DATA']
        drop_column(COL_NR_OF_CONNECTIONS, table)
    except Exception:
        LOGGER.warning("Cold not remove column as required by the downgrade")
        raise
Ejemplo n.º 6
0
def downgrade(migrate_engine):
    """
    Operations to reverse the above upgrade go here.
    """
    try:
        meta.bind = migrate_engine
        table = meta.tables['PROJECTS']
        drop_column(COL_VERSION, table)

    except Exception:
        logger = get_logger(__name__)
        logger.warning("Cold not remove column as required by the downgrade")
        raise
Ejemplo n.º 7
0
def downgrade(migrate_engine):
    """
    Operations to reverse the above upgrade go here.
    """
    try:
        meta.bind = migrate_engine
        table = meta.tables['MAPPED_CORRELATION_COEFFICIENTS_DATA']
        drop_column(COL_LABELS, table)

    except Exception:
        ## This update is not critical. We can run even in case of error at update
        logger = get_logger(__name__)
        logger.warning("We do not update table MAPPED_CORRELATION_COEFFICIENTS_DATA, because it is not yet created")
Ejemplo n.º 8
0
def downgrade(migrate_engine):
    """
    Operations to reverse the above upgrade go here.
    """
    try:
        meta.bind = migrate_engine
        table = meta.tables['MAPPED_CORRELATION_COEFFICIENTS_DATA']
        drop_column(COL_LABELS, table)

    except Exception:
        ## This update is not critical. We can run even in case of error at update
        logger = get_logger(__name__)
        logger.warning("We do not update table MAPPED_CORRELATION_COEFFICIENTS_DATA, because it is not yet created")
Ejemplo n.º 9
0
def downgrade(migrate_engine):
    """
    Operations to reverse the above upgrade go here.
    """
    try:
        meta.bind = migrate_engine
        table = meta.tables['PROJECTS']
        drop_column(COL_VERSION, table)

    except Exception:
        logger = get_logger(__name__)
        logger.warning("Cold not remove column as required by the downgrade")
        raise
Ejemplo n.º 10
0
def downgrade(migrate_engine):
    """
    Operations to reverse the above upgrade go here.
    """
    meta.bind = migrate_engine
    table1 = meta.tables['MAPPED_TIME_SERIES_DATA']
    table2 = meta.tables['MAPPED_TIME_SERIES_REGION_DATA']
    table3 = meta.tables['MAPPED_SENSORS_DATA']

    drop_column(COL_REG1, table1)
    drop_column(COL_REG2, table1)
    drop_column(COL_REG3, table2)
    drop_column(COL_REG4, table2)
    drop_column(COL_SENSORS, table3)
Ejemplo n.º 11
0
def downgrade(migrate_engine):
    """Operations to reverse the above upgrade go here."""
    meta.bind = migrate_engine
    table1 = meta.tables['MAPPED_CONNECTIVITY_DATA']

    create_column(COL_OLD, table1)

    session = SA_SESSIONMAKER()
    session.execute(text("UPDATE \"MAPPED_CONNECTIVITY_DATA\" set _unidirectional=_undirected"))
    session.commit()
    session.close()

    drop_column(COL_NEW, table1)
    create_column(COL_NOSE_CORRECTION, table1)
Ejemplo n.º 12
0
def downgrade(migrate_engine):
    """
    Operations to reverse the above upgrade go here.
    """
    meta.bind = migrate_engine
    table1 = meta.tables['MAPPED_TIME_SERIES_DATA']
    table2 = meta.tables['MAPPED_TIME_SERIES_REGION_DATA']
    table3 = meta.tables['MAPPED_SENSORS_DATA']

    drop_column(COL_REG1, table1)
    drop_column(COL_REG2, table1)
    drop_column(COL_REG3, table2)
    drop_column(COL_REG4, table2)
    drop_column(COL_SENSORS, table3)
Ejemplo n.º 13
0
def upgrade(migrate_engine):
    """
    Upgrade operations go here.
    Don't create your own engine; bind migrate_engine to your metadata.
    """
    meta.bind = migrate_engine
    table1 = meta.tables['MAPPED_CONNECTIVITY_DATA']

    create_column(COL_NEW, table1)

    session = SA_SESSIONMAKER()
    session.execute(text("UPDATE \"MAPPED_CONNECTIVITY_DATA\" set _undirected=_unidirectional"))
    session.commit()
    session.close()

    drop_column(COL_OLD, table1)
    drop_column(COL_NOSE_CORRECTION, table1)
Ejemplo n.º 14
0
def downgrade(migrate_engine):
    """Operations to reverse the above upgrade go here."""
    meta.bind = migrate_engine

    table = meta.tables['DATA_TYPES_GROUPS']
    drop_column(COL_RANGES_1, table)
    drop_column(COL_RANGES_2, table)
    
    session = SA_SESSIONMAKER()
    
    session.execute(text("""UPDATE "OPERATIONS"
                               SET status = 
                                CASE
                                    WHEN status = '4-FINISHED' THEN 'FINISHED'
                                    WHEN status = '3-STARTED' THEN 'STARTED'
                                    WHEN status = '2-CANCELED' THEN 'CANCELED'
                                    ELSE 'ERROR'
                                END
                             WHERE status IN ('4-FINISHED', '2-CANCELED', '3-STARTED', '1-ERROR');"""))
Ejemplo n.º 15
0
def downgrade(migrate_engine):
    """Operations to reverse the above upgrade go here."""
    meta.bind = migrate_engine

    table1 = meta.tables['MAPPED_TIME_SERIES_DATA']
    drop_column(COL_1, table1)
    drop_column(COL_2, table1)
    drop_column(COL_3, table1)
    drop_column(COL_4, table1)

    session = SA_SESSIONMAKER()
    try:
        session.execute(
            text("ALTER TABLE \"MAPPED_TIME_SERIES_DATA\" "
                 "RENAME COLUMN _labels_ordering to _dim_labels"))
        session.execute(
            text("ALTER TABLE \"MAPPED_CROSS_CORRELATION_DATA\" "
                 "RENAME COLUMN _labels_ordering to _dim_labels"))

    except sqlalchemy.exc.OperationalError:
        session.execute(
            text("ALTER TABLE \"MAPPED_TIME_SERIES_DATA\" "
                 "ADD COLUMN _dim_labels VARYING CHARACTER(255)"))
        session.execute(
            text("ALTER TABLE \"MAPPED_CROSS_CORRELATION_DATA\" "
                 "ADD COLUMN _dim_labels VARYING CHARACTER(255)"))
    session.commit()
    session.close()

    table2 = meta.tables['MAPPED_CONNECTIVITY_DATA']
    drop_column(COL_7, table2)

    for mapping in TABLE_RENAMES:
        session = SA_SESSIONMAKER()
        session.execute(
            text("ALTER TABLE \"%s\" RENAME TO \"%s\"" %
                 (mapping[1], mapping[0])))
        session.commit()
        session.close()
Ejemplo n.º 16
0
def downgrade(migrate_engine):
    """Operations to reverse the above upgrade go here."""
    meta.bind = migrate_engine

    table1 = meta.tables['BURST_CONFIGURATIONS']
    drop_column(COLUMN_BURST, table1)

    table2 = meta.tables['ALGORITHM_CATEGORIES']
    drop_column(COLUMN_CATEGORY, table2)

    table3 = meta.tables['ALGORITHM_GROUPS']
    drop_column(COLUMN_GROUP, table3)

    table4 = meta.tables['MAPPED_SURFACE_DATA']
    drop_column(COLUMN_VALID_SURFACE, table4)
Ejemplo n.º 17
0
def downgrade(migrate_engine):
    """Operations to reverse the above upgrade go here."""
    meta.bind = migrate_engine

    table1 = meta.tables['BURST_CONFIGURATIONS']
    drop_column(COLUMN_BURST, table1)

    table2 = meta.tables['ALGORITHM_CATEGORIES']
    drop_column(COLUMN_CATEGORY, table2)

    table3 = meta.tables['ALGORITHM_GROUPS']
    drop_column(COLUMN_GROUP, table3)

    table4 = meta.tables['MAPPED_SURFACE_DATA']
    drop_column(COLUMN_VALID_SURFACE, table4)
def downgrade(migrate_engine):
    """Operations to reverse the above upgrade go here."""
    meta.bind = migrate_engine

    table1 = meta.tables['MAPPED_TIME_SERIES_DATA']
    drop_column(COL_1, table1)
    drop_column(COL_2, table1)
    drop_column(COL_3, table1)
    drop_column(COL_4, table1)

    session = SA_SESSIONMAKER()
    try:
        session.execute(text("ALTER TABLE \"MAPPED_TIME_SERIES_DATA\" "
                             "RENAME COLUMN _labels_ordering to _dim_labels"))
        session.execute(text("ALTER TABLE \"MAPPED_CROSS_CORRELATION_DATA\" "
                             "RENAME COLUMN _labels_ordering to _dim_labels"))

    except sqlalchemy.exc.OperationalError:
        session.execute(text("ALTER TABLE \"MAPPED_TIME_SERIES_DATA\" "
                             "ADD COLUMN _dim_labels VARYING CHARACTER(255)"))
        session.execute(text("ALTER TABLE \"MAPPED_CROSS_CORRELATION_DATA\" "
                             "ADD COLUMN _dim_labels VARYING CHARACTER(255)"))
    session.commit()
    session.close()

    table2 = meta.tables['MAPPED_CONNECTIVITY_DATA']
    drop_column(COL_7, table2)

    for mapping in TABLE_RENAMES:
        session = SA_SESSIONMAKER()
        session.execute(text("ALTER TABLE \"%s\" RENAME TO \"%s\"" % (mapping[1], mapping[0])))
        session.commit()
        session.close()
        
        
        
Ejemplo n.º 19
0
def downgrade(migrate_engine):
    """Operations to reverse the above upgrade go here."""
    meta.bind = migrate_engine

    table = meta.tables['MAPPED_SURFACE_DATA']
    drop_column(COLUMN_N1, table)
    drop_column(COLUMN_N2, table)
    drop_column(COLUMN_N3, table)

    session = SA_SESSIONMAKER()
    session.execute(text("""UPDATE "OPERATIONS" SET status='4-FINISHED' WHERE status = '5-FINISHED' """))
    session.execute(text("""UPDATE "OPERATIONS" SET status='3-STARTED' WHERE status = '4-PENDING' """))
    session.commit()
    session.close()
Ejemplo n.º 20
0
def downgrade(migrate_engine):
    """
    Operations to reverse the above upgrade go here.
    """
    try:
        meta.bind = migrate_engine
        table1 = meta.tables['MAPPED_SURFACE_DATA']

        drop_column(COL_1, table1)
        drop_column(COL_2, table1)
        drop_column(COL_3, table1)

    except Exception:
        logger = get_logger(__name__)
        logger.warning("Cold not remove column as required by the downgrade")
        raise
Ejemplo n.º 21
0
def downgrade(migrate_engine):
    """
    Operations to reverse the above upgrade go here.
    """
    try:
        meta.bind = migrate_engine
        table1 = meta.tables['MAPPED_SURFACE_DATA']

        drop_column(COL_1, table1)
        drop_column(COL_2, table1)
        drop_column(COL_3, table1)

    except Exception:
        logger = get_logger(__name__)
        logger.warning("Cold not remove column as required by the downgrade")
        raise
Ejemplo n.º 22
0
def downgrade(migrate_engine):
    """Operations to reverse the above upgrade go here."""
    meta.bind = migrate_engine

    table = meta.tables['MAPPED_SURFACE_DATA']
    drop_column(COLUMN_N1, table)
    drop_column(COLUMN_N2, table)
    drop_column(COLUMN_N3, table)

    session = SA_SESSIONMAKER()
    session.execute(
        text(
            """UPDATE "OPERATIONS" SET status='4-FINISHED' WHERE status = '5-FINISHED' """
        ))
    session.execute(
        text(
            """UPDATE "OPERATIONS" SET status='3-STARTED' WHERE status = '4-PENDING' """
        ))
    session.commit()
    session.close()
Ejemplo n.º 23
0
def upgrade(migrate_engine):
    """
    Alter existing table ALGORITHMS, by moving columns from the old ALGORITHM_GROUPS table.
    """
    meta.bind = migrate_engine
    table_algo = meta.tables["ALGORITHMS"]
    for col in ADD_COLUMNS:
        create_column(col, table_algo)

    session = SA_SESSIONMAKER()
    try:
        session.execute(text("ALTER TABLE \"MAPPED_SIMULATION_STATE\" "
                             "ADD COLUMN _current_state VARYING CHARACTER(255)"))
        session.commit()
    except Exception:
        session.close()
        session = SA_SESSIONMAKER()
        session.execute(text("ALTER TABLE \"MAPPED_SIMULATION_STATE\" "
                             "ADD COLUMN _current_state character varying;"))
        session.commit()
    finally:
        session.close()

    session = SA_SESSIONMAKER()
    try:
        session.execute(text(
            """UPDATE "ALGORITHMS" SET
            module = (select G.module FROM "ALGORITHM_GROUPS" G WHERE "ALGORITHMS".fk_algo_group=G.id),
            classname = (select G.classname FROM "ALGORITHM_GROUPS" G WHERE "ALGORITHMS".fk_algo_group=G.id),
            displayname = (select G.displayname FROM "ALGORITHM_GROUPS" G WHERE "ALGORITHMS".fk_algo_group=G.id),
            fk_category = (select G.fk_category FROM "ALGORITHM_GROUPS" G WHERE "ALGORITHMS".fk_algo_group=G.id);"""))
        session.commit()

        # Delete old columns, no longer needed
        for col in DEL_COLUMNS:
            drop_column(col, table_algo)

        # Create constraint only after rows are being populated
        table_algo = meta.tables["ALGORITHMS"]
        fk_constraint = ForeignKeyConstraint(["fk_category"], ["ALGORITHM_CATEGORIES.id"],
                                             ondelete="CASCADE", table=table_algo)
        fk_constraint.create()

        # Drop old table
        session = SA_SESSIONMAKER()
        session.execute(text("""DROP TABLE "ALGORITHM_GROUPS";"""))
        session.commit()

    except Exception as excep:
        LOGGER.exception(excep)
    finally:
        session.close()

    session = SA_SESSIONMAKER()
    try:
        session.execute(text("""ALTER TABLE "MAPPED_CONNECTIVITY_ANNOTATIONS"
                                RENAME TO "MAPPED_CONNECTIVITY_ANNOTATIONS_DATA"; """))
        session.execute(text("""ALTER TABLE "MAPPED_DATATYPE_MEASURE" RENAME TO "MAPPED_DATATYPE_MEASURE_DATA"; """))
        session.execute(text("""ALTER TABLE "MAPPED_SIMULATION_STATE" RENAME TO "MAPPED_SIMULATION_STATE_DATA"; """))
        session.execute(text("""ALTER TABLE "MAPPED_VALUE_WRAPPER" RENAME TO "MAPPED_VALUE_WRAPPER_DATA"; """))
        session.execute(text("""ALTER TABLE "MAPPED_PROJECTION_DATA" RENAME TO "MAPPED_PROJECTION_MATRIX_DATA"; """))
        session.commit()
    except Exception as excep:
        LOGGER.exception(excep)
    finally:
        session.close()
Ejemplo n.º 24
0
    finally:
        session.close()

    session = SA_SESSIONMAKER()
    try:
        session.execute(text(
            """UPDATE "ALGORITHMS" SET
            module = (select G.module FROM "ALGORITHM_GROUPS" G WHERE "ALGORITHMS".fk_algo_group=G.id),
            classname = (select G.classname FROM "ALGORITHM_GROUPS" G WHERE "ALGORITHMS".fk_algo_group=G.id),
            displayname = (select G.displayname FROM "ALGORITHM_GROUPS" G WHERE "ALGORITHMS".fk_algo_group=G.id),
            fk_category = (select G.fk_category FROM "ALGORITHM_GROUPS" G WHERE "ALGORITHMS".fk_algo_group=G.id);"""))
        session.commit()

        # Delete old columns, no longer needed
        for col in DEL_COLUMNS:
            drop_column(col, table_algo)

        # Create constraint only after rows are being populated
        table_algo = meta.tables["ALGORITHMS"]
        fk_constraint = ForeignKeyConstraint(["fk_category"], ["ALGORITHM_CATEGORIES.id"],
                                             ondelete="CASCADE", table=table_algo)
        fk_constraint.create()

        # Drop old table
        session = SA_SESSIONMAKER()
        session.execute(text("""DROP TABLE "ALGORITHM_GROUPS";"""))
        session.commit()

    except Exception, excep:
        LOGGER.exception(excep)
    finally:
Ejemplo n.º 25
0
def upgrade(migrate_engine):
    """
    Alter existing table ALGORITHMS, by moving columns from the old ALGORITHM_GROUPS table.
    """
    meta.bind = migrate_engine
    table_algo = meta.tables["ALGORITHMS"]
    for col in ADD_COLUMNS:
        create_column(col, table_algo)

    session = SA_SESSIONMAKER()
    try:
        session.execute(
            text("ALTER TABLE \"MAPPED_SIMULATION_STATE\" "
                 "ADD COLUMN _current_state VARYING CHARACTER(255)"))
        session.commit()
    except Exception:
        session.close()
        session = SA_SESSIONMAKER()
        session.execute(
            text("ALTER TABLE \"MAPPED_SIMULATION_STATE\" "
                 "ADD COLUMN _current_state character varying;"))
        session.commit()
    finally:
        session.close()

    session = SA_SESSIONMAKER()
    try:
        session.execute(
            text("""UPDATE "ALGORITHMS" SET
            module = (select G.module FROM "ALGORITHM_GROUPS" G WHERE "ALGORITHMS".fk_algo_group=G.id),
            classname = (select G.classname FROM "ALGORITHM_GROUPS" G WHERE "ALGORITHMS".fk_algo_group=G.id),
            displayname = (select G.displayname FROM "ALGORITHM_GROUPS" G WHERE "ALGORITHMS".fk_algo_group=G.id),
            fk_category = (select G.fk_category FROM "ALGORITHM_GROUPS" G WHERE "ALGORITHMS".fk_algo_group=G.id);"""
                 ))
        session.commit()

        # Delete old columns, no longer needed
        for col in DEL_COLUMNS:
            drop_column(col, table_algo)

        # Create constraint only after rows are being populated
        table_algo = meta.tables["ALGORITHMS"]
        fk_constraint = ForeignKeyConstraint(["fk_category"],
                                             ["ALGORITHM_CATEGORIES.id"],
                                             ondelete="CASCADE",
                                             table=table_algo)
        fk_constraint.create()

        # Drop old table
        session = SA_SESSIONMAKER()
        session.execute(text("""DROP TABLE "ALGORITHM_GROUPS";"""))
        session.commit()

    except Exception as excep:
        LOGGER.exception(excep)
    finally:
        session.close()

    session = SA_SESSIONMAKER()
    try:
        session.execute(
            text("""ALTER TABLE "MAPPED_CONNECTIVITY_ANNOTATIONS"
                                RENAME TO "MAPPED_CONNECTIVITY_ANNOTATIONS_DATA"; """
                 ))
        session.execute(
            text(
                """ALTER TABLE "MAPPED_DATATYPE_MEASURE" RENAME TO "MAPPED_DATATYPE_MEASURE_DATA"; """
            ))
        session.execute(
            text(
                """ALTER TABLE "MAPPED_SIMULATION_STATE" RENAME TO "MAPPED_SIMULATION_STATE_DATA"; """
            ))
        session.execute(
            text(
                """ALTER TABLE "MAPPED_VALUE_WRAPPER" RENAME TO "MAPPED_VALUE_WRAPPER_DATA"; """
            ))
        session.execute(
            text(
                """ALTER TABLE "MAPPED_PROJECTION_DATA" RENAME TO "MAPPED_PROJECTION_MATRIX_DATA"; """
            ))
        session.commit()
    except Exception as excep:
        LOGGER.exception(excep)
    finally:
        session.close()
Ejemplo n.º 26
0
        session.close()

    session = SA_SESSIONMAKER()
    try:
        session.execute(
            text("""UPDATE "ALGORITHMS" SET
            module = (select G.module FROM "ALGORITHM_GROUPS" G WHERE "ALGORITHMS".fk_algo_group=G.id),
            classname = (select G.classname FROM "ALGORITHM_GROUPS" G WHERE "ALGORITHMS".fk_algo_group=G.id),
            displayname = (select G.displayname FROM "ALGORITHM_GROUPS" G WHERE "ALGORITHMS".fk_algo_group=G.id),
            fk_category = (select G.fk_category FROM "ALGORITHM_GROUPS" G WHERE "ALGORITHMS".fk_algo_group=G.id);"""
                 ))
        session.commit()

        # Delete old columns, no longer needed
        for col in DEL_COLUMNS:
            drop_column(col, table_algo)

        # Create constraint only after rows are being populated
        table_algo = meta.tables["ALGORITHMS"]
        fk_constraint = ForeignKeyConstraint(["fk_category"],
                                             ["ALGORITHM_CATEGORIES.id"],
                                             ondelete="CASCADE",
                                             table=table_algo)
        fk_constraint.create()

        # Drop old table
        session = SA_SESSIONMAKER()
        session.execute(text("""DROP TABLE "ALGORITHM_GROUPS";"""))
        session.commit()

    except Exception, excep: