~singpolyma/sgx-jmp

b808c03d00dc435cae1f5429adbf4762fc11c6d5 — Stephen Paul Weber 5 months ago bb83156
When two plan logs overlap current window

Extend the later one
1 files changed, 4 insertions(+), 3 deletions(-)

M lib/customer_plan.rb
M lib/customer_plan.rb => lib/customer_plan.rb +4 -3
@@ 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