Add table existence check for Oracle and PostgreSQL DB initialization

• Add Oracle table check on startup
• Add PostgreSQL table check on startup
• Use event loop for async DB operations
• Ensure tables exist before DB operations
This commit is contained in:
yangdx
2025-02-11 04:19:12 +08:00
parent 7ec769456c
commit 5408e7ea02

View File

@@ -447,6 +447,9 @@ class LightRAG:
# 初始化 OracleDB 对象 # 初始化 OracleDB 对象
oracle_db = OracleDB(dbconfig) oracle_db = OracleDB(dbconfig)
# Check if DB tables exist, if not, tables will be created
loop = always_get_an_event_loop()
loop.run_until_complete(oracle_db.check_tables())
# 只对 Oracle 实现的存储类注入 db 对象 # 只对 Oracle 实现的存储类注入 db 对象
if self.kv_storage == "OracleKVStorage": if self.kv_storage == "OracleKVStorage":
@@ -496,8 +499,11 @@ class LightRAG:
# 初始化 PostgreSQLDB 对象 # 初始化 PostgreSQLDB 对象
postgres_db = PostgreSQLDB(dbconfig) postgres_db = PostgreSQLDB(dbconfig)
# Initialize and check tables
loop = always_get_an_event_loop() loop = always_get_an_event_loop()
loop.run_until_complete(postgres_db.initdb()) loop.run_until_complete(postgres_db.initdb())
# Check if DB tables exist, if not, tables will be created
loop.run_until_complete(postgres_db.check_tables())
# 只对 PostgreSQL 实现的存储类注入 db 对象 # 只对 PostgreSQL 实现的存储类注入 db 对象
if self.kv_storage == "PGKVStorage": if self.kv_storage == "PGKVStorage":