Update schema and INSERT to plan_log using new range type

Stephen Paul Weber created

plan_log has been updated to use a range type, so our INSERTs need to be
updated as well.

Change summary

bin/billing_monthly_cronjob          | 5 +++--
bin/process_pending_btc_transactions | 4 ++--
config.ru                            | 2 +-
schemas                              | 2 +-
4 files changed, 7 insertions(+), 6 deletions(-)

Detailed changes

bin/billing_monthly_cronjob 🔗

@@ -101,8 +101,9 @@ class Plan
 
 		params = [RENEW_UNTIL, customer_id, expires_at]
 		db.exec_params(<<-SQL, params)
-		  UPDATE plan_log SET expires_at=$1
-		  WHERE customer_id=$2 AND expires_at=$3
+			UPDATE plan_log
+			SET date_range=range_merge(date_range, tsrange('now', $1))
+			WHERE customer_id=$2 AND date_range -|- tsrange($3, $3, '[]')
 		SQL
 	end
 end

bin/process_pending_btc_transactions 🔗

@@ -122,9 +122,9 @@ class Plan
 		params = [@customer.id, name, start, expire]
 		DB.exec_params(<<-SQL, params)
 			INSERT INTO plan_log
-				(customer_id, plan_name, starts_at, expires_at)
+				(customer_id, plan_name, date_range)
 			VALUES
-				($1, $2, $3, $4)
+				($1, $2, tsrange($3, $4))
 		SQL
 	end
 

config.ru 🔗

@@ -63,7 +63,7 @@ class Plan
 
 	def activate(customer_id, months)
 		DB.exec_params(
-			"INSERT INTO plan_log VALUES ($1, $2, $3, $4)",
+			"INSERT INTO plan_log VALUES ($1, $2, tsrange($3, $4))",
 			[customer_id, @plan[:name], Time.now, Date.today >> months]
 		)
 		true

schemas 🔗

@@ -1 +1 @@
-Subproject commit 3e0d7e8ae7193f567294036c3235d50ed318b945
+Subproject commit 5573078307ccb4fed4dec6e95a2bf38e91385424