refactor(core): декомпозиция db_cli, сервисный дамп БД и зачистка контекста
This commit is contained in:
+23
-1
@@ -5,6 +5,10 @@ ROLE: Фасад ядра базы данных с полной обратной
|
||||
===============================================================================
|
||||
"""
|
||||
|
||||
import os
|
||||
import pandas as pd
|
||||
from config import OUTPUT_DIR
|
||||
|
||||
from core.connection import get_connection, DB_PATH
|
||||
from core.schema import init_all_tables
|
||||
|
||||
@@ -32,4 +36,22 @@ from core.repositories.zup_repo import (
|
||||
add_department_synonym_to_db
|
||||
)
|
||||
|
||||
init_db = init_all_tables
|
||||
init_db = init_all_tables
|
||||
|
||||
def dump_database_to_excel(out_filename: str = "db_dump_full.xlsx") -> str:
|
||||
"""Создает полный дамп всех ключевых таблиц SQLite в многостраничный Excel."""
|
||||
out_path = os.path.join(OUTPUT_DIR, out_filename)
|
||||
tables = [
|
||||
'scud_logs', 'scud_events_raw', 'zup_staff', 'zup_absences',
|
||||
'anomalies_history', 'ai_knowledge_base', 'chat_messages',
|
||||
'session_states', 'system_prompt_nodes', 'tasks',
|
||||
'exceptions_registry', 'manual_absences', 'person_identity_mapping'
|
||||
]
|
||||
with get_connection() as conn, pd.ExcelWriter(out_path, engine='openpyxl') as writer:
|
||||
for table in tables:
|
||||
try:
|
||||
df = pd.read_sql_query(f"SELECT * FROM {table}", conn)
|
||||
df.to_excel(writer, sheet_name=table[:31], index=False)
|
||||
except Exception:
|
||||
pass
|
||||
return out_path
|
||||
Reference in New Issue
Block a user