Skip to content

Commit

Permalink
feat: simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
nehalist committed Jan 23, 2024
1 parent 48f9790 commit eb2691c
Show file tree
Hide file tree
Showing 38 changed files with 538 additions and 6,054 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
DO $$ BEGIN
CREATE TYPE "game" AS ENUM('custom', 'foosball', 'badminton', 'chess', 'pool', 'table-tennis', 'sixty-six');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "leagueStatus" AS ENUM('active', 'finished');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "membershipRole" AS ENUM('member', 'admin');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "ratingSystem" AS ENUM('unknown', 'elo', 'glicko2');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "role" AS ENUM('user', 'admin');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "account" (
"userId" text,
"type" text NOT NULL,
Expand All @@ -19,14 +43,29 @@ CREATE TABLE IF NOT EXISTS "account" (
CONSTRAINT "account_provider_providerAccountId_pk" PRIMARY KEY("provider","providerAccountId")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "feedback" (
"id" text PRIMARY KEY NOT NULL,
"userId" text NOT NULL,
"description" text,
"createdAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "league" (
"id" text PRIMARY KEY NOT NULL,
"name" text NOT NULL,
"image" text,
"description" text,
"game" "game" DEFAULT 'custom' NOT NULL,
"maxScorePerMatch" integer DEFAULT 0 NOT NULL,
"allowDraws" boolean DEFAULT true NOT NULL,
"defaultRating" integer DEFAULT 1000 NOT NULL,
"ratingSystem" "ratingSystem" DEFAULT 'unknown' NOT NULL,
"ratingSystemParameters" json DEFAULT '{}'::json NOT NULL,
"leagueStatus" "leagueStatus" DEFAULT 'active',
"inviteCode" text DEFAULT substr(md5(random()::text), 0, 25) NOT NULL,
"ownerId" text NOT NULL,
"createdAt" timestamp DEFAULT now() NOT NULL
"createdAt" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "league_inviteCode_unique" UNIQUE("inviteCode")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "matches" (
Expand All @@ -35,27 +74,27 @@ CREATE TABLE IF NOT EXISTS "matches" (
"createdAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "memberships" (
"leagueId" text NOT NULL,
"userId" text NOT NULL,
"role" "membershipRole" DEFAULT 'member' NOT NULL,
"createdAt" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "memberships_userId_leagueId_pk" PRIMARY KEY("userId","leagueId")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "session" (
"sessionToken" text PRIMARY KEY NOT NULL,
"userId" text,
"expires" timestamp NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "team_member" (
"id" text PRIMARY KEY NOT NULL,
"name" text NOT NULL,
"image" text,
"teamId" text NOT NULL,
"userId" text NOT NULL,
"createdAt" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "team_member_teamId_userId_unique" UNIQUE("teamId","userId")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "team" (
"id" text PRIMARY KEY NOT NULL,
"name" text NOT NULL,
"image" text,
"leagueId" text NOT NULL,
"teamsize" integer DEFAULT 1 NOT NULL,
"userId" text NOT NULL,
"createdAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
Expand All @@ -65,9 +104,11 @@ CREATE TABLE IF NOT EXISTS "user" (
"firstName" text,
"lastName" text,
"email" text NOT NULL,
"role" "role" DEFAULT 'user' NOT NULL,
"emailVerified" timestamp,
"image" text,
"selectedLeagueId" text
"selectedLeagueId" text,
"createdAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "verificationToken" (
Expand All @@ -84,7 +125,13 @@ EXCEPTION
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "league" ADD CONSTRAINT "league_ownerId_user_id_fk" FOREIGN KEY ("ownerId") REFERENCES "user"("id") ON DELETE no action ON UPDATE no action;
ALTER TABLE "feedback" ADD CONSTRAINT "feedback_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "league" ADD CONSTRAINT "league_ownerId_user_id_fk" FOREIGN KEY ("ownerId") REFERENCES "user"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
Expand All @@ -96,19 +143,19 @@ EXCEPTION
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "session" ADD CONSTRAINT "session_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE cascade ON UPDATE no action;
ALTER TABLE "memberships" ADD CONSTRAINT "memberships_leagueId_league_id_fk" FOREIGN KEY ("leagueId") REFERENCES "league"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "team_member" ADD CONSTRAINT "team_member_teamId_team_id_fk" FOREIGN KEY ("teamId") REFERENCES "team"("id") ON DELETE cascade ON UPDATE no action;
ALTER TABLE "memberships" ADD CONSTRAINT "memberships_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "team_member" ADD CONSTRAINT "team_member_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE cascade ON UPDATE no action;
ALTER TABLE "session" ADD CONSTRAINT "session_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
Expand All @@ -118,3 +165,9 @@ DO $$ BEGIN
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "team" ADD CONSTRAINT "team_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
17 changes: 0 additions & 17 deletions drizzle/0001_common_roxanne_simpson.sql

This file was deleted.

1 change: 0 additions & 1 deletion drizzle/0002_same_lily_hollister.sql

This file was deleted.

1 change: 0 additions & 1 deletion drizzle/0003_public_randall.sql

This file was deleted.

1 change: 0 additions & 1 deletion drizzle/0004_goofy_junta.sql

This file was deleted.

5 changes: 0 additions & 5 deletions drizzle/0005_steady_boomerang.sql

This file was deleted.

7 changes: 0 additions & 7 deletions drizzle/0006_workable_joshua_kane.sql

This file was deleted.

1 change: 0 additions & 1 deletion drizzle/0007_brave_invaders.sql

This file was deleted.

15 changes: 0 additions & 15 deletions drizzle/0008_purple_darkstar.sql

This file was deleted.

1 change: 0 additions & 1 deletion drizzle/0009_far_blob.sql

This file was deleted.

Loading

0 comments on commit eb2691c

Please sign in to comment.