Skip to content

Commit ee38449

Browse files
committed
refactor: improve PostgreSQL migration code quality
Why this change is needed: 1. Added clarifying comments to _pg_migrate_workspace_data() parameter handling 2. Removed dead code from PGDocStatusStorage.initialize() that was never executed Changes: 1. PostgreSQL Migration Parameter Documentation (lightrag/kg/postgres_impl.py:2240-2241): - Added comments explaining dict rebuild for correct value ordering - Clarifies that Python 3.7+ dict insertion order is relied upon - Documents that execute() converts dict to tuple via .values() 2. Dead Code Removal (lightrag/kg/postgres_impl.py:3061-3062): - Removed unreachable table creation code from PGDocStatusStorage.initialize() - Table is already created by PostgreSQLDB.initdb() during initialization - This code path was never executed as table always exists before initialize() is called - Added NOTE comment explaining where table creation actually happens Impact: - No functional changes - only code clarification and cleanup - Reduces maintenance burden by removing unreachable code - Improves code readability with better documentation Testing: - All 14 PostgreSQL migration tests pass - All 5 UnifiedLock safety tests pass - Pre-commit checks pass (ruff-format, ruff)
1 parent 0fb7c5b commit ee38449

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lightrag/kg/postgres_impl.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,6 +2237,8 @@ async def _pg_migrate_workspace_data(
22372237
VALUES ({placeholders})
22382238
ON CONFLICT (workspace, id) DO NOTHING
22392239
"""
2240+
# Rebuild dict in columns order to ensure values() matches placeholders order
2241+
# Python 3.7+ dicts maintain insertion order, and execute() uses tuple(data.values())
22402242
values = {col: row_dict[col] for col in columns}
22412243
await db.execute(insert_query, values)
22422244

@@ -3058,11 +3060,8 @@ async def initialize(self):
30583060
# Use "default" for compatibility (lowest priority)
30593061
self.workspace = "default"
30603062

3061-
# Create table if not exists
3062-
table_name = namespace_to_table_name(self.namespace)
3063-
table_exists = await _pg_table_exists(self.db, table_name)
3064-
if not table_exists:
3065-
await _pg_create_table(self.db, table_name, table_name)
3063+
# NOTE: Table creation is handled by PostgreSQLDB.initdb() during initialization
3064+
# No need to create table here as it's already created in the TABLES dict
30663065

30673066
async def finalize(self):
30683067
if self.db is not None:

0 commit comments

Comments
 (0)