From 7b0788712da6909253cc8ffb561151984fa3d14c Mon Sep 17 00:00:00 2001 From: Michael Chihlas Date: Sun, 1 Feb 2026 00:53:55 -0500 Subject: [PATCH] Fix database migrations for Railway deployment - Add InviteCode model import to alembic env.py - Derive DATABASE_URL_SYNC from DATABASE_URL as a property so it uses the same Railway-provided connection string Co-Authored-By: Claude Opus 4.5 --- backend/alembic/env.py | 2 +- backend/app/core/config.py | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/backend/alembic/env.py b/backend/alembic/env.py index 62da8f2f..294b3f6e 100644 --- a/backend/alembic/env.py +++ b/backend/alembic/env.py @@ -9,7 +9,7 @@ from alembic import context # Import your models from app.core.database import Base -from app.models import User, Team, Tree, Session, Attachment +from app.models import User, Team, Tree, Session, Attachment, InviteCode from app.core.config import settings # this is the Alembic Config object diff --git a/backend/app/core/config.py b/backend/app/core/config.py index 7be1b8a3..f830f5a9 100644 --- a/backend/app/core/config.py +++ b/backend/app/core/config.py @@ -11,7 +11,6 @@ class Settings(BaseSettings): # Database - Railway provides DATABASE_URL, we convert it for asyncpg DATABASE_URL: str = "postgresql+asyncpg://postgres:postgres@localhost:5432/patherly" - DATABASE_URL_SYNC: str = "postgresql://postgres:postgres@localhost:5432/patherly" @field_validator("DATABASE_URL", mode="before") @classmethod @@ -21,13 +20,10 @@ class Settings(BaseSettings): return v.replace("postgresql://", "postgresql+asyncpg://", 1) return v - @field_validator("DATABASE_URL_SYNC", mode="before") - @classmethod - def ensure_sync_url(cls, v: str) -> str: - """Ensure sync URL uses standard postgresql prefix.""" - if v.startswith("postgresql+asyncpg://"): - return v.replace("postgresql+asyncpg://", "postgresql://", 1) - return v + @property + def DATABASE_URL_SYNC(self) -> str: + """Get sync URL by removing asyncpg prefix from DATABASE_URL.""" + return self.DATABASE_URL.replace("postgresql+asyncpg://", "postgresql://", 1) # JWT Settings SECRET_KEY: str = "your-secret-key-change-in-production-use-openssl-rand-hex-32"