Configure SQL Alchemy ORM to properly use year-based partitioned Notification tables #131
Labels
Dev Reviewed
Reviewed by Tech Lead
Notify
Board trigger
PM Reviewed
Reviewed by Product Manager
QA Reviewed
Reviewed by Quality Assurance
QA
Issue requires QA collaboration
User Story - Business Need
During the implementation of #95, we identified that SQLAlchemy ORM does not natively support querying year-based partitioned tables directly through ORM objects. This limitation arises because SQLAlchemy does not create distinct ORM objects for partitioned tables—only the parent table is represented.
While PostgreSQL automatically routes queries to the appropriate partitioned table when the filter condition aligns with the partitioning key (
created_at
), SQLAlchemy ORM lacks a simple, intuitive way to target specific year-based partitions when needed. For instance:Queries like
Notification.where(Notification.created_at >= '2024-01-01', Notification.created_at < '2025-01-01')
work and query properly on the partitioned tables because PostgreSQL optimizes them at execution.However, for more granular control (e.g., explicitly querying notifications_2024), SQLAlchemy does not offer direct support.
User Story(ies)
As a developer working with SQLAlchemy queries on the
Notification
table,I want a straightforward and "graceful" way to query year-based partitioned
Notification
tables,So that the application can efficiently and correctly target specific partitions and maintain readability and maintainability in the codebase.
Additional Info and Resources
created_at >= DB_PARTITION_DATE
(@k-macmillan's suggestion) would allow developers to explicitly query a specific partition table by year while still using SQLAlchemy. Postgres docs mention it is how you prune unwanted partitions.GET
orPOST
db/test/
can be updated to test different queries.Acceptance Criteria
dao method
is implemented that makes use of the partition tablesQA Considerations
notifications_2024
).Potential Dependencies
The text was updated successfully, but these errors were encountered: