Backend: - Add PostgreSQL service to docker-compose with health checks - Add SQLAlchemy async models for all entities (Agency, User, Campaign, Proof, ProofVersion, FlaggedItem, ResolvedItem, ErrorItem) - Add Alembic migration framework with initial schema migration - Add repository layer for CRUD operations - Add REST API endpoints for campaigns, proofs, and audit items - Add file storage service for proof uploads - Update WebSocket handler to optionally persist analysis results Frontend: - Add apiService.ts for REST API communication - Update geminiService.ts to support database persistence options Deployment: - Update deploy.sh to handle database migrations (6-step process) - Update Dockerfile to include alembic configuration - Add PostgreSQL environment variables to .env templates 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
74 lines
1.8 KiB
Python
74 lines
1.8 KiB
Python
import asyncio
|
|
from logging.config import fileConfig
|
|
|
|
from sqlalchemy import pool
|
|
from sqlalchemy.engine import Connection
|
|
from sqlalchemy.ext.asyncio import async_engine_from_config
|
|
|
|
from alembic import context
|
|
|
|
from app.config import settings
|
|
from app.models.database import Base
|
|
from app.models.models import (
|
|
Agency, User, Campaign, Proof, ProofVersion,
|
|
FlaggedItem, ResolvedItem, ErrorItem, DropdownOption
|
|
)
|
|
|
|
config = context.config
|
|
|
|
if config.config_file_name is not None:
|
|
fileConfig(config.config_file_name)
|
|
|
|
target_metadata = Base.metadata
|
|
|
|
|
|
def get_url():
|
|
return settings.DATABASE_URL
|
|
|
|
|
|
def run_migrations_offline() -> None:
|
|
"""Run migrations in 'offline' mode."""
|
|
url = get_url()
|
|
context.configure(
|
|
url=url,
|
|
target_metadata=target_metadata,
|
|
literal_binds=True,
|
|
dialect_opts={"paramstyle": "named"},
|
|
)
|
|
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
|
|
def do_run_migrations(connection: Connection) -> None:
|
|
context.configure(connection=connection, target_metadata=target_metadata)
|
|
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
|
|
async def run_async_migrations() -> None:
|
|
"""Run migrations in 'online' mode with async engine."""
|
|
configuration = config.get_section(config.config_ini_section)
|
|
configuration["sqlalchemy.url"] = get_url()
|
|
connectable = async_engine_from_config(
|
|
configuration,
|
|
prefix="sqlalchemy.",
|
|
poolclass=pool.NullPool,
|
|
)
|
|
|
|
async with connectable.connect() as connection:
|
|
await connection.run_sync(do_run_migrations)
|
|
|
|
await connectable.dispose()
|
|
|
|
|
|
def run_migrations_online() -> None:
|
|
"""Run migrations in 'online' mode."""
|
|
asyncio.run(run_async_migrations())
|
|
|
|
|
|
if context.is_offline_mode():
|
|
run_migrations_offline()
|
|
else:
|
|
run_migrations_online()
|