Ejemplo n.º 1
0
def upgrade(engine):
    # Create a session.
    session = sessionmaker(engine)()

    real_sample_type = session.query(upgrade_0_to_1.SampleType). \
        filter_by(name="Real").first()

    ts = session.query(upgrade_0_to_1.TestSuite).filter_by(name='nts').first()
    score = upgrade_0_to_1.SampleField(name="score", type=real_sample_type)
    ts.sample_fields.append(score)
    session.add(ts)

    session.commit()
    session.close()

    test_suite_sample_fields = introspect_table(engine,
                                                'TestSuiteSampleFields')

    set_scores = update(test_suite_sample_fields) \
        .where(test_suite_sample_fields.c.Name == "score") \
        .values(bigger_is_better=1)

    with engine.begin() as trans:
        trans.execute(set_scores)
        # Give the NT table a score column.
        score = Column('score', Float)
        add_column(trans, 'NT_Sample', score)
Ejemplo n.º 2
0
def upgrade(engine):
    # Create a session.
    session = sqlalchemy.orm.sessionmaker(engine)()

    real_sample_type = session.query(upgrade_0_to_1.SampleType).\
        filter_by(name="Real").first()

    ts = session.query(upgrade_0_to_1.TestSuite).filter_by(name='nts').first()
    mem_bytes = upgrade_0_to_1.SampleField(name="mem_bytes",
                                           type=real_sample_type)
    ts.sample_fields.append(mem_bytes)
    session.add(ts)
    session.commit()
    session.close()

    test_suite_sample_fields = introspect_table(engine,
                                                'TestSuiteSampleFields')

    set_mem = update(test_suite_sample_fields) \
        .where(test_suite_sample_fields.c.Name == "mem_bytes") \
        .values(bigger_is_better=0)

    # upgrade_3_to_4.py added this column, so it is not in the ORM.
    with engine.begin() as trans:
        trans.execute(set_mem)
        mem_bytes = Column('mem_bytes', Float)
        add_column(trans, 'NT_Sample', mem_bytes)
Ejemplo n.º 3
0
def upgrade(engine):
    # Create a session.
    session = sqlalchemy.orm.sessionmaker(engine)()

    real_sample_type = session.query(upgrade_0_to_1.SampleType).\
        filter_by(name="Real").first()

    ts = session.query(upgrade_0_to_1.TestSuite).filter_by(name='nts').first()
    code_size = upgrade_0_to_1.SampleField(name="code_size",
                                           type=real_sample_type)
    ts.sample_fields.append(code_size)
    session.add(ts)
    session.commit()
    session.close()

    test_suite_sample_fields = introspect_table(engine,
                                                'TestSuiteSampleFields')
    update_code_size = update(test_suite_sample_fields) \
        .where(test_suite_sample_fields.c.Name == "code_size") \
        .values(bigger_is_better=0)
    # upgrade_3_to_4.py added this column, so it is not in the ORM.

    with engine.begin() as trans:
        trans.execute(update_code_size)
        code_size = Column('code_size', Float)
        add_column(trans, 'NT_Sample', code_size)
Ejemplo n.º 4
0
def _mk_index_on(engine, ts_name):
    fc_table = introspect_table(engine, "{}_FieldChangeV2".format(ts_name))

    fast_fc_lookup = Index('idx_fast_fieldchange_lookup', fc_table.c.StartOrderID)
    try:
        fast_fc_lookup.create(engine)
    except (sqlalchemy.exc.OperationalError, sqlalchemy.exc.ProgrammingError) as e:
        logger.warning("Skipping index creation on {}, because of {}".format(fc_table.name, e.message))
Ejemplo n.º 5
0
def _mk_index_on(engine, ts_name):
    fc_table = introspect_table(engine, "{}_RegressionIndicator".format(ts_name))

    fast_fc_lookup = Index('idx_fast_ri_lookup', fc_table.c.RegressionID)
    try:
        fast_fc_lookup.create(engine)
    except (sqlalchemy.exc.OperationalError, sqlalchemy.exc.ProgrammingError) as e:
        logger.warning("Skipping index creation on {}, because of {}".format(fc_table.name, e.message))
Ejemplo n.º 6
0
def drop_fields(engine, test_suite_id, name, trans):
    """In the *Fields Tables, drop entries related to the test_suite_id.
    """
    fields_table = introspect_table(engine, name)
    order_files = delete(fields_table,
                         fields_table.c.TestSuiteID == test_suite_id)
    trans.execute(order_files)
    return fields_table
Ejemplo n.º 7
0
def _mk_index_on(engine, ts_name):
    fc_table = introspect_table(engine, "{}_RegressionIndicator".format(ts_name))

    fast_fc_lookup = Index('idx_fast_ri_lookup', fc_table.c.RegressionID)
    try:
        fast_fc_lookup.create(engine)
    except (sqlalchemy.exc.OperationalError, sqlalchemy.exc.ProgrammingError) as e:
        logger.warning("Skipping index creation on {}, because of {}".format(fc_table.name, e.message))
Ejemplo n.º 8
0
def _mk_index_on(engine, ts_name):
    fc_table = introspect_table(engine, "{}_FieldChangeV2".format(ts_name))

    fast_fc_lookup = Index('idx_fast_fieldchange_lookup',
                           fc_table.c.StartOrderID)
    try:
        fast_fc_lookup.create(engine)
    except (sqlalchemy.exc.OperationalError,
            sqlalchemy.exc.ProgrammingError) as e:
        logger.warning("Skipping index creation on {}, because of {}".format(
            fc_table.name, e.message))
Ejemplo n.º 9
0
def upgrade(engine):
    """Add an index to FieldChangeV2 for each fo the test-suites.
    """

    test_suite = introspect_table(engine, 'TestSuite')

    with engine.begin() as trans:
        db_keys = list(trans.execute(select([test_suite])))

    for suite in db_keys:
        with engine.begin() as trans:
            _mk_index_on(trans, suite[2])
Ejemplo n.º 10
0
def upgrade(engine):
    """Add an index to FieldChangeV2 for each fo the test-suites.
    """

    test_suite = introspect_table(engine, 'TestSuite')

    with engine.begin() as trans:
        db_keys = list(trans.execute(select([test_suite])))

    for suite in db_keys:
        with engine.begin() as trans:
            _mk_index_on(trans, suite[2])
Ejemplo n.º 11
0
def upgrade(engine):
    table_renames = [
        TableRename('Compile_Baseline', 'compile_Baseline'),
        TableRename('Compile_ChangeIgnore', 'compile_ChangeIgnore'),
        TableRename('Compile_RegressionIndicator',
                    'compile_RegressionIndicator'),
        TableRename('Compile_FieldChange', 'compile_FieldChange'),
        TableRename('Compile_FieldChangeV2', 'compile_FieldChangeV2'),
        TableRename('Compile_Profile', 'compile_Profile'),
        TableRename('Compile_Regression', 'compile_Regression'),
        TableRename('Compile_Sample', 'compile_Sample'),
        TableRename('Compile_Run', 'compile_Run'),
        TableRename('Compile_Order', 'compile_Order'),
        TableRename('Compile_Test', 'compile_Test'),
        TableRename('Compile_Machine', 'compile_Machine'),
    ]
    all_empty = True
    for rename in table_renames:
        tab = introspect_table(engine, rename.old_name)
        size = select([func.count(tab.c.ID)])
        num = engine.execute(size).scalar()

        if num > 0:
            all_empty = False
            break
    test_suite = introspect_table(engine, 'TestSuite')
    with engine.begin() as trans:
        # If nobody ever put data into the compile suite drop it.
        if all_empty:
            for name, _ in table_renames:
                tab = introspect_table(engine, name)
                tab.drop()
            _drop_suite(trans, 'compile', engine)
        else:
            for rename in table_renames:
                rename_table(engine, rename.old_name, rename.new_name)
            # Just change the DB_Key to match the name
            trans.execute(update(test_suite)
                          .where(test_suite.c.Name == 'compile')
                          .values(DBKeyName='compile'))
Ejemplo n.º 12
0
def drop_samples_fields(engine, test_suite_id, trans):
    """In the TestSuiteSampleFields, drop entries related to the test_suite_id.

    This extra function is needed because in MySQL it can't sort out the forign
    keys in the same table.
    """
    samples_table = introspect_table(engine, 'TestSuiteSampleFields')
    order_files = delete(samples_table,
                         and_(samples_table.c.TestSuiteID == test_suite_id,
                              samples_table.c.status_field.isnot(None)))
    trans.execute(order_files)
    order_files = delete(samples_table,
                         samples_table.c.TestSuiteID == test_suite_id)
    trans.execute(order_files)
    return samples_table
Ejemplo n.º 13
0
def _drop_suite(trans, name, engine):
    """Drop the suite name.

    This patches up the suite description tables for Order Fields,
    Machine Fields, Run Fields and Sample Fields.

    After than remove the suite directly from the TestSuite table.
    """

    test_suite = introspect_table(engine, 'TestSuite')

    test_suite_id = trans.execute(
        select([test_suite.c.ID]).where(test_suite.c.Name == name)) \
        .scalar()

    drop_fields(engine, test_suite_id, 'TestSuiteOrderFields', trans)
    drop_fields(engine, test_suite_id, 'TestSuiteMachineFields', trans)
    drop_fields(engine, test_suite_id, 'TestSuiteRunFields', trans)

    drop_samples_fields(engine, test_suite_id, trans)

    trans.execute(delete(test_suite).where(test_suite.c.Name == name))
Ejemplo n.º 14
0
def update_testsuite(engine, db_key_name):
    table_name = '%s_FieldChange' % db_key_name
    with engine.begin() as trans:
        table = introspect_table(engine, table_name, autoload=False)
        table.drop(checkfirst=True)