Skip to content

Commit 2c2dbf6

Browse files
authored
Lego/feat/coupons (#317)
## Summary - Define Coupons table with its dependence on Event and with its relation with Tickets - include query/filter on Events for tickets with coupons.
1 parent faae3f0 commit 2c2dbf6

8 files changed

Lines changed: 4327 additions & 3 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
CREATE TABLE IF NOT EXISTS "coupons" (
2+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3+
"name" text NOT NULL,
4+
"coupon" text NOT NULL,
5+
"description" text,
6+
"event_id" uuid NOT NULL,
7+
"is_active" boolean DEFAULT false NOT NULL,
8+
"created_at" timestamp (6) DEFAULT now() NOT NULL,
9+
"updated_at" timestamp (6),
10+
"deleted_at" timestamp (6)
11+
);
12+
--> statement-breakpoint
13+
ALTER TABLE "tickets" ADD COLUMN "coupon_id" uuid;--> statement-breakpoint
14+
DO $$ BEGIN
15+
ALTER TABLE "coupons" ADD CONSTRAINT "coupons_event_id_events_id_fk" FOREIGN KEY ("event_id") REFERENCES "public"."events"("id") ON DELETE no action ON UPDATE no action;
16+
EXCEPTION
17+
WHEN duplicate_object THEN null;
18+
END $$;
19+
--> statement-breakpoint
20+
CREATE INDEX IF NOT EXISTS "coupons_event_id_index" ON "coupons" USING btree ("event_id");--> statement-breakpoint
21+
CREATE INDEX IF NOT EXISTS "coupons_code_index" ON "coupons" USING btree ("coupon");--> statement-breakpoint
22+
CREATE UNIQUE INDEX IF NOT EXISTS "coupons_event_code_unique_index" ON "coupons" USING btree ("event_id","coupon");--> statement-breakpoint
23+
DO $$ BEGIN
24+
ALTER TABLE "tickets" ADD CONSTRAINT "tickets_coupon_id_coupons_id_fk" FOREIGN KEY ("coupon_id") REFERENCES "public"."coupons"("id") ON DELETE no action ON UPDATE no action;
25+
EXCEPTION
26+
WHEN duplicate_object THEN null;
27+
END $$;

0 commit comments

Comments
 (0)