# Migration `20200210201051-create-base-schema`

This migration has been generated by andres at 2/10/2020, 8:10:51 PM.
You can check out the [state of the schema](./schema.prisma) after the migration.

## Database Steps

```sql
CREATE TABLE "public"."Content" (
    "author" text  NOT NULL DEFAULT '',
    "course" text   ,
    "createdAt" timestamp(3)  NOT NULL DEFAULT '1970-01-01 00:00:00',
    "id" text  NOT NULL ,
    "title" text  NOT NULL DEFAULT '',
    PRIMARY KEY ("id")
) 

CREATE TABLE "public"."Course" (
    "createdAt" timestamp(3)  NOT NULL DEFAULT '1970-01-01 00:00:00',
    "id" text  NOT NULL ,
    "name" text  NOT NULL DEFAULT '',
    "suggestedLevel" text  NOT NULL DEFAULT 'FIRST',
    PRIMARY KEY ("id")
) 

CREATE TABLE "public"."Guardian" (
    "createdAt" timestamp(3)  NOT NULL DEFAULT '1970-01-01 00:00:00',
    "email" text  NOT NULL DEFAULT '',
    "id" text  NOT NULL ,
    "user" text  NOT NULL ,
    PRIMARY KEY ("id")
) 

CREATE TABLE "public"."Instructor" (
    "createdAt" timestamp(3)  NOT NULL DEFAULT '1970-01-01 00:00:00',
    "email" text  NOT NULL DEFAULT '',
    "id" text  NOT NULL ,
    "user" text  NOT NULL ,
    PRIMARY KEY ("id")
) 

CREATE TABLE "public"."Page" (
    "content" text  NOT NULL ,
    "createdAt" timestamp(3)  NOT NULL DEFAULT '1970-01-01 00:00:00',
    "data" text  NOT NULL DEFAULT '',
    "id" text  NOT NULL ,
    PRIMARY KEY ("id")
) 

CREATE TABLE "public"."Student" (
    "createdAt" timestamp(3)  NOT NULL DEFAULT '1970-01-01 00:00:00',
    "gradeLevel" text  NOT NULL DEFAULT 'FIRST',
    "id" text  NOT NULL ,
    "user" text  NOT NULL ,
    PRIMARY KEY ("id")
) 

CREATE TABLE "public"."Admin" (
    "createdAt" timestamp(3)  NOT NULL DEFAULT '1970-01-01 00:00:00',
    "email" text  NOT NULL DEFAULT '',
    "id" text  NOT NULL ,
    "user" text  NOT NULL ,
    PRIMARY KEY ("id")
) 

CREATE TABLE "public"."User" (
    "firstName" text  NOT NULL DEFAULT '',
    "id" text  NOT NULL ,
    "lastName" text  NOT NULL DEFAULT '',
    "password" text  NOT NULL DEFAULT '',
    "username" text  NOT NULL DEFAULT '',
    PRIMARY KEY ("id")
) 

CREATE TABLE "public"."_CourseToStudent" (
    "A" text  NOT NULL ,
    "B" text  NOT NULL 
) 

CREATE TABLE "public"."_CourseToInstructor" (
    "A" text  NOT NULL ,
    "B" text  NOT NULL 
) 

CREATE TABLE "public"."_GuardianToStudent" (
    "A" text  NOT NULL ,
    "B" text  NOT NULL 
) 

CREATE UNIQUE INDEX "Guardian.email" ON "public"."Guardian"("email")

CREATE UNIQUE INDEX "Guardian_user" ON "public"."Guardian"("user")

CREATE UNIQUE INDEX "Instructor.email" ON "public"."Instructor"("email")

CREATE UNIQUE INDEX "Instructor_user" ON "public"."Instructor"("user")

CREATE UNIQUE INDEX "Student_user" ON "public"."Student"("user")

CREATE UNIQUE INDEX "Admin.email" ON "public"."Admin"("email")

CREATE UNIQUE INDEX "Admin_user" ON "public"."Admin"("user")

CREATE UNIQUE INDEX "User.username" ON "public"."User"("username")

CREATE UNIQUE INDEX "_CourseToStudent_AB_unique" ON "public"."_CourseToStudent"("A","B")

CREATE UNIQUE INDEX "_CourseToInstructor_AB_unique" ON "public"."_CourseToInstructor"("A","B")

CREATE UNIQUE INDEX "_GuardianToStudent_AB_unique" ON "public"."_GuardianToStudent"("A","B")

ALTER TABLE "public"."Content" ADD FOREIGN KEY ("course") REFERENCES "public"."Course"("id") ON DELETE SET NULL

ALTER TABLE "public"."Guardian" ADD FOREIGN KEY ("user") REFERENCES "public"."User"("id") ON DELETE RESTRICT

ALTER TABLE "public"."Instructor" ADD FOREIGN KEY ("user") REFERENCES "public"."User"("id") ON DELETE RESTRICT

ALTER TABLE "public"."Page" ADD FOREIGN KEY ("content") REFERENCES "public"."Content"("id") ON DELETE RESTRICT

ALTER TABLE "public"."Student" ADD FOREIGN KEY ("user") REFERENCES "public"."User"("id") ON DELETE RESTRICT

ALTER TABLE "public"."Admin" ADD FOREIGN KEY ("user") REFERENCES "public"."User"("id") ON DELETE RESTRICT

ALTER TABLE "public"."_CourseToStudent" ADD FOREIGN KEY ("A") REFERENCES "public"."Course"("id") ON DELETE CASCADE

ALTER TABLE "public"."_CourseToStudent" ADD FOREIGN KEY ("B") REFERENCES "public"."Student"("id") ON DELETE CASCADE

ALTER TABLE "public"."_CourseToInstructor" ADD FOREIGN KEY ("A") REFERENCES "public"."Course"("id") ON DELETE CASCADE

ALTER TABLE "public"."_CourseToInstructor" ADD FOREIGN KEY ("B") REFERENCES "public"."Instructor"("id") ON DELETE CASCADE

ALTER TABLE "public"."_GuardianToStudent" ADD FOREIGN KEY ("A") REFERENCES "public"."Guardian"("id") ON DELETE CASCADE

ALTER TABLE "public"."_GuardianToStudent" ADD FOREIGN KEY ("B") REFERENCES "public"."Student"("id") ON DELETE CASCADE
```

## Changes

```diff
diff --git schema.prisma schema.prisma
migration ..20200210201051-create-base-schema
--- datamodel.dml
+++ datamodel.dml
@@ -1,0 +1,92 @@
+generator client {
+  provider = "prisma-client-js"
+}
+
+datasource db {
+  provider = "postgresql"
+  url      = env("DATABASE_URL")
+}
+
+model Content {
+  author    String
+  createdAt DateTime @default(now())
+  id        String   @id @default(cuid())
+  title     String
+  pages     Page[]
+}
+
+model Course {
+  createdAt      DateTime     @default(now())
+  id             String       @id @default(cuid())
+  name           String
+  suggestedLevel GradeLevel
+  students       Student[]
+  contents       Content[]
+  instructors    Instructor[]
+}
+
+model Guardian {
+  id        String    @id @default(cuid())
+  createdAt DateTime  @default(now())
+  email     String    @unique
+  students  Student[]
+  user      User
+}
+
+model Instructor {
+  id        String   @id @default(cuid())
+  createdAt DateTime @default(now())
+  email     String   @unique
+  courses   Course[]
+  user      User
+}
+
+model Page {
+  createdAt DateTime @default(now())
+  data      String
+  id        String   @id @default(cuid())
+  content   Content
+}
+
+model Student {
+  createdAt  DateTime   @default(now())
+  gradeLevel GradeLevel
+  id         String     @id @default(cuid())
+  guardians  Guardian[]
+  courses    Course[]
+  user       User
+}
+
+enum GradeLevel {
+  FIRST
+  SECOND
+  THIRD
+  FOURTH
+  FIFTH
+  SIXTH
+  SEVENTH
+  EIGHTH
+  NINTH
+  TENTH
+  ELEVENTH
+  TWELFTH
+}
+
+model Admin {
+  id        String   @id @default(cuid())
+  createdAt DateTime @default(now())
+  email     String   @unique
+  user      User
+}
+
+model User {
+  id         String      @id @default(cuid())
+  username   String      @unique
+  password   String
+  firstName  String
+  lastName   String
+  admin      Admin?
+  guardian   Guardian?
+  instructor Instructor?
+  student    Student?
+}
```


