def _downgrade_v2_to_v1(op, version_info_table): """ Downgrade assets db by removing the 'auto_close_date' column. """ version_info_table.delete().execute() # Drop indices before batch # This is to prevent index collision when creating the temp table op.drop_index('ix_equities_fuzzy_symbol') op.drop_index('ix_equities_company_symbol') # Execute batch op to allow column modification in SQLite with op.batch_alter_table('equities') as batch_op: batch_op.drop_column('auto_close_date') # Recreate indices after batch op.create_index('ix_equities_fuzzy_symbol', table_name='equities', columns=['fuzzy_symbol']) op.create_index('ix_equities_company_symbol', table_name='equities', columns=['company_symbol']) write_version_info(version_info_table, 1)
def _downgrade_v1_to_v0(op, version_info_table): """ Downgrade assets db by removing the 'tick_size' column and renaming the 'multiplier' column. """ version_info_table.delete().execute() # Drop indices before batch # This is to prevent index collision when creating the temp table op.drop_index('ix_futures_contracts_root_symbol') op.drop_index('ix_futures_contracts_symbol') # Execute batch op to allow column modification in SQLite with op.batch_alter_table('futures_contracts') as batch_op: # Rename 'multiplier' batch_op.alter_column(column_name='multiplier', new_column_name='contract_multiplier') # Delete 'tick_size' batch_op.drop_column('tick_size') # Recreate indices after batch op.create_index('ix_futures_contracts_root_symbol', table_name='futures_contracts', columns=['root_symbol']) op.create_index('ix_futures_contracts_symbol', table_name='futures_contracts', columns=['symbol'], unique=True) write_version_info(version_info_table, 0)
def test_finder_checks_version(self): version_table = self.metadata.tables['version_info'] version_table.delete().execute() write_version_info(version_table, -2) check_version_info(version_table, -2) # Assert that trying to build a finder with a bad db raises an error with self.assertRaises(AssetDBVersionError): AssetFinder(engine=self.engine) # Change the version number of the db to the correct version version_table.delete().execute() write_version_info(version_table, ASSET_DB_VERSION) check_version_info(version_table, ASSET_DB_VERSION) # Now that the versions match, this Finder should succeed AssetFinder(engine=self.engine)
def test_finder_checks_version(self): version_table = self.metadata.tables['version_info'] version_table.delete().execute() write_version_info(self.engine, version_table, -2) check_version_info(self.engine, version_table, -2) # Assert that trying to build a finder with a bad db raises an error with self.assertRaises(AssetDBVersionError): AssetFinder(engine=self.engine) # Change the version number of the db to the correct version version_table.delete().execute() write_version_info(self.engine, version_table, ASSET_DB_VERSION) check_version_info(self.engine, version_table, ASSET_DB_VERSION) # Now that the versions match, this Finder should succeed AssetFinder(engine=self.engine)
def test_finder_checks_version(self): # Create an env and give it a bogus version number env = TradingEnvironment(load=noop_load) metadata = sa.MetaData(bind=env.engine) version_table = _version_table_schema(metadata) version_table.delete().execute() write_version_info(version_table, -2) check_version_info(version_table, -2) # Assert that trying to build a finder with a bad db raises an error with self.assertRaises(AssetDBVersionError): AssetFinder(engine=env.engine) # Change the version number of the db to the correct version version_table.delete().execute() write_version_info(version_table, ASSET_DB_VERSION) check_version_info(version_table, ASSET_DB_VERSION) # Now that the versions match, this Finder should succeed AssetFinder(engine=env.engine)
def test_write_version(self): version_table = self.metadata.tables['version_info'] version_table.delete().execute() # Assert that the version is not present in the table self.assertIsNone(sa.select((version_table.c.version,)).scalar()) # This should fail because the table has no version info and is, # therefore, consdered v0 with self.assertRaises(AssetDBVersionError): check_version_info(version_table, -2) # This should not raise an error because the version has been written write_version_info(version_table, -2) check_version_info(version_table, -2) # Assert that the version is in the table and correct self.assertEqual(sa.select((version_table.c.version,)).scalar(), -2) # Assert that trying to overwrite the version fails with self.assertRaises(sa.exc.IntegrityError): write_version_info(version_table, -3)
def test_write_version(self): version_table = self.metadata.tables['version_info'] version_table.delete().execute() # Assert that the version is not present in the table self.assertIsNone(sa.select((version_table.c.version, )).scalar()) # This should fail because the table has no version info and is, # therefore, consdered v0 with self.assertRaises(AssetDBVersionError): check_version_info(self.engine, version_table, -2) # This should not raise an error because the version has been written write_version_info(self.engine, version_table, -2) check_version_info(self.engine, version_table, -2) # Assert that the version is in the table and correct self.assertEqual(sa.select((version_table.c.version, )).scalar(), -2) # Assert that trying to overwrite the version fails with self.assertRaises(sa.exc.IntegrityError): write_version_info(self.engine, version_table, -3)
def test_write_version(self): env = TradingEnvironment(load=noop_load) metadata = sa.MetaData(bind=env.engine) version_table = _version_table_schema(metadata) version_table.delete().execute() # Assert that the version is not present in the table self.assertIsNone(sa.select((version_table.c.version,)).scalar()) # This should fail because the table has no version info and is, # therefore, consdered v0 with self.assertRaises(AssetDBVersionError): check_version_info(version_table, -2) # This should not raise an error because the version has been written write_version_info(version_table, -2) check_version_info(version_table, -2) # Assert that the version is in the table and correct self.assertEqual(sa.select((version_table.c.version,)).scalar(), -2) # Assert that trying to overwrite the version fails with self.assertRaises(sa.exc.IntegrityError): write_version_info(version_table, -3)
def test_write_version(self): env = TradingEnvironment(load=noop_load) metadata = sa.MetaData(bind=env.engine) version_table = _version_table_schema(metadata) version_table.delete().execute() # Assert that the version is not present in the table self.assertIsNone(sa.select((version_table.c.version, )).scalar()) # This should fail because the table has no version info and is, # therefore, consdered v0 with self.assertRaises(AssetDBVersionError): check_version_info(version_table, -2) # This should not raise an error because the version has been written write_version_info(version_table, -2) check_version_info(version_table, -2) # Assert that the version is in the table and correct self.assertEqual(sa.select((version_table.c.version, )).scalar(), -2) # Assert that trying to overwrite the version fails with self.assertRaises(sa.exc.IntegrityError): write_version_info(version_table, -3)
def wrapper(op, conn, version_info_table): conn.execute(version_info_table.delete()) # clear the version f(op) write_version_info(conn, version_info_table, destination)
def wrapper(op, engine, version_info_table): version_info_table.delete().execute() # clear the version f(op) write_version_info(engine, version_info_table, destination)