- Fixed a critical in the company-explorer by forcing a database re-initialization with a new file (). This ensures the application code is in sync with the database schema. - Documented the schema mismatch incident and its resolution in MIGRATION_PLAN.md. - Restored and enhanced BUILDER_APPS_MIGRATION.md by recovering extensive, valuable content from the git history that was accidentally deleted. The guide now again includes detailed troubleshooting steps and code templates for common migration pitfalls.
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
import os
|
|
import logging
|
|
from typing import Optional
|
|
|
|
# Versuche Pydantic zu nutzen, Fallback auf os.environ
|
|
try:
|
|
from pydantic_settings import BaseSettings
|
|
from pydantic import Extra
|
|
|
|
class Settings(BaseSettings):
|
|
# App Info
|
|
APP_NAME: str = "Company Explorer"
|
|
VERSION: str = "0.4.0"
|
|
DEBUG: bool = True
|
|
|
|
# Database (Store in App dir for simplicity)
|
|
DATABASE_URL: str = "sqlite:////app/companies_v3_fixed_2.db"
|
|
|
|
# API Keys
|
|
GEMINI_API_KEY: Optional[str] = None
|
|
OPENAI_API_KEY: Optional[str] = None
|
|
SERP_API_KEY: Optional[str] = None
|
|
|
|
# Paths
|
|
LOG_DIR: str = "/app/logs_debug"
|
|
|
|
class Config:
|
|
env_file = ".env"
|
|
extra = 'ignore'
|
|
|
|
settings = Settings()
|
|
|
|
except ImportError:
|
|
# Fallback wenn pydantic-settings nicht installiert ist
|
|
class Settings:
|
|
APP_NAME = "Company Explorer"
|
|
VERSION = "0.2.1"
|
|
DEBUG = True
|
|
DATABASE_URL = "sqlite:////app/logs_debug/companies_debug.db"
|
|
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
|
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
|
SERP_API_KEY = os.getenv("SERP_API_KEY")
|
|
LOG_DIR = "/app/logs_debug"
|
|
|
|
settings = Settings()
|
|
|
|
# Ensure Log Dir
|
|
os.makedirs(settings.LOG_DIR, exist_ok=True)
|
|
|
|
# API Key Loading Helper (from file if env missing)
|
|
def load_api_key_from_file(filename: str) -> Optional[str]:
|
|
try:
|
|
if os.path.exists(filename):
|
|
with open(filename, 'r') as f:
|
|
return f.read().strip()
|
|
except Exception as e:
|
|
print(f"Could not load key from {filename}: {e}") # Print because logging might not be ready
|
|
return None
|
|
|
|
# Auto-load keys if not in env
|
|
if not settings.GEMINI_API_KEY:
|
|
settings.GEMINI_API_KEY = load_api_key_from_file("/app/gemini_api_key.txt")
|
|
|
|
if not settings.SERP_API_KEY:
|
|
settings.SERP_API_KEY = load_api_key_from_file("/app/serpapikey.txt") |