@@ -254,6 +254,49 @@ def test_partitioning_time_daily_apply():
254
254
assert table .partitions [6 ].name == "2019_jun_04"
255
255
256
256
257
+ @pytest .mark .postgres_version (lt = 110000 )
258
+ def test_partitioning_time_consistent_daily_apply ():
259
+ """Ensures that automatic daily partition creation is consistent and aligned
260
+ when the partition size spans multiple days (e.g., days > 1)"""
261
+
262
+ model = define_fake_partitioned_model (
263
+ {"timestamp" : models .DateTimeField ()}, {"key" : ["timestamp" ]}
264
+ )
265
+
266
+ schema_editor = connection .schema_editor ()
267
+ schema_editor .create_partitioned_model (model )
268
+
269
+ with freezegun .freeze_time ("2025-06-20" ):
270
+ manager = PostgresPartitioningManager (
271
+ [partition_by_current_time (model , days = 5 , count = 3 )]
272
+ )
273
+ manager .plan ().apply ()
274
+
275
+ table = _get_partitioned_table (model )
276
+ assert len (table .partitions ) == 3
277
+
278
+ # Partitions are aligned based on the fixed anchor (Unix Epoch by default).
279
+ # 2025-06-20 falls within the partition starting at 2025-06-16,
280
+ # since it's the most recent multiple of 5 days since 1970-01-01.
281
+ assert table .partitions [0 ].name == "2025_jun_16"
282
+ assert table .partitions [1 ].name == "2025_jun_21"
283
+ assert table .partitions [2 ].name == "2025_jun_26"
284
+
285
+ # re-running it another day only creates the next one needed.
286
+ with freezegun .freeze_time ("2025-06-22" ):
287
+ manager = PostgresPartitioningManager (
288
+ [partition_by_current_time (model , days = 5 , count = 3 )]
289
+ )
290
+ manager .plan ().apply ()
291
+
292
+ table = _get_partitioned_table (model )
293
+ assert len (table .partitions ) == 4
294
+ assert table .partitions [0 ].name == "2025_jun_16"
295
+ assert table .partitions [1 ].name == "2025_jun_21"
296
+ assert table .partitions [2 ].name == "2025_jun_26"
297
+ assert table .partitions [3 ].name == "2025_jul_01"
298
+
299
+
257
300
@pytest .mark .postgres_version (lt = 110000 )
258
301
def test_partitioning_time_monthly_apply_insert ():
259
302
"""Tests whether automatically created monthly partitions line up
0 commit comments