-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0000_mute_black_bird.sql
More file actions
37 lines (37 loc) · 1.72 KB
/
0000_mute_black_bird.sql
File metadata and controls
37 lines (37 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
CREATE TYPE "public"."eventState" AS ENUM('draft', 'published');--> statement-breakpoint
CREATE TYPE "public"."roles" AS ENUM('user', 'committee');--> statement-breakpoint
CREATE TABLE "events" (
"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "events_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"organizer" text NOT NULL,
"state" "eventState" DEFAULT 'draft',
"title" text NOT NULL,
"capacity" integer,
"date" timestamp NOT NULL,
"about_markdown" text,
"location_name" text,
"location_map_url" text,
"form" json,
"created_at" timestamp DEFAULT now(),
"updated_at" timestamp DEFAULT now()
);
--> statement-breakpoint
CREATE TABLE "registrations" (
"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "registrations_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"user_id" text NOT NULL,
"event_id" integer NOT NULL,
"form_data" json,
"created_at" timestamp DEFAULT now()
);
--> statement-breakpoint
CREATE TABLE "users" (
"id" text PRIMARY KEY NOT NULL,
"email" text NOT NULL,
"first_name" text NOT NULL,
"last_name" text NOT NULL,
"role" "roles" DEFAULT 'user',
CONSTRAINT "users_email_unique" UNIQUE("email")
);
--> statement-breakpoint
ALTER TABLE "registrations" ADD CONSTRAINT "registrations_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "registrations" ADD CONSTRAINT "registrations_event_id_events_id_fk" FOREIGN KEY ("event_id") REFERENCES "public"."events"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE UNIQUE INDEX "unique_user_event" ON "registrations" USING btree ("user_id","event_id");