From 5408e7ea02b5c1e0aa199f3c68f8df352a07a8e5 Mon Sep 17 00:00:00 2001 From: yangdx Date: Tue, 11 Feb 2025 04:19:12 +0800 Subject: [PATCH] Add table existence check for Oracle and PostgreSQL DB initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • 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 --- lightrag/lightrag.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lightrag/lightrag.py b/lightrag/lightrag.py index 3603509a..5518023d 100644 --- a/lightrag/lightrag.py +++ b/lightrag/lightrag.py @@ -447,6 +447,9 @@ class LightRAG: # 初始化 OracleDB 对象 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 对象 if self.kv_storage == "OracleKVStorage": @@ -496,8 +499,11 @@ class LightRAG: # 初始化 PostgreSQLDB 对象 postgres_db = PostgreSQLDB(dbconfig) + # Initialize and check tables loop = always_get_an_event_loop() 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 对象 if self.kv_storage == "PGKVStorage":