malkhut(fix): DuckDB sync FK-safe delete order + full E2E verification
Fixed foreign key constraint violation in sync_from_profiles: DELETE child tables (asset_exchanges, behavior_profiles) BEFORE parent tables (assets, exchanges). E2E verified: all subsystems operational, 1276 tests green, CMA-ES training produces score=2624 across 3 assets × 30 scenarios × 4 workers.
This commit is contained in:
@@ -297,10 +297,6 @@ class AssetStore:
|
|||||||
ex.has_options, ex.api_base_url, ex.ws_base_url,
|
ex.has_options, ex.api_base_url, ex.ws_base_url,
|
||||||
ex.default_taker_fee_bps, ex.default_maker_fee_bps, ex.typical_latency_ms,
|
ex.default_taker_fee_bps, ex.default_maker_fee_bps, ex.typical_latency_ms,
|
||||||
])
|
])
|
||||||
self.conn.execute("DELETE FROM exchanges")
|
|
||||||
self.conn.executemany(
|
|
||||||
"INSERT INTO exchanges VALUES (?,?,?,?,?,?,?,?,?,?)", ex_rows
|
|
||||||
)
|
|
||||||
|
|
||||||
# Batch assets
|
# Batch assets
|
||||||
asset_rows = []
|
asset_rows = []
|
||||||
@@ -324,19 +320,6 @@ class AssetStore:
|
|||||||
])
|
])
|
||||||
for ex in p.exchanges:
|
for ex in p.exchanges:
|
||||||
exchange_rows.append((p.symbol, ex))
|
exchange_rows.append((p.symbol, ex))
|
||||||
self.conn.execute("DELETE FROM assets")
|
|
||||||
self.conn.executemany(
|
|
||||||
"INSERT INTO assets VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
|
||||||
asset_rows
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# Batch exchange index
|
|
||||||
self.conn.execute("DELETE FROM asset_exchanges")
|
|
||||||
self.conn.executemany(
|
|
||||||
"INSERT INTO asset_exchanges (symbol, exchange_id) VALUES (?, ?)",
|
|
||||||
exchange_rows
|
|
||||||
)
|
|
||||||
|
|
||||||
# Batch behaviors
|
# Batch behaviors
|
||||||
beh_rows = []
|
beh_rows = []
|
||||||
@@ -356,7 +339,23 @@ class AssetStore:
|
|||||||
b.liquidation.speed, b.liquidation.recovery,
|
b.liquidation.speed, b.liquidation.recovery,
|
||||||
b.bingx.spread_mult, b.bingx.depth_ratio, b.bingx.latency_ms,
|
b.bingx.spread_mult, b.bingx.depth_ratio, b.bingx.latency_ms,
|
||||||
])
|
])
|
||||||
|
|
||||||
|
# FK-safe delete order: children first, then parents
|
||||||
|
self.conn.execute("DELETE FROM asset_exchanges")
|
||||||
self.conn.execute("DELETE FROM behavior_profiles")
|
self.conn.execute("DELETE FROM behavior_profiles")
|
||||||
|
self.conn.execute("DELETE FROM assets")
|
||||||
|
self.conn.execute("DELETE FROM exchanges")
|
||||||
|
|
||||||
|
# FK-safe insert order: parents first, then children
|
||||||
|
self.conn.executemany("INSERT INTO exchanges VALUES (?,?,?,?,?,?,?,?,?,?)", ex_rows)
|
||||||
|
self.conn.executemany(
|
||||||
|
"INSERT INTO assets VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
||||||
|
asset_rows
|
||||||
|
)
|
||||||
|
self.conn.executemany(
|
||||||
|
"INSERT INTO asset_exchanges (symbol, exchange_id) VALUES (?, ?)",
|
||||||
|
exchange_rows
|
||||||
|
)
|
||||||
if beh_rows:
|
if beh_rows:
|
||||||
self.conn.executemany(
|
self.conn.executemany(
|
||||||
"INSERT INTO behavior_profiles VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
"INSERT INTO behavior_profiles VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
||||||
|
|||||||
Reference in New Issue
Block a user