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:
@@ -9,7 +9,7 @@ from alembic import context
|
|||||||
|
|
||||||
# Import your models
|
# Import your models
|
||||||
from app.core.database import Base
|
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
|
from app.core.config import settings
|
||||||
|
|
||||||
# this is the Alembic Config object
|
# this is the Alembic Config object
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ class Settings(BaseSettings):
|
|||||||
|
|
||||||
# Database - Railway provides DATABASE_URL, we convert it for asyncpg
|
# Database - Railway provides DATABASE_URL, we convert it for asyncpg
|
||||||
DATABASE_URL: str = "postgresql+asyncpg://postgres:postgres@localhost:5432/patherly"
|
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")
|
@field_validator("DATABASE_URL", mode="before")
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -21,13 +20,10 @@ class Settings(BaseSettings):
|
|||||||
return v.replace("postgresql://", "postgresql+asyncpg://", 1)
|
return v.replace("postgresql://", "postgresql+asyncpg://", 1)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
@field_validator("DATABASE_URL_SYNC", mode="before")
|
@property
|
||||||
@classmethod
|
def DATABASE_URL_SYNC(self) -> str:
|
||||||
def ensure_sync_url(cls, v: str) -> str:
|
"""Get sync URL by removing asyncpg prefix from DATABASE_URL."""
|
||||||
"""Ensure sync URL uses standard postgresql prefix."""
|
return self.DATABASE_URL.replace("postgresql+asyncpg://", "postgresql://", 1)
|
||||||
if v.startswith("postgresql+asyncpg://"):
|
|
||||||
return v.replace("postgresql+asyncpg://", "postgresql://", 1)
|
|
||||||
return v
|
|
||||||
|
|
||||||
# JWT Settings
|
# JWT Settings
|
||||||
SECRET_KEY: str = "your-secret-key-change-in-production-use-openssl-rand-hex-32"
|
SECRET_KEY: str = "your-secret-key-change-in-production-use-openssl-rand-hex-32"
|
||||||
|
|||||||
Reference in New Issue
Block a user