From a934017d8727d8dbbbcb00de3a2c1c208a5921f7 Mon Sep 17 00:00:00 2001 From: Stefan <32109571+Stefan-5422@users.noreply.github.com> Date: Mon, 11 Oct 2021 12:06:02 +0200 Subject: [PATCH] boilerplate --- index.ts | 16 +++ .../20211011095943_init/migration.sql | 105 ++++++++++++++++++ prisma/migrations/migration_lock.toml | 3 + prisma/schema.prisma | 85 ++++++++++++++ tsconfig.json | 9 ++ 5 files changed, 218 insertions(+) create mode 100644 index.ts create mode 100644 prisma/migrations/20211011095943_init/migration.sql create mode 100644 prisma/migrations/migration_lock.toml create mode 100644 prisma/schema.prisma create mode 100644 tsconfig.json diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..20aff4a --- /dev/null +++ b/index.ts @@ -0,0 +1,16 @@ +import { PrismaClient } from '@prisma/client' + +const prisma = new PrismaClient() + +async function main() { + // ... you will write your Prisma Client queries here + console.log("Hello world!!") +} + +main() + .catch((e) => { + throw e + }) + .finally(async () => { + await prisma.$disconnect() + }) \ No newline at end of file diff --git a/prisma/migrations/20211011095943_init/migration.sql b/prisma/migrations/20211011095943_init/migration.sql new file mode 100644 index 0000000..77cfea8 --- /dev/null +++ b/prisma/migrations/20211011095943_init/migration.sql @@ -0,0 +1,105 @@ +-- CreateTable +CREATE TABLE "Event" ( + "id" INTEGER NOT NULL, + "date" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "Event_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Admin" ( + "id" INTEGER NOT NULL, + "name" TEXT NOT NULL, + "password" TEXT NOT NULL, + "level" INTEGER NOT NULL, + "eventId" INTEGER NOT NULL, + + CONSTRAINT "Admin_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Campaign" ( + "id" INTEGER NOT NULL, + "ends" TIMESTAMP(3) NOT NULL, + "limit" INTEGER NOT NULL DEFAULT 40, + "curr" INTEGER NOT NULL DEFAULT 0, + "links" TEXT[], + "eventId" INTEGER NOT NULL, + "groupId" INTEGER NOT NULL, + + CONSTRAINT "Campaign_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Discipline" ( + "id" INTEGER NOT NULL, + "name" TEXT NOT NULL, + "minteamsize" INTEGER NOT NULL, + "maxteamsize" INTEGER NOT NULL, + "eventId" INTEGER NOT NULL, + + CONSTRAINT "Discipline_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Teams" ( + "id" INTEGER NOT NULL, + "name" TEXT NOT NULL, + "startdate" TIMESTAMP(3) NOT NULL, + "disciplineId" INTEGER NOT NULL, + + CONSTRAINT "Teams_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Participant" ( + "id" INTEGER NOT NULL, + "firstname" TEXT NOT NULL, + "lastname" TEXT NOT NULL, + "email" TEXT NOT NULL, + "teamsId" INTEGER NOT NULL, + + CONSTRAINT "Participant_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Oragnisation" ( + "id" INTEGER NOT NULL, + "name" TEXT NOT NULL, + "eventId" INTEGER NOT NULL, + + CONSTRAINT "Oragnisation_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Group" ( + "id" INTEGER NOT NULL, + "name" TEXT NOT NULL, + "oragnisationId" INTEGER NOT NULL, + + CONSTRAINT "Group_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "Admin" ADD CONSTRAINT "Admin_eventId_fkey" FOREIGN KEY ("eventId") REFERENCES "Event"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Campaign" ADD CONSTRAINT "Campaign_groupId_fkey" FOREIGN KEY ("groupId") REFERENCES "Group"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Campaign" ADD CONSTRAINT "Campaign_eventId_fkey" FOREIGN KEY ("eventId") REFERENCES "Event"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Discipline" ADD CONSTRAINT "Discipline_eventId_fkey" FOREIGN KEY ("eventId") REFERENCES "Event"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Teams" ADD CONSTRAINT "Teams_disciplineId_fkey" FOREIGN KEY ("disciplineId") REFERENCES "Discipline"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Participant" ADD CONSTRAINT "Participant_teamsId_fkey" FOREIGN KEY ("teamsId") REFERENCES "Teams"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Oragnisation" ADD CONSTRAINT "Oragnisation_eventId_fkey" FOREIGN KEY ("eventId") REFERENCES "Event"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Group" ADD CONSTRAINT "Group_oragnisationId_fkey" FOREIGN KEY ("oragnisationId") REFERENCES "Oragnisation"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000..fbffa92 --- /dev/null +++ b/prisma/migrations/migration_lock.toml @@ -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" \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma new file mode 100644 index 0000000..179f1a2 --- /dev/null +++ b/prisma/schema.prisma @@ -0,0 +1,85 @@ +// This is your Prisma schema file, +// learn more about it in the docs: https://pris.ly/d/prisma-schema + +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} + +generator client { + provider = "prisma-client-js" +} + +model Event { + id Int @id + date DateTime + disciplines Discipline[] + admins Admin[] + organisations Oragnisation[] + campaigns Campaign[] +} + +model Admin { + id Int @id + name String + password String + level Int + event Event @relation(fields: [eventId], references: [id]) + eventId Int +} + +model Campaign { + id Int @id + ends DateTime + limit Int @default(40) + curr Int @default(0) + links String[] + group Group @relation(fields: [groupId], references: [id]) + Event Event @relation(fields: [eventId], references: [id]) + eventId Int + groupId Int +} + +model Discipline { + id Int @id + name String + minteamsize Int + maxteamsize Int + event Event @relation(fields: [eventId], references: [id]) + eventId Int + teams Teams[] +} + +model Teams { + id Int @id + name String + startdate DateTime + participants Participant[] + discipline Discipline @relation(fields: [disciplineId], references: [id]) + disciplineId Int +} + +model Participant { + id Int @id + firstname String + lastname String + email String + teams Teams @relation(fields: [teamsId], references: [id]) + teamsId Int +} + +model Oragnisation { + id Int @id + name String + groups Group[] + Event Event @relation(fields: [eventId], references: [id]) + eventId Int +} + +model Group { + id Int @id + name String + Oragnisation Oragnisation @relation(fields: [oragnisationId], references: [id]) + oragnisationId Int + Campaign Campaign[] +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..4a8ff6e --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "sourceMap": true, + "outDir": "dist", + "strict": true, + "lib": ["esnext"], + "esModuleInterop": true + } +} \ No newline at end of file