Files
Tools/Dockerfile
T
Nirodan 9db922703b Add versioned DB migration system with automatic backup
migrations.py
- schema_migrations table tracks applied versions (version, description, applied_at)
- MIGRATIONS list is append-only; each entry is (version, description, sql)
- backup() dumps all user-data tables to a timestamped JSON file in backups/
  before any schema changes so data can be recovered if something goes wrong
- run_migrations() is idempotent: already-applied versions are skipped

Integration
- app.py calls _run_startup_migrations() at module load so every restart
  applies any pending migrations (no-op if schema is current)
- setup_routes.py calls run_migrations() after the initial setup form is
  submitted so all tables exist before the user hits the main page for the
  first time
- notes.py and admin.py: removed all per-request CREATE TABLE DDL; schema is
  now owned entirely by the migration system

Docker
- docker-compose.dev.yml: add backups-data volume so JSON backups survive
  container restarts and rebuilds
- Dockerfile: pre-create /app/backend/logs and /app/backend/backups so the
  directories exist even before volumes are mounted

Adding future schema changes
- Append a new (version, description, sql) tuple to MIGRATIONS in migrations.py
- The next restart will detect it as pending, back up first, then apply it

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 10:27:11 +02:00

42 lines
1.2 KiB
Docker

# --- 1. Frontend bauen ---
FROM node:20-bookworm-slim AS frontend-build
WORKDIR /app
COPY frontend ./frontend
WORKDIR /app/frontend
RUN npm install && npm run build
# --- 2. Backend-Stage ---
FROM python:3.13-slim-bullseye
WORKDIR /app
# Backend-Dateien korrekt kopieren
COPY backend/app.py ./backend/app.py
COPY backend/util ./backend/util
COPY backend/auth ./backend/auth
COPY backend/tools ./backend/tools
COPY backend/admin.py ./backend/admin.py
COPY backend/templates ./backend/templates
# Store DB config in a docker-friendly location (/config), override via DB_CONFIG_PATH env if needed
COPY backend/config /config
COPY backend/requirements.txt ./requirements.txt
COPY backend/entrypoint.sh ./entrypoint.sh
# Persistent directories (overridden by Docker volumes at runtime)
RUN mkdir -p /app/backend/logs /app/backend/backups
# Frontend aus Build-Stage übernehmen
COPY --from=frontend-build /app/frontend/dist ./frontend/dist
# Python-Abhängigkeiten installieren
RUN pip install --no-cache-dir -r requirements.txt
# Entrypoint ausführbar machen
RUN chmod +x /app/entrypoint.sh
# Flask starten
WORKDIR /app/backend
ENV PYTHONPATH=/app/backend
ENV DB_CONFIG_PATH=/config/db_config.json
EXPOSE 5000
ENTRYPOINT ["/app/entrypoint.sh"]