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)
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)
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() score = upgrade_0_to_1.SampleField( name="score", type=real_sample_type, info_key=".score", ) ts.sample_fields.append(score) session.add(ts) session.commit() # upgrade_3_to_4.py added this column, so it is not in the ORM. session.connection().execute(""" UPDATE "TestSuiteSampleFields" SET bigger_is_better=1 WHERE "Name"='score' """) session.commit() # FIXME: This is obviously not the right way to do this, but I gave up # trying to find out how to do it properly in SQLAlchemy without # SQLAlchemy-migrate installed. session.connection().execute(""" ALTER TABLE "NT_Sample" ADD COLUMN "score" FLOAT """) session.commit()