diff --git a/lib/customer_plan.rb b/lib/customer_plan.rb index 35663583d129d3b9e18b554e71beadfdf429f906..2e9c6f48d586914225ce4a7d40e381d6f79a7a70 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