From 6cf1e3628f24e4b0d1a879eaaf8ddcc5548c1952 Mon Sep 17 00:00:00 2001 From: k00b Date: Mon, 23 Dec 2024 18:26:44 -0600 Subject: [PATCH] reduce territory price with prorated refund for actives --- 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 0c953e719..55ce75f25 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 000000000..e3fbb044d --- /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