aleph.toolkit.partitions module¶
Helpers for monthly RANGE-partitioned tables on a TIMESTAMPTZ column.
Used by: * the alembic migration that creates crn_metrics / ccn_metrics * the metrics_partition cron job that maintains them (create next month,
drop past-cutoff)
Keeping the naming and bounds logic in one place means migration-time partitions and cron-created partitions follow identical conventions.
- aleph.toolkit.partitions.add_months(d: datetime, months: int) datetime[source]¶
Shift d by N calendar months (positive or negative). Snaps to the first day of the resulting month.
- aleph.toolkit.partitions.month_floor(d: datetime) datetime[source]¶
First instant of d’s month, UTC.
- aleph.toolkit.partitions.monthly_bounds(start: datetime, end_exclusive: datetime) List[Tuple[datetime, datetime]][source]¶
List of [lower, upper) month-aligned ranges from start to end_exclusive. Both arguments should already be at month boundaries.