fix: specify conflict target in PostgreSQL ON CONFLICT clause

Why this change is needed:
PostgreSQL requires an explicit conflict target specification when using
ON CONFLICT with tables that have composite primary keys. Without it,
PostgreSQL throws: "ON CONFLICT DO NOTHING requires inference specification
or constraint name". This syntax error occurs during data migration from
legacy tables when users upgrade from older LightRAG versions.

How it solves it:
Changed line 2378 from "ON CONFLICT DO NOTHING" to "ON CONFLICT (workspace, id)
DO NOTHING" to match the table's PRIMARY KEY (workspace, id) constraint.
This aligns with the correct syntax used in all other 12 ON CONFLICT clauses
throughout the codebase (e.g., line 684, 5229, 5236, etc.).

Impact:
- Fixes migration failure in PGVectorStorage.setup_table()
- Prevents syntax errors when migrating data from legacy tables
- Maintains consistency with all other ON CONFLICT usages in postgres_impl.py
- Affects users upgrading from pre-model-suffix table structure

Testing:
Verified by examining:
- All 12 existing ON CONFLICT usages specify (workspace, id)
- All PostgreSQL tables use PRIMARY KEY (workspace, id)
- Migration code at line 684 uses identical correct syntax
This commit is contained in:
BukeLy 2025-11-20 11:47:15 +08:00
parent 8386ea061e
commit c89b0ee599

View file

@ -2375,7 +2375,7 @@ class PGVectorStorage(BaseVectorStorage):
insert_query = f"""
INSERT INTO {table_name} ({columns_str})
VALUES ({placeholders})
ON CONFLICT DO NOTHING
ON CONFLICT (workspace, id) DO NOTHING
"""
# Construct dict for execute() method