Fix critical startup issue - remove email-validator dependency
- Replace EmailStr with custom email validation using regex
- Remove pydantic[email] dependency to prevent import errors
- Update config to use dynamic database path with proper directory creation
- Improve database session configuration with connection pooling
- Fix application startup failures caused by missing email-validator package
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
b9798f0eaf
commit
e09f7ca405
@ -10,8 +10,17 @@ class Settings(BaseSettings):
|
|||||||
ALGORITHM: str = "HS256"
|
ALGORITHM: str = "HS256"
|
||||||
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8
|
||||||
|
|
||||||
DB_DIR: Path = Path("/app/storage/db")
|
# Use relative path from current working directory or absolute path if specified
|
||||||
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
DB_DIR: Path = Path(os.getenv("DB_DIR", "/app/storage/db"))
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
# Ensure the database directory exists
|
||||||
|
self.DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def SQLALCHEMY_DATABASE_URL(self) -> str:
|
||||||
|
return f"sqlite:///{self.DB_DIR}/db.sqlite"
|
||||||
|
|
||||||
PAYMENT_PROVIDER_API_URL: str = os.getenv("PAYMENT_PROVIDER_API_URL", "")
|
PAYMENT_PROVIDER_API_URL: str = os.getenv("PAYMENT_PROVIDER_API_URL", "")
|
||||||
PAYMENT_PROVIDER_API_KEY: str = os.getenv("PAYMENT_PROVIDER_API_KEY", "")
|
PAYMENT_PROVIDER_API_KEY: str = os.getenv("PAYMENT_PROVIDER_API_KEY", "")
|
||||||
|
@ -1,16 +1,13 @@
|
|||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
|
from app.core.config import settings
|
||||||
DB_DIR = Path("/app/storage/db")
|
|
||||||
DB_DIR.mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
|
|
||||||
|
|
||||||
engine = create_engine(
|
engine = create_engine(
|
||||||
SQLALCHEMY_DATABASE_URL,
|
settings.SQLALCHEMY_DATABASE_URL,
|
||||||
connect_args={"check_same_thread": False}
|
connect_args={"check_same_thread": False},
|
||||||
|
pool_pre_ping=True,
|
||||||
|
pool_recycle=300
|
||||||
)
|
)
|
||||||
|
|
||||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||||
|
@ -1,17 +1,27 @@
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
from pydantic import BaseModel, EmailStr
|
from pydantic import BaseModel, field_validator
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
class UserBase(BaseModel):
|
class UserBase(BaseModel):
|
||||||
email: Optional[EmailStr] = None
|
email: Optional[str] = None
|
||||||
username: Optional[str] = None
|
username: Optional[str] = None
|
||||||
is_active: Optional[bool] = True
|
is_active: Optional[bool] = True
|
||||||
is_verified: Optional[bool] = False
|
is_verified: Optional[bool] = False
|
||||||
|
|
||||||
|
@field_validator('email')
|
||||||
|
@classmethod
|
||||||
|
def validate_email(cls, v):
|
||||||
|
if v is not None:
|
||||||
|
email_pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
|
||||||
|
if not re.match(email_pattern, v):
|
||||||
|
raise ValueError('Invalid email format')
|
||||||
|
return v
|
||||||
|
|
||||||
|
|
||||||
class UserCreate(UserBase):
|
class UserCreate(UserBase):
|
||||||
email: EmailStr
|
email: str
|
||||||
username: str
|
username: str
|
||||||
password: str
|
password: str
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user