Skip to content

Instantly share code, notes, and snippets.

@Tosinkoa
Created September 1, 2022 21:16
Show Gist options
  • Save Tosinkoa/416f6d91bbca47c89994b3ddcc5baf8f to your computer and use it in GitHub Desktop.
Save Tosinkoa/416f6d91bbca47c89994b3ddcc5baf8f to your computer and use it in GitHub Desktop.
```
-- CreateTable
CREATE TABLE "session" (
"sid" VARCHAR NOT NULL,
"sess" JSON NOT NULL,
"expire" TIMESTAMP() NOT NULL,
CONSTRAINT "session_pkey" PRIMARY KEY ("sid")
);
-- CreateTable
CREATE TABLE "slot" (
"id" SERIAL NOT NULL,
"user_id" INTEGER NOT NULL,
"slot_key" VARCHAR(999)[],
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"week_of_year" INTEGER NOT NULL,
"weekly_amount_spent" INTEGER NOT NULL,
"weekly_slot_own" INTEGER NOT NULL,
"year" INTEGER NOT NULL,
CONSTRAINT "slot_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "users" (
"id" SERIAL NOT NULL,
"first_name" VARCHAR(255) NOT NULL,
"last_name" VARCHAR(255) NOT NULL,
"email" CITEXT NOT NULL,
"phone_number" VARCHAR(255),
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"password" VARCHAR(255) NOT NULL,
"profile_image" TEXT NOT NULL,
"profile_image_id" TEXT NOT NULL,
"verified" BOOLEAN NOT NULL DEFAULT false,
"username" CITEXT NOT NULL,
"google_user" BOOLEAN NOT NULL DEFAULT false,
CONSTRAINT "users_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "verifyToken" (
"id" SERIAL NOT NULL,
"token" TEXT NOT NULL,
"user_id" INTEGER NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "verifyToken_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "winner" (
"id" SERIAL NOT NULL,
"user_id" INTEGER NOT NULL,
"profile_image" TEXT NOT NULL,
"profile_image_id" TEXT NOT NULL,
"winner_first_name" VARCHAR(255) NOT NULL,
"winner_last_name" VARCHAR(255) NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"winner_username" VARCHAR(255) NOT NULL,
"amount_won" INTEGER NOT NULL,
CONSTRAINT "winner_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "winnersReview" (
"id" SERIAL NOT NULL,
"review_title" TEXT NOT NULL,
"review_body" TEXT NOT NULL,
"winner_id" INTEGER NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"user_id" INTEGER NOT NULL,
CONSTRAINT "winnersReview_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "winnersReviewImages" (
"id" SERIAL NOT NULL,
"review_image" TEXT[],
"review_image_id" TEXT[],
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"winner_review_id" INTEGER NOT NULL,
CONSTRAINT "winnersReviewImages_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "IDX_session_expire" ON "session"("expire");
-- CreateIndex
CREATE UNIQUE INDEX "slot_id_key" ON "slot"("id");
-- CreateIndex
CREATE UNIQUE INDEX "slot_slot_key_key" ON "slot"("slot_key");
-- CreateIndex
CREATE UNIQUE INDEX "users_id_key" ON "users"("id");
-- CreateIndex
CREATE UNIQUE INDEX "users_email_key" ON "users"("email");
-- CreateIndex
CREATE UNIQUE INDEX "users_phone_number_key" ON "users"("phone_number");
-- CreateIndex
CREATE UNIQUE INDEX "users_username_key" ON "users"("username");
-- CreateIndex
CREATE UNIQUE INDEX "verifyToken_id_key" ON "verifyToken"("id");
-- CreateIndex
CREATE UNIQUE INDEX "verifyToken_token_key" ON "verifyToken"("token");
-- CreateIndex
CREATE UNIQUE INDEX "verifyToken_user_id_key" ON "verifyToken"("user_id");
-- CreateIndex
CREATE UNIQUE INDEX "winner_id_key" ON "winner"("id");
-- CreateIndex
CREATE UNIQUE INDEX "winnersReview_id_key" ON "winnersReview"("id");
-- CreateIndex
CREATE UNIQUE INDEX "winnersReview_winner_id_key" ON "winnersReview"("winner_id");
-- CreateIndex
CREATE UNIQUE INDEX "winnersReviewImages_id_key" ON "winnersReviewImages"("id");
-- CreateIndex
CREATE UNIQUE INDEX "winnersReviewImages_winner_review_id_key" ON "winnersReviewImages"("winner_review_id");
-- AddForeignKey
ALTER TABLE "slot" ADD CONSTRAINT "slot_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "verifyToken" ADD CONSTRAINT "verifyToken_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "winner" ADD CONSTRAINT "winner_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "winnersReview" ADD CONSTRAINT "winnersReview_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "winnersReview" ADD CONSTRAINT "winnersReview_winner_id_fkey" FOREIGN KEY ("winner_id") REFERENCES "winner"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "winnersReviewImages" ADD CONSTRAINT "winnersReviewImages_winner_review_id_fkey" FOREIGN KEY ("winner_review_id") REFERENCES "winnersReview"("id") ON DELETE CASCADE ON UPDATE CASCADE;
```
@DanielFGray
Copy link

DanielFGray commented Sep 1, 2022

create table session (
  sid text primary key not null,
  sess json not null,
  expire timestamptz not null,
);
create index idx_session_expire on session(expire);

create table users (
  id int primary key generated always as identity,
  first_name text not null,
  last_name text not null,
  email citext unique not null,
  phone_number text unique,
  created_at timestamptz not null default now(),
  updated_at timestamptz not null,
  password text not null,
  profile_image text not null,
  profile_image_id text not null,
  verified boolean not null default false,
  username citext unique not null,
  google_user boolean not null default false,
);

create table slot (
  id int primary key generated always as identity,
  user_id integer not null references users on delete cascade on update cascade,
  slot_key text unique,
  created_at timestamptz not null default now(),
  updated_at timestamptz not null,
  week_of_year integer not null,
  weekly_amount_spent integer not null,
  weekly_slot_own integer not null,
  year integer not null,
);

create table verify_token (
  id int primary key generated always as identity,
  token text unique not null,
  user_id integer not null references users on delete cascade on update cascade,
  created_at timestamptz not null default now(),
  updated_at timestamptz not null,
);

create table winner (
  id int primary key generated always as identity,
  user_id integer not null references users on delete cascade on update cascade,
  profile_image text not null,
  profile_image_id text not null,
  winner_first_name text not null,
  winner_last_name text not null,
  created_at timestamptz not null default now(),
  updated_at timestamptz not null,
  winner_username text not null references users(username) on delete cascade on update cascade,
  amount_won integer not null,
);

create table winners_review (
  id int primary key generated always as identity,
  review_title text not null,
  review_body text not null,
  winner_id integer unique not null references winner on delete cascade on update cascade,
  created_at timestamptz not null default now(),
  updated_at timestamptz not null,
  user_id integer not null references users,
);

create table winners_review_images (
  id int primary key generated always as identity,
  review_image text[],
  review_image_id text[],
  created_at timestamptz not null default now(),
  updated_at timestamptz not null,
  winner_review_id integer unique not null references winners_review on delete cascade on update cascade,
);

@Tosinkoa
Copy link
Author

Tosinkoa commented Sep 1, 2022

Thank you so much for helping me out, I value the insights and guidance you provide, thanks again. @DanielFGray and anyone else who help me out with this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment