File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,16 +25,18 @@ class Settings(BaseSettings):
2525 @field_validator ("database_url" , mode = "before" )
2626 @classmethod
2727 def fix_database_url (cls , v : str ) -> str :
28- """Convert postgres:// to postgresql:// and add sslmode for Railway ."""
28+ """Convert postgres:// to postgresql:// for SQLAlchemy compatibility ."""
2929 if not v :
3030 return v
3131 # Fix postgres:// to postgresql://
3232 if v .startswith ("postgres://" ):
3333 v = v .replace ("postgres://" , "postgresql://" , 1 )
34- # Add sslmode=disable for Railway internal connections if not present
35- if "sslmode=" not in v and "ssl=" not in v :
36- separator = "&" if "?" in v else "?"
37- v = f"{ v } { separator } sslmode=disable"
34+ # Remove sslmode parameter if present (asyncpg doesn't support it in URL)
35+ if "sslmode=" in v :
36+ import re
37+ v = re .sub (r'[?&]sslmode=[^&]*' , '' , v )
38+ # Clean up double && or trailing ?
39+ v = v .replace ('&&' , '&' ).rstrip ('?' ).rstrip ('&' )
3840 return v
3941
4042 # Security
Original file line number Diff line number Diff line change 1717 DATABASE_URL = DATABASE_URL .replace ("sqlite://" , "sqlite+aiosqlite://" , 1 )
1818
1919# Create async engine
20+ # For Railway internal connections, disable SSL
2021engine = create_async_engine (
2122 DATABASE_URL ,
2223 echo = settings .debug ,
2324 future = True ,
25+ connect_args = {"ssl" : False } if "railway.internal" in DATABASE_URL else {},
2426)
2527
2628# Create async session factory
You can’t perform that action at this time.
0 commit comments