feat: promo code

This commit is contained in:
Face 2025-05-26 17:20:53 +03:00
parent 0ddb431536
commit bcac2584ed
12 changed files with 1908 additions and 54 deletions

View file

@ -0,0 +1,39 @@
CREATE TABLE IF NOT EXISTS "promo_code" (
"id" serial PRIMARY KEY NOT NULL,
"code" varchar(50) NOT NULL,
"description" text,
"reward_amount" numeric(20, 8) NOT NULL,
"max_uses" integer,
"is_active" boolean DEFAULT true NOT NULL,
"expires_at" timestamp with time zone,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"created_by" integer,
CONSTRAINT "promo_code_code_unique" UNIQUE("code")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "promo_code_redemption" (
"id" serial PRIMARY KEY NOT NULL,
"user_id" integer NOT NULL,
"promo_code_id" integer NOT NULL,
"reward_amount" numeric(20, 8) NOT NULL,
"redeemed_at" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "promo_code_redemption_user_id_promo_code_id_unique" UNIQUE("user_id","promo_code_id")
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "promo_code" ADD CONSTRAINT "promo_code_created_by_user_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "promo_code_redemption" ADD CONSTRAINT "promo_code_redemption_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "promo_code_redemption" ADD CONSTRAINT "promo_code_redemption_promo_code_id_promo_code_id_fk" FOREIGN KEY ("promo_code_id") REFERENCES "public"."promo_code"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

File diff suppressed because it is too large Load diff

View file

@ -50,6 +50,13 @@
"when": 1748189449547,
"tag": "0006_happy_katie_power",
"breakpoints": true
},
{
"idx": 7,
"version": "7",
"when": 1748262487765,
"tag": "0007_funny_hemingway",
"breakpoints": true
}
]
}