-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reduce territory price with prorated refund for actives
- Loading branch information
Showing
3 changed files
with
23 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
prisma/migrations/20241223204948_territory_refund/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; |