From d24a23ec96ebb11c86f81fc7214dea39b7ec7893 Mon Sep 17 00:00:00 2001 From: Apple Date: Tue, 2 Dec 2025 01:57:27 -0800 Subject: [PATCH] fix(db-hardening): Add lib __init__.py and improve MinIO import error handling --- docs/DB_HARDENING_QUICKSTART.md | 71 +++++++++++++++++++++++++++ services/city-service/lib/__init__.py | 7 +++ services/city-service/routes_city.py | 4 +- 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 docs/DB_HARDENING_QUICKSTART.md create mode 100644 services/city-service/lib/__init__.py diff --git a/docs/DB_HARDENING_QUICKSTART.md b/docs/DB_HARDENING_QUICKSTART.md new file mode 100644 index 00000000..9153b50d --- /dev/null +++ b/docs/DB_HARDENING_QUICKSTART.md @@ -0,0 +1,71 @@ +# DB Hardening Quick Start + +## Швидкий старт + +### 1. Запустити PostgreSQL + Backup + MinIO + +```bash +docker compose -f docker-compose.db.yml up -d +``` + +### 2. Налаштувати MinIO + +1. Відкрити консоль: `http://localhost:9001` +2. Логін: `assets-admin` / пароль з `.env` +3. Створити bucket: `daarion-assets` +4. Встановити public read policy + +### 3. Налаштувати ENV + +Додати в `.env`: + +```env +POSTGRES_PASSWORD=your-secure-password +MINIO_ROOT_USER=assets-admin +MINIO_ROOT_PASSWORD=your-secure-password +ASSETS_BUCKET=daarion-assets +ASSETS_PUBLIC_BASE_URL=https://assets.daarion.space/daarion-assets +MINIO_ENDPOINT=http://minio:9000 +``` + +### 4. Перевірити + +```bash +# PostgreSQL +docker exec daarion-postgres psql -U postgres -d daarion -c "SELECT 1;" + +# MinIO +curl http://localhost:9000/minio/health/live + +# Backup +ls -lh db_backups/ +``` + +--- + +## Якщо база втрачена + +### Швидке відновлення + +```bash +# 1. Застосувати міграції +for f in migrations/*.sql; do + docker exec -i daarion-postgres psql -U postgres -d daarion < "$f" +done + +# 2. Seed базові дані +python3 scripts/seed_full_city_reset.py + +# 3. DAGI-агенти NODE2 +python3 scripts/sync-node2-dagi-agents.py +``` + +--- + +## Документація + +- **DB_RESTORE.md** - відновлення з бекапу +- **SEED_RECOVERY.md** - аварійне відновлення +- **INFRA_ASSETS_MINIO.md** - налаштування MinIO +- **TASK_PHASE_DATABASE_HARDENING_AND_ASSETS_MIGRATION_v1.md** - повний таск + diff --git a/services/city-service/lib/__init__.py b/services/city-service/lib/__init__.py new file mode 100644 index 00000000..3601e0a8 --- /dev/null +++ b/services/city-service/lib/__init__.py @@ -0,0 +1,7 @@ +""" +City Service Library +""" +from .assets_client import upload_asset, delete_asset, ensure_bucket + +__all__ = ['upload_asset', 'delete_asset', 'ensure_bucket'] + diff --git a/services/city-service/routes_city.py b/services/city-service/routes_city.py index fff0cdcf..02145fa2 100644 --- a/services/city-service/routes_city.py +++ b/services/city-service/routes_city.py @@ -18,9 +18,9 @@ import shutil try: from lib.assets_client import upload_asset as minio_upload_asset MINIO_AVAILABLE = True -except ImportError: +except ImportError as e: MINIO_AVAILABLE = False - logger.warning("MinIO client not available, falling back to local storage") + logger.warning(f"MinIO client not available, falling back to local storage: {e}") from models_city import ( CityRoomRead,