File size: 1,171 Bytes
ef83cbc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#!/usr/bin/env python3
"""
統合データベースヘルパー関数
全てのGradioコントローラー用の統一データベースアクセス
"""
import sqlite3
import os
import sys
# パスを追加してconfig/database.pyにアクセス
current_dir = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.join(current_dir, '..', '..')
sys.path.append(project_root)
def get_unified_db_connection(db_name='approval_system'):
"""統一されたデータベース接続を取得"""
try:
from config.database import get_db_connection
return get_db_connection(db_name)
except ImportError:
# フォールバック: 直接データベースパスを指定
db_path = f"/workspaces/fastapi_django_main_lives/database/{db_name}.db"
os.makedirs(os.path.dirname(db_path), exist_ok=True)
return sqlite3.connect(db_path)
def ensure_unified_tables():
"""統一されたテーブル初期化"""
try:
from config.database import ensure_tables_exist
ensure_tables_exist()
except ImportError:
# フォールバック処理
pass
|