fix: resolve foreign key constraint violation during checkpoint restore
Issue: - Restore operation failed with foreign key constraint violation - Error: "update or delete on table business_scopes violates foreign key constraint" - Problem: DELETE operations didn't handle foreign key dependencies correctly Solution: - Changed DELETE FROM to TRUNCATE TABLE ... CASCADE in _restore_table() - TRUNCATE with CASCADE automatically removes dependent records - Now restore operation properly handles all foreign key relationships - Data can be restored without constraint violations This ensures checkpoint restore works correctly across all related tables. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
a5d56ade26
commit
e462f609ba
File diff suppressed because one or more lines are too long
|
|
@ -386,10 +386,11 @@ def _restore_table(conn: pg.Connection, table_name: str, data: List[Dict[str, An
|
|||
try:
|
||||
cur = conn.cursor()
|
||||
|
||||
delete_sql = f"DELETE FROM {table_name}"
|
||||
cur.execute(delete_sql)
|
||||
# Use TRUNCATE with CASCADE to handle foreign key dependencies
|
||||
# This will automatically remove dependent records
|
||||
truncate_sql = f"TRUNCATE TABLE {table_name} CASCADE"
|
||||
cur.execute(truncate_sql)
|
||||
|
||||
if data:
|
||||
columns = list(data[0].keys())
|
||||
placeholders = ", ".join(["%s"] * len(columns))
|
||||
insert_sql = f"INSERT INTO {table_name} ({', '.join(columns)}) VALUES ({placeholders})"
|
||||
|
|
|
|||
Loading…
Reference in New Issue