mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-22 19:15:08 +03:00
Implement real, working microservices architecture
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
# Migration Runner Dockerfile
|
||||
FROM backend/base:latest
|
||||
|
||||
# Copy migration files
|
||||
COPY backend/alembic /app/backend/alembic/
|
||||
COPY backend/migration.py /app/backend/migration.py
|
||||
|
||||
# Copy migration runner
|
||||
COPY backend/services/migration_runner/main.py /app/backend/services/migration_runner/main.py
|
||||
|
||||
# Set service name for entrypoint
|
||||
ENV SERVICE_NAME=migration_runner
|
||||
|
||||
# Override entrypoint to run migrations
|
||||
ENTRYPOINT ["python", "-m", "backend.services.migration_runner.main"]
|
||||
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Migration runner service - executes database migrations and exits.
|
||||
This service runs Alembic migrations against PostgreSQL and terminates.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from alembic import command
|
||||
from alembic.config import Config
|
||||
|
||||
def run_migrations():
|
||||
"""Run Alembic migrations."""
|
||||
print("Starting database migrations...")
|
||||
|
||||
# Change to backend directory to run migrations
|
||||
backend_dir = Path(__file__).parent.parent.parent
|
||||
os.chdir(backend_dir)
|
||||
|
||||
# Ensure shared models are imported for alembic
|
||||
import backend.shared.models
|
||||
|
||||
# Set DATABASE_URL from environment if not set
|
||||
db_url = os.getenv("DATABASE_URL")
|
||||
if not db_url:
|
||||
print("ERROR: DATABASE_URL environment variable not set")
|
||||
sys.exit(1)
|
||||
|
||||
# Export DATABASE_URL for alembic
|
||||
os.environ["DATABASE_URL"] = db_url
|
||||
|
||||
try:
|
||||
# Use the robust migration system from migration.py
|
||||
# This handles all edge cases and recovery scenarios automatically
|
||||
print("Starting database migrations...")
|
||||
|
||||
# Import and run the migration function
|
||||
from backend.migration import run_migrations
|
||||
run_migrations()
|
||||
|
||||
print("Database migrations completed successfully!")
|
||||
|
||||
except Exception as e:
|
||||
print(f"ERROR: Failed to run migrations: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_migrations()
|
||||
Reference in New Issue
Block a user