Add default ORDER BY id to BaseModel.select() for PostgreSQL compatibility
PostgreSQL does not guarantee row order without ORDER BY, unlike SQLite which implicitly returned rows by rowid. This caused bugs where queries returned results in unexpected order (e.g., get_team_by_owner returning gauntlet team instead of main team). Override select() in BaseModel to add default ordering by id. Explicit .order_by() calls will override this default. Also mark legacy db_engine.py as deprecated.
This commit is contained in:
parent
7574e488d9
commit
985a6ed2b0
@ -178,6 +178,17 @@ class BaseModel(Model):
|
|||||||
class Meta:
|
class Meta:
|
||||||
database = db
|
database = db
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def select(cls, *fields):
|
||||||
|
"""Override select to add default ordering by id for PostgreSQL compatibility.
|
||||||
|
|
||||||
|
PostgreSQL does not guarantee row order without ORDER BY, unlike SQLite
|
||||||
|
which implicitly returned rows by rowid. This ensures consistent ordering
|
||||||
|
across all queries unless explicitly overridden with .order_by().
|
||||||
|
"""
|
||||||
|
query = super().select(*fields)
|
||||||
|
return query.order_by(cls.id)
|
||||||
|
|
||||||
|
|
||||||
class Current(BaseModel):
|
class Current(BaseModel):
|
||||||
season = IntegerField()
|
season = IntegerField()
|
||||||
|
|||||||
@ -1,4 +1,11 @@
|
|||||||
import math
|
import math
|
||||||
|
|
||||||
|
"""
|
||||||
|
DEPRECATED: This file is a legacy implementation from before the deployment
|
||||||
|
of /database/app/. The active codebase is now in /database/app/db_engine.py.
|
||||||
|
This file is kept for reference only and should not be used.
|
||||||
|
"""
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import List
|
from typing import List
|
||||||
import logging
|
import logging
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user