Migrate to PostgreSQL + add FastAPI webapp for Coolify deploy

Backend migration:
- Replace pyodbc/SQL Server with psycopg2/PostgreSQL throughout
- Rewrite Database class with portable SQL: SERIAL, ON CONFLICT, NOW()
- Lowercase table names (rip_help_files, rip_help_sections) - Postgres convention
- libpq connection string format in HELP_DB_CONN

Webapp (webapp/):
- FastAPI app: GET /, GET /images/<f>, GET /home-image, GET /api/sections,
  POST /api/keywords/<code>, GET /healthz
- Jinja2 template extracted from generate_html.py with HTTP image URLs
- Direct keyword save to DB (no JSON download detour)
- Same prefix scoping as CLI tools (?prefix=RIP)

Deployment:
- Dockerfile (python:3.12-slim + uvicorn)
- docker-compose.yml for local dev
- requirements-webapp.txt (minimal, no Windows-only deps)
- .dockerignore excludes pipeline scripts and BAT files
- README updated with webapp section and Coolify deploy guide

Also: switch AI model to claude-haiku-4-5 (~3x cheaper, same quality for this task)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-20 17:00:44 +03:00
parent 711053b8bd
commit 9613420d1d
13 changed files with 1034 additions and 167 deletions

View File

@@ -2,7 +2,7 @@
save_keywords.py
================
Чете keywords_changes.json (генериран от браузъра)
и записва промените в SQL Server.
и записва промените в PostgreSQL.
Стартирай с: python save_keywords.py
"""
@@ -12,16 +12,13 @@ from pathlib import Path
from datetime import datetime
try:
import pyodbc
import psycopg2
except ImportError:
sys.exit("Инсталирай pyodbc: pip install pyodbc")
sys.exit("Инсталирай psycopg2: pip install psycopg2-binary")
CONN_STR = os.getenv(
"HELP_DB_CONN",
"DRIVER={ODBC Driver 18 for SQL Server};"
"TrustServerCertificate=yes;"
"SERVER=94.26.63.238,13151;DATABASE=blondina;"
"UID=blondina_login;PWD=blondina_parola_123"
"host=192.168.88.18 port=5432 dbname=rip_help_system user=sa password=Parola~12345!!!"
)
CHANGES_FILE = Path(__file__).parent / "keywords_changes.json"
@@ -38,7 +35,7 @@ def main():
return
print(f"Записвам {len(changes)} промени в БД...")
conn = pyodbc.connect(CONN_STR, autocommit=False)
conn = psycopg2.connect(CONN_STR)
cur = conn.cursor()
ok, err = 0, 0
@@ -49,8 +46,8 @@ def main():
continue
try:
cur.execute(
"UPDATE RIP_help_sections SET keywords=?, updated_at=GETDATE() WHERE code=?",
keywords, code
"UPDATE rip_help_sections SET keywords=%s, updated_at=NOW() WHERE code=%s",
(keywords, code)
)
if cur.rowcount > 0:
ok += 1