From b4988c12f406e7c02d3e18f45899d930e268b42a Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 3 May 2021 19:08:37 -0500 Subject: [PATCH] Update schema and INSERT to plan_log using new range type plan_log has been updated to use a range type, so our INSERTs need to be updated as well. --- bin/billing_monthly_cronjob | 5 +++-- bin/process_pending_btc_transactions | 4 ++-- config.ru | 2 +- schemas | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bin/billing_monthly_cronjob b/bin/billing_monthly_cronjob index 09a4fc2..fc804a9 100755 --- a/bin/billing_monthly_cronjob +++ b/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 diff --git a/bin/process_pending_btc_transactions b/bin/process_pending_btc_transactions index ae922a8..e51b024 100755 --- a/bin/process_pending_btc_transactions +++ b/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 diff --git a/config.ru b/config.ru index 8f62599..fbb010d 100644 --- a/config.ru +++ b/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 diff --git a/schemas b/schemas index 3e0d7e8..5573078 160000 --- a/schemas +++ b/schemas @@ -1 +1 @@ -Subproject commit 3e0d7e8ae7193f567294036c3235d50ed318b945 +Subproject commit 5573078307ccb4fed4dec6e95a2bf38e91385424 -- 2.45.2