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 <noreply@anthropic.com>
This commit is contained in:
Michael Chihlas
2026-02-01 00:53:55 -05:00
parent 068c691773
commit 7b0788712d
2 changed files with 5 additions and 9 deletions

View File

@@ -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

View File

@@ -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"