Use migrations to introduce new tables for bookings

This commit is contained in:
nicolas 2021-06-06 01:31:03 +02:00
parent a5e750eae7
commit bc7ac136cc
4 changed files with 140 additions and 0 deletions

View file

@ -0,0 +1,50 @@
-- CreateTable
CREATE TABLE "EventType" (
"id" SERIAL NOT NULL,
"title" TEXT NOT NULL,
"slug" TEXT NOT NULL,
"description" TEXT,
"locations" JSONB,
"length" INTEGER NOT NULL,
"hidden" BOOLEAN NOT NULL DEFAULT false,
"userId" INTEGER,
PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Credential" (
"id" SERIAL NOT NULL,
"type" TEXT NOT NULL,
"key" JSONB NOT NULL,
"userId" INTEGER,
PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "users" (
"id" SERIAL NOT NULL,
"username" TEXT,
"name" TEXT,
"email" TEXT,
"password" TEXT,
"bio" TEXT,
"avatar" TEXT,
"timeZone" TEXT NOT NULL DEFAULT E'Europe/London',
"weekStart" TEXT DEFAULT E'Sunday',
"startTime" INTEGER NOT NULL DEFAULT 0,
"endTime" INTEGER NOT NULL DEFAULT 1440,
"created" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "users.email_unique" ON "users"("email");
-- AddForeignKey
ALTER TABLE "EventType" ADD FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Credential" ADD FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;

View file

@ -0,0 +1,48 @@
-- CreateTable
CREATE TABLE "BookingReference" (
"id" SERIAL NOT NULL,
"type" TEXT NOT NULL,
"uid" TEXT NOT NULL,
"bookingId" INTEGER,
PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Attendee" (
"id" SERIAL NOT NULL,
"email" TEXT NOT NULL,
"name" TEXT NOT NULL,
"timeZone" TEXT NOT NULL,
"bookingId" INTEGER,
PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Booking" (
"id" SERIAL NOT NULL,
"uid" TEXT NOT NULL,
"userId" INTEGER,
"eventTypeId" INTEGER,
"title" TEXT NOT NULL,
"description" TEXT,
"startTime" TIMESTAMP(3) NOT NULL,
"endTime" TIMESTAMP(3) NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3),
PRIMARY KEY ("id")
);
-- AddForeignKey
ALTER TABLE "Attendee" ADD FOREIGN KEY ("bookingId") REFERENCES "Booking"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Booking" ADD FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Booking" ADD FOREIGN KEY ("eventTypeId") REFERENCES "EventType"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "BookingReference" ADD FOREIGN KEY ("bookingId") REFERENCES "Booking"("id") ON DELETE SET NULL ON UPDATE CASCADE;

View file

@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"

View file

@ -20,6 +20,7 @@ model EventType {
hidden Boolean @default(false)
user User? @relation(fields: [userId], references: [id])
userId Int?
bookings Booking[]
}
model Credential {
@ -45,5 +46,43 @@ model User {
createdDate DateTime @default(now()) @map(name: "created")
eventTypes EventType[]
credentials Credential[]
bookings Booking[]
@@map(name: "users")
}
model BookingReference {
id Int @default(autoincrement()) @id
type String
uid String
booking Booking? @relation(fields: [bookingId], references: [id])
bookingId Int?
}
model Attendee {
id Int @default(autoincrement()) @id
email String
name String
timeZone String
booking Booking? @relation(fields: [bookingId], references: [id])
bookingId Int?
}
model Booking {
id Int @default(autoincrement()) @id
uid String
user User? @relation(fields: [userId], references: [id])
userId Int?
references BookingReference[]
eventType EventType? @relation(fields: [eventTypeId], references: [id])
eventTypeId Int?
title String
description String?
startTime DateTime
endTime DateTime
attendees Attendee[]
createdAt DateTime @default(now())
updatedAt DateTime?
}