diff --git a/app/models.py b/app/models.py index 750ecb7d..633ee704 100644 --- a/app/models.py +++ b/app/models.py @@ -758,5 +758,7 @@ class Statistic(SQLModel, table=True): id: int | None = Field(default=None, primary_key=True) type: StatisticType = Field(sa_column=Column(Enum(StatisticType, name="statistic_type"))) data: dict[str, Any] = Field(default={}, sa_column=Column(JSON)) - created_at: datetime | None = Field(sa_column=Column(DateTime(timezone=True), nullable=False, onupdate=func.now())) + created_at: datetime | None = Field( + sa_column=Column(DateTime(timezone=True), nullable=False, default=datetime.utcnow(), server_default=func.now()) + ) lender_id: int | None = Field(foreign_key="lender.id", nullable=True) diff --git a/app/utils/statistics.py b/app/utils/statistics.py index 571662d4..c3923541 100644 --- a/app/utils/statistics.py +++ b/app/utils/statistics.py @@ -70,7 +70,6 @@ def update_statistics(db_provider: Callable[[], Generator[Session, None, None]] statistic_kpi_data = Statistic( type=StatisticType.APPLICATION_KPIS, data=statistic_kpis, - created_at=datetime.now(), ) session.add(statistic_kpi_data) @@ -103,7 +102,6 @@ def update_statistics(db_provider: Callable[[], Generator[Session, None, None]] statistic_opt_data = Statistic( type=StatisticType.MSME_OPT_IN_STATISTICS, data=statistics_msme_opt_in, - created_at=datetime.now(), ) session.add(statistic_opt_data) @@ -133,7 +131,6 @@ def update_statistics(db_provider: Callable[[], Generator[Session, None, None]] type=StatisticType.APPLICATION_KPIS, data=statistic_kpis, lender_id=lender_id, - created_at=datetime.now(), ) session.add(statistic_kpi_data) diff --git a/migrations/versions/385fb9a01efc_add_single_column_indexes_for_slow_.py b/migrations/versions/385fb9a01efc_add_single_column_indexes_for_slow_.py index 85801898..18e742e1 100644 --- a/migrations/versions/385fb9a01efc_add_single_column_indexes_for_slow_.py +++ b/migrations/versions/385fb9a01efc_add_single_column_indexes_for_slow_.py @@ -6,6 +6,7 @@ """ from alembic import op +from sqlalchemy import text # revision identifiers, used by Alembic. revision = "385fb9a01efc" @@ -17,7 +18,7 @@ def index_exists(name): connection = op.get_bind() result = connection.execute( - "SELECT exists(SELECT 1 from pg_indexes where indexname = '{}') as ix_exists;".format(name) + text("SELECT exists(SELECT 1 from pg_indexes where indexname = :indexname) as ix_exists"), {"indexname": name} ).first() return result.ix_exists