Skip to content

Commit 146f0ba

Browse files
committed
feat(db): add is_legacy column to referral table with migration
- Add is_legacy boolean column to referral table (default false) - Migration adds referral_legacy enum value to grant_type - Backfills existing referrals as is_legacy=true (grandfathered users) - Migrates existing credit_ledger referral grants with expiry to referral_legacy type
1 parent ecda87e commit 146f0ba

File tree

4 files changed

+2826
-1
lines changed

4 files changed

+2826
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
ALTER TYPE "public"."grant_type" ADD VALUE 'referral_legacy' BEFORE 'purchase';--> statement-breakpoint
2+
ALTER TABLE "referral" ADD COLUMN "is_legacy" boolean DEFAULT false NOT NULL;--> statement-breakpoint
3+
-- Backfill: Mark all existing referrals as legacy (they were created under the old recurring program)
4+
UPDATE "referral" SET "is_legacy" = true;--> statement-breakpoint
5+
-- Migrate existing referral grants that have an expiry date to referral_legacy type
6+
-- (These are the recurring grants from the old program)
7+
UPDATE "credit_ledger"
8+
SET "type" = 'referral_legacy',
9+
"priority" = 30
10+
WHERE "type" = 'referral'
11+
AND "expires_at" IS NOT NULL;--> statement-breakpoint
12+
-- Update priority for remaining referral grants (one-time grants, if any exist) to new priority
13+
UPDATE "credit_ledger"
14+
SET "priority" = 50
15+
WHERE "type" = 'referral'
16+
AND "expires_at" IS NULL;

0 commit comments

Comments
 (0)