mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-04 23:02:02 +08:00
ENH: Adding exchange_full to equity asset column
This commit is contained in:
Binary file not shown.
@@ -1313,6 +1313,15 @@ class TestAssetDBVersioning(ZiplineTestCase):
|
||||
def test_downgrade(self):
|
||||
# Attempt to downgrade a current assets db all the way down to v0
|
||||
conn = self.engine.connect()
|
||||
|
||||
# first downgrade to v3
|
||||
downgrade(self.engine, 3)
|
||||
metadata = sa.MetaData(conn)
|
||||
metadata.reflect(bind=self.engine)
|
||||
check_version_info(metadata.tables['version_info'], 3)
|
||||
self.assertFalse('exchange_full' in metadata.tables)
|
||||
|
||||
# now go all the way to v0
|
||||
downgrade(self.engine, 0)
|
||||
|
||||
# Verify that the db version is now 0
|
||||
|
||||
@@ -148,7 +148,6 @@ def _downgrade_v2(op):
|
||||
|
||||
# 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
|
||||
@@ -195,7 +194,7 @@ def _downgrade_v3(op):
|
||||
)
|
||||
op.drop_table('equities')
|
||||
op.rename_table('_new_equities', 'equities')
|
||||
# we need to make sure the indicies have the proper names after the rename
|
||||
# we need to make sure the indices have the proper names after the rename
|
||||
op.create_index(
|
||||
'ix_equities_company_symbol',
|
||||
'equities',
|
||||
@@ -206,3 +205,25 @@ def _downgrade_v3(op):
|
||||
'equities',
|
||||
['fuzzy_symbol'],
|
||||
)
|
||||
|
||||
|
||||
@downgrades(4)
|
||||
def _downgrade_v4(op):
|
||||
"""
|
||||
Downgrades assets db by copying the `exchange_full` column to `exchange`,
|
||||
then dropping the `exchange_full` column.
|
||||
"""
|
||||
op.drop_index('ix_equities_fuzzy_symbol')
|
||||
op.drop_index('ix_equities_company_symbol')
|
||||
|
||||
op.execute("UPDATE equities SET exchange = exchange_full")
|
||||
|
||||
with op.batch_alter_table('equities') as batch_op:
|
||||
batch_op.drop_column('exchange_full')
|
||||
|
||||
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'])
|
||||
|
||||
@@ -6,7 +6,7 @@ import sqlalchemy as sa
|
||||
# assets database
|
||||
# NOTE: When upgrading this remember to add a downgrade in:
|
||||
# .asset_db_migrations
|
||||
ASSET_DB_VERSION = 3
|
||||
ASSET_DB_VERSION = 4
|
||||
|
||||
|
||||
def generate_asset_db_metadata(bind=None):
|
||||
@@ -55,6 +55,7 @@ def _equities_table_schema(metadata):
|
||||
sa.Column('first_traded', sa.Integer),
|
||||
sa.Column('auto_close_date', sa.Integer),
|
||||
sa.Column('exchange', sa.Text),
|
||||
sa.Column('exchange_full', sa.Text)
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -41,7 +41,10 @@ _equities_defaults = {
|
||||
'end_date': 2 ** 62 - 1,
|
||||
'first_traded': None,
|
||||
'auto_close_date': None,
|
||||
# the canonical exchange name, like "NYSE"
|
||||
'exchange': None,
|
||||
# optional, something like "New York Stock Exchange"
|
||||
'exchange_full': None,
|
||||
}
|
||||
|
||||
# Default values for the futures DataFrame
|
||||
|
||||
Reference in New Issue
Block a user