MAINT: Put downgrade in transaction

This commit is contained in:
Richard Frank
2016-08-24 13:24:07 -04:00
parent bc87ea4efb
commit 418e8901f4
2 changed files with 8 additions and 8 deletions
+2 -2
View File
@@ -24,7 +24,7 @@ def downgrade(engine, desired_version):
"""
# Check the version of the db at the engine
with engine.connect() as conn:
with engine.begin() as conn:
metadata = sa.MetaData(conn)
metadata.reflect()
version_info_table = metadata.tables['version_info']
@@ -100,7 +100,7 @@ def downgrades(src):
@do(op.setitem(_downgrade_methods, destination))
@wraps(f)
def wrapper(op, conn, version_info_table):
version_info_table.delete().execute() # clear the version
conn.execute(version_info_table.delete()) # clear the version
f(op)
write_version_info(conn, version_info_table, destination)
+6 -6
View File
@@ -442,9 +442,9 @@ class AssetDBWriter(object):
--------
zipline.assets.asset_finder
"""
with self.engine.begin() as txn:
with self.engine.begin() as conn:
# Create SQL tables if they do not exist.
self.init_db(txn)
self.init_db(conn)
# Get the data to add to SQL.
data = self._load_data(
@@ -457,25 +457,25 @@ class AssetDBWriter(object):
self._write_df_to_table(
futures_exchanges,
data.exchanges,
txn,
conn,
chunk_size,
)
self._write_df_to_table(
futures_root_symbols,
data.root_symbols,
txn,
conn,
chunk_size,
)
self._write_assets(
'future',
data.futures,
txn,
conn,
chunk_size,
)
self._write_assets(
'equity',
data.equities,
txn,
conn,
chunk_size,
mapping_data=data.equities_mappings,
)