Skip to content

Commit 3b6aa0b

Browse files
committed
fix db init and upgrade pydantic config
add checkfirst=True to create_all so it does not fail when db is created use ConfigDict and not depricated Config class Signed-off-by: Robert Marklund <robbelibobban@gmail.com>
1 parent 8143bb1 commit 3b6aa0b

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

app/core/config.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
"""Configuration settings for Ollama Proxy Server."""
22

3+
from pydantic import ConfigDict
34
from pydantic_settings import BaseSettings
45

56

67
class Settings(BaseSettings):
78
"""Bootstrap settings for the application."""
89

10+
model_config = ConfigDict(
11+
env_file=".env",
12+
case_sensitive=True,
13+
# extra="ignore",
14+
extra="forbid",
15+
)
16+
917
# --- Bootstrap Settings ---
1018
# These are the only settings read from the .env file.
1119
DATABASE_URL: str = "sqlite+aiosqlite:///./ollama_proxy.db"
@@ -20,14 +28,6 @@ class Settings(BaseSettings):
2028
LOG_LEVEL: str = "info"
2129

2230

23-
class Config: # pylint: disable=too-few-public-methods
24-
"""Pydantic configuration."""
25-
26-
env_file = ".env"
27-
case_sensitive = True
28-
extra = "ignore" # <-- THIS IS THE FIX
29-
30-
3131
# This `settings` object is now only used for bootstrapping.
3232
# The rest of the app will use settings loaded from the DB.
3333
settings = Settings()

app/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async def init_db():
7070

7171
# Then create any missing tables
7272
async with engine.begin() as conn:
73-
await conn.run_sync(Base.metadata.create_all)
73+
await conn.run_sync(Base.metadata.create_all, checkfirst=True)
7474

7575
_db_initialized = True
7676
logger.info("Database schema is ready.")

app/schema/apikey.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import datetime
44

5-
from pydantic import BaseModel
5+
from pydantic import BaseModel, ConfigDict
66

77

88
class APIKeyBase(BaseModel):
@@ -25,7 +25,4 @@ class APIKey(APIKeyBase):
2525
is_revoked: bool
2626
created_at: datetime.datetime
2727

28-
class Config: # pylint: disable=too-few-public-methods
29-
"""Pydantic configuration."""
30-
31-
from_attributes = True
28+
model_config = ConfigDict(extra="forbid")

app/schema/user.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""User schemas for Ollama Proxy Server."""
22

3-
from pydantic import BaseModel
3+
from pydantic import BaseModel, ConfigDict
44

55

66
class UserBase(BaseModel):
@@ -22,7 +22,4 @@ class User(UserBase):
2222
is_active: bool
2323
is_admin: bool
2424

25-
class Config: # pylint: disable=too-few-public-methods
26-
"""Pydantic configuration."""
27-
28-
from_attributes = True
25+
model_config = ConfigDict(extra="forbid")

0 commit comments

Comments
 (0)