Skip to content

Commit 53424eb

Browse files
author
Scott Sanderson
committed
BUG: Drop orphaned records from asset db in v6 downgrade.
Remove records that no longer refer to equities from equity_symbol_mappings and asset_router.
1 parent b5424b8 commit 53424eb

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

zipline/assets/asset_db_migrations.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,3 +526,28 @@ def _downgrade_v7(op):
526526
sa.Column('multiplier', sa.Float),
527527
sa.Column('tick_size', sa.Float),
528528
)
529+
530+
# Delete equity_symbol_mappings records that no longer refer to valid sids.
531+
op.execute(
532+
"""
533+
DELETE FROM
534+
equity_symbol_mappings
535+
WHERE
536+
sid NOT IN (SELECT sid FROM equities);
537+
"""
538+
)
539+
540+
# Delete asset_router records that no longer refer to valid sids.
541+
op.execute(
542+
"""
543+
DELETE FROM
544+
asset_router
545+
WHERE
546+
sid
547+
NOT IN (
548+
SELECT sid FROM equities
549+
UNION
550+
SELECT sid FROM futures_contracts
551+
);
552+
"""
553+
)

0 commit comments

Comments
 (0)