From b808c03d00dc435cae1f5429adbf4762fc11c6d5 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 4 Sep 2023 12:40:50 -0500 Subject: [PATCH] When two plan logs overlap current window Extend the later one --- lib/customer_plan.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/customer_plan.rb b/lib/customer_plan.rb index 3566358..2e9c6f4 100644 --- a/lib/customer_plan.rb +++ b/lib/customer_plan.rb @@ -164,13 +164,14 @@ protected UPDATE plan_log SET date_range=range_merge( date_range, tsrange( - LOCALTIMESTAMP, - GREATEST(upper(date_range), LOCALTIMESTAMP) + '1 month' + LOWER(date_range), + GREATEST(UPPER(date_range), LOCALTIMESTAMP) + '1 month' ) ) WHERE customer_id=$1 AND - date_range && tsrange(LOCALTIMESTAMP, LOCALTIMESTAMP + '1 month') + UPPER(date_range) = (SELECT MAX(UPPER(date_range)) FROM plan_log WHERE + customer_id=$1 AND date_range && tsrange(LOCALTIMESTAMP, LOCALTIMESTAMP + '1 month')) SQL end end -- 2.38.5