From 2fc529419e59a9df8e763f2d06eed742c254dcbb Mon Sep 17 00:00:00 2001 From: Keyan <34140557+huumn@users.noreply.github.com> Date: Mon, 23 Dec 2024 18:50:35 -0600 Subject: [PATCH] reduce territory price with prorated refund for actives (#1761) --- components/territory-form.js | 6 +++--- lib/constants.js | 8 ++++---- .../migration.sql | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 prisma/migrations/20241223204948_territory_refund/migration.sql diff --git a/components/territory-form.js b/components/territory-form.js index 0c953e71..55ce75f2 100644 --- a/components/territory-form.js +++ b/components/territory-form.js @@ -197,7 +197,7 @@ export default function TerritoryForm ({ sub }) { > ({ monthly: { - term: '+ 100k', + term: '+ 50k', label: `${labelPrefix} month`, op: '+', modifier: cost => cost + TERRITORY_COST_MONTHLY }, yearly: { - term: '+ 1m', + term: '+ 500k', label: `${labelPrefix} year`, op: '+', modifier: cost => cost + TERRITORY_COST_YEARLY diff --git a/prisma/migrations/20241223204948_territory_refund/migration.sql b/prisma/migrations/20241223204948_territory_refund/migration.sql new file mode 100644 index 00000000..e3fbb044 --- /dev/null +++ b/prisma/migrations/20241223204948_territory_refund/migration.sql @@ -0,0 +1,16 @@ +-- refund users who have active territories and paid the old, higher price +-- for the rest of their billing period once the switchover is complete + +WITH active_territories AS ( + SELECT *, + "billingCost" * + EXTRACT(epoch FROM "billPaidUntil" - now()) / EXTRACT(epoch FROM "billPaidUntil" - "billedLastAt") * + 0.5 AS refund_sats + FROM "Sub" + WHERE "status" = 'ACTIVE' + AND "billingType" IN ('MONTHLY', 'YEARLY') +) +UPDATE users +SET msats = msats + refund_sats*1000 +FROM active_territories +WHERE users.id = active_territories."userId"; \ No newline at end of file