Refactored prisma schema, switched from graphql-yoga to apollo-server

This commit is contained in:
2020-10-07 00:04:00 +05:00
parent 7770685f4b
commit ebca575f46
17 changed files with 1703 additions and 756 deletions

View File

@@ -1,103 +0,0 @@
# Migration `20201003131039-initial-structure`
This migration has been generated by Dm1tr1y147 at 10/3/2020, 6:10:39 PM.
You can check out the [state of the schema](./schema.prisma) after the migration.
## Database Steps
```sql
CREATE TABLE "User" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" TEXT NOT NULL,
"email" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
)
CREATE TABLE "Poll" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"userId" INTEGER,
"title" TEXT NOT NULL,
"description" TEXT,
"slug" TEXT NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE
)
CREATE TABLE "Question" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"pollId" INTEGER,
"title" TEXT NOT NULL,
FOREIGN KEY ("pollId") REFERENCES "Poll"("id") ON DELETE SET NULL ON UPDATE CASCADE
)
CREATE TABLE "Variant" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"questionId" INTEGER,
"text" TEXT NOT NULL,
"count" INTEGER NOT NULL DEFAULT 0,
FOREIGN KEY ("questionId") REFERENCES "Question"("id") ON DELETE SET NULL ON UPDATE CASCADE
)
CREATE UNIQUE INDEX "Poll.slug_unique" ON "Poll"("slug")
```
## Changes
```diff
diff --git schema.prisma schema.prisma
migration ..20201003131039-initial-structure
--- datamodel.dml
+++ datamodel.dml
@@ -1,0 +1,46 @@
+// This is your Prisma schema file,
+// learn more about it in the docs: https://pris.ly/d/prisma-schema
+
+datasource db {
+ provider = "sqlite"
+ url = "***"
+}
+
+generator client {
+ provider = "prisma-client-js"
+}
+
+model User {
+ id Int @id @default(autoincrement())
+ name String
+ email String?
+ createdAt DateTime @default(now())
+ polls Poll[]
+}
+
+model Poll {
+ id Int @id @default(autoincrement())
+ User User? @relation(fields: [userId], references: [id])
+ userId Int?
+ title String
+ description String?
+ slug String @unique
+ questions Question[]
+ createdAt DateTime @default(now())
+}
+
+model Question {
+ id Int @id @default(autoincrement())
+ Poll Poll? @relation(fields: [pollId], references: [id])
+ pollId Int?
+ title String
+ variants Variant[]
+}
+
+model Variant {
+ id Int @id @default(autoincrement())
+ Question Question? @relation(fields: [questionId], references: [id])
+ questionId Int?
+ text String
+ count Int @default(0)
+}
```

View File

@@ -1,46 +0,0 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
datasource db {
provider = "sqlite"
url = "***"
}
generator client {
provider = "prisma-client-js"
}
model User {
id Int @id @default(autoincrement())
name String
email String?
createdAt DateTime @default(now())
polls Poll[]
}
model Poll {
id Int @id @default(autoincrement())
User User? @relation(fields: [userId], references: [id])
userId Int?
title String
description String?
slug String @unique
questions Question[]
createdAt DateTime @default(now())
}
model Question {
id Int @id @default(autoincrement())
Poll Poll? @relation(fields: [pollId], references: [id])
pollId Int?
title String
variants Variant[]
}
model Variant {
id Int @id @default(autoincrement())
Question Question? @relation(fields: [questionId], references: [id])
questionId Int?
text String
count Int @default(0)
}

View File

@@ -0,0 +1,219 @@
# Migration `20201006125838-initial-migration`
This migration has been generated by Dm1tr1y147 at 10/6/2020, 5:58:38 PM.
You can check out the [state of the schema](./schema.prisma) after the migration.
## Database Steps
```sql
CREATE TYPE "public"."ChoiseType" AS ENUM ('SELECT', 'CHECK', 'CHOOSE')
CREATE TYPE "public"."AnswerType" AS ENUM ('INPUT', 'CHOISE')
CREATE TABLE "public"."Form" (
"title" text NOT NULL ,
"dateCreated" timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"id" integer NOT NULL ,
"userId" integer NOT NULL ,
PRIMARY KEY ("id")
)
CREATE TABLE "public"."ChoisesQuestion" (
"title" text NOT NULL ,
"type" "ChoiseType" NOT NULL ,
"number" integer NOT NULL ,
"id" integer NOT NULL ,
"formId" integer ,
PRIMARY KEY ("id")
)
CREATE TABLE "public"."Variant" (
"text" text NOT NULL ,
"id" integer NOT NULL ,
"choisesQuestionId" integer ,
PRIMARY KEY ("id")
)
CREATE TABLE "public"."InputQuestion" (
"title" text NOT NULL ,
"number" integer NOT NULL ,
"id" integer NOT NULL ,
"formId" integer ,
PRIMARY KEY ("id")
)
CREATE TABLE "public"."FormSubmission" (
"date" timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"id" integer NOT NULL ,
"formId" integer ,
"userId" integer NOT NULL ,
PRIMARY KEY ("id")
)
CREATE TABLE "public"."Answer" (
"id" integer NOT NULL ,
"userInput" text NOT NULL ,
"userChoise" integer NOT NULL ,
"type" "AnswerType" NOT NULL ,
"formSubmissionId" integer ,
PRIMARY KEY ("id")
)
CREATE TABLE "public"."User" (
"id" integer NOT NULL ,
"name" text NOT NULL ,
PRIMARY KEY ("id")
)
ALTER TABLE "public"."Form" ADD FOREIGN KEY ("userId")REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE
ALTER TABLE "public"."ChoisesQuestion" ADD FOREIGN KEY ("formId")REFERENCES "public"."Form"("id") ON DELETE SET NULL ON UPDATE CASCADE
ALTER TABLE "public"."Variant" ADD FOREIGN KEY ("choisesQuestionId")REFERENCES "public"."ChoisesQuestion"("id") ON DELETE SET NULL ON UPDATE CASCADE
ALTER TABLE "public"."InputQuestion" ADD FOREIGN KEY ("formId")REFERENCES "public"."Form"("id") ON DELETE SET NULL ON UPDATE CASCADE
ALTER TABLE "public"."FormSubmission" ADD FOREIGN KEY ("userId")REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE
ALTER TABLE "public"."FormSubmission" ADD FOREIGN KEY ("formId")REFERENCES "public"."Form"("id") ON DELETE SET NULL ON UPDATE CASCADE
ALTER TABLE "public"."Answer" ADD FOREIGN KEY ("formSubmissionId")REFERENCES "public"."FormSubmission"("id") ON DELETE SET NULL ON UPDATE CASCADE
```
## Changes
```diff
diff --git schema.prisma schema.prisma
migration ..20201006125838-initial-migration
--- datamodel.dml
+++ datamodel.dml
@@ -1,0 +1,126 @@
+// This is your Prisma schema file,
+// learn more about it in the docs: https://pris.ly/d/prisma-schema
+
+datasource db {
+ provider = "postgres"
+ url = "***"
+}
+
+generator client {
+ provider = "prisma-client-js"
+}
+
+// model User {
+// id Int @id @default(autoincrement())
+// name String
+// email String?
+// createdAt DateTime @default(now())
+// polls Poll[]
+// }
+
+// model Poll {
+// id Int @id @default(autoincrement())
+// User User? @relation(fields: [userId], references: [id])
+// userId Int?
+// title String
+// description String?
+// slug String @unique @default(cuid())
+// questions Question[]
+// createdAt DateTime @default(now())
+// }
+
+// model Question {
+// id Int @id @default(autoincrement())
+// Poll Poll? @relation(fields: [pollId], references: [id])
+// pollId Int?
+// title String
+// variants Variant[]
+// }
+
+// model Variant {
+// id Int @id @default(autoincrement())
+// Question Question? @relation(fields: [questionId], references: [id])
+// questionId Int?
+// text String
+// count Int @default(0)
+// }
+
+model Form {
+ title String
+ choisesQuestions ChoisesQuestion[]
+ inputQuestions InputQuestion[]
+ submissions FormSubmission[]
+ dateCreated DateTime @default(now())
+
+ id Int @id
+ userId Int
+ author User @relation(fields: [userId], references: [id])
+}
+
+model ChoisesQuestion {
+ title String
+ variants Variant[]
+ type ChoiseType
+ number Int
+
+ id Int @id
+ Form Form? @relation(fields: [formId], references: [id])
+ formId Int?
+}
+
+model Variant {
+ text String
+
+ id Int @id
+ ChoisesQuestion ChoisesQuestion? @relation(fields: [choisesQuestionId], references: [id])
+ choisesQuestionId Int?
+}
+
+model InputQuestion {
+ title String
+ number Int
+
+ id Int @id
+ Form Form? @relation(fields: [formId], references: [id])
+ formId Int?
+}
+
+model FormSubmission {
+ answers Answer[]
+ date DateTime @default(now())
+
+
+ id Int @id
+ user User @relation(fields: [userId], references: [id])
+ Form Form? @relation(fields: [formId], references: [id])
+ formId Int?
+ userId Int
+}
+
+model Answer {
+ id Int @id
+ userInput String
+ userChoise Int
+ type AnswerType
+ FormSubmission FormSubmission? @relation(fields: [formSubmissionId], references: [id])
+ formSubmissionId Int?
+}
+
+enum ChoiseType {
+ SELECT
+ CHECK
+ CHOOSE
+}
+
+enum AnswerType {
+ INPUT
+ CHOISE
+}
+
+model User {
+ id Int @id
+ name String
+
+ forms Form[]
+ formsSubmissions FormSubmission[]
+}
```

View File

@@ -0,0 +1,126 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
datasource db {
provider = "postgres"
url = "***"
}
generator client {
provider = "prisma-client-js"
}
// model User {
// id Int @id @default(autoincrement())
// name String
// email String?
// createdAt DateTime @default(now())
// polls Poll[]
// }
// model Poll {
// id Int @id @default(autoincrement())
// User User? @relation(fields: [userId], references: [id])
// userId Int?
// title String
// description String?
// slug String @unique @default(cuid())
// questions Question[]
// createdAt DateTime @default(now())
// }
// model Question {
// id Int @id @default(autoincrement())
// Poll Poll? @relation(fields: [pollId], references: [id])
// pollId Int?
// title String
// variants Variant[]
// }
// model Variant {
// id Int @id @default(autoincrement())
// Question Question? @relation(fields: [questionId], references: [id])
// questionId Int?
// text String
// count Int @default(0)
// }
model Form {
title String
choisesQuestions ChoisesQuestion[]
inputQuestions InputQuestion[]
submissions FormSubmission[]
dateCreated DateTime @default(now())
id Int @id
userId Int
author User @relation(fields: [userId], references: [id])
}
model ChoisesQuestion {
title String
variants Variant[]
type ChoiseType
number Int
id Int @id
Form Form? @relation(fields: [formId], references: [id])
formId Int?
}
model Variant {
text String
id Int @id
ChoisesQuestion ChoisesQuestion? @relation(fields: [choisesQuestionId], references: [id])
choisesQuestionId Int?
}
model InputQuestion {
title String
number Int
id Int @id
Form Form? @relation(fields: [formId], references: [id])
formId Int?
}
model FormSubmission {
answers Answer[]
date DateTime @default(now())
id Int @id
user User @relation(fields: [userId], references: [id])
Form Form? @relation(fields: [formId], references: [id])
formId Int?
userId Int
}
model Answer {
id Int @id
userInput String
userChoise Int
type AnswerType
FormSubmission FormSubmission? @relation(fields: [formSubmissionId], references: [id])
formSubmissionId Int?
}
enum ChoiseType {
SELECT
CHECK
CHOOSE
}
enum AnswerType {
INPUT
CHOISE
}
model User {
id Int @id
name String
forms Form[]
formsSubmissions FormSubmission[]
}

View File

@@ -0,0 +1,187 @@
# Migration `20201006185953-improved-schema-structure`
This migration has been generated by Dm1tr1y147 at 10/6/2020, 11:59:53 PM.
You can check out the [state of the schema](./schema.prisma) after the migration.
## Database Steps
```sql
CREATE SEQUENCE "answer_id_seq";
ALTER TABLE "public"."Answer" ALTER COLUMN "id" SET DEFAULT nextval('answer_id_seq');
ALTER SEQUENCE "answer_id_seq" OWNED BY "public"."Answer"."id"
CREATE SEQUENCE "choisesquestion_id_seq";
ALTER TABLE "public"."ChoisesQuestion" ALTER COLUMN "id" SET DEFAULT nextval('choisesquestion_id_seq');
ALTER SEQUENCE "choisesquestion_id_seq" OWNED BY "public"."ChoisesQuestion"."id"
CREATE SEQUENCE "form_id_seq";
ALTER TABLE "public"."Form" ALTER COLUMN "id" SET DEFAULT nextval('form_id_seq');
ALTER SEQUENCE "form_id_seq" OWNED BY "public"."Form"."id"
CREATE SEQUENCE "formsubmission_id_seq";
ALTER TABLE "public"."FormSubmission" ALTER COLUMN "id" SET DEFAULT nextval('formsubmission_id_seq');
ALTER SEQUENCE "formsubmission_id_seq" OWNED BY "public"."FormSubmission"."id"
CREATE SEQUENCE "inputquestion_id_seq";
ALTER TABLE "public"."InputQuestion" ALTER COLUMN "id" SET DEFAULT nextval('inputquestion_id_seq');
ALTER SEQUENCE "inputquestion_id_seq" OWNED BY "public"."InputQuestion"."id"
CREATE SEQUENCE "user_id_seq";
ALTER TABLE "public"."User" ALTER COLUMN "id" SET DEFAULT nextval('user_id_seq');
ALTER SEQUENCE "user_id_seq" OWNED BY "public"."User"."id"
CREATE SEQUENCE "variant_id_seq";
ALTER TABLE "public"."Variant" ALTER COLUMN "id" SET DEFAULT nextval('variant_id_seq');
ALTER SEQUENCE "variant_id_seq" OWNED BY "public"."Variant"."id"
```
## Changes
```diff
diff --git schema.prisma schema.prisma
migration 20201006125838-initial-migration..20201006185953-improved-schema-structure
--- datamodel.dml
+++ datamodel.dml
@@ -2,125 +2,90 @@
// learn more about it in the docs: https://pris.ly/d/prisma-schema
datasource db {
provider = "postgres"
- url = "***"
+ url = "***"
}
generator client {
provider = "prisma-client-js"
}
-// model User {
-// id Int @id @default(autoincrement())
-// name String
-// email String?
-// createdAt DateTime @default(now())
-// polls Poll[]
-// }
-
-// model Poll {
-// id Int @id @default(autoincrement())
-// User User? @relation(fields: [userId], references: [id])
-// userId Int?
-// title String
-// description String?
-// slug String @unique @default(cuid())
-// questions Question[]
-// createdAt DateTime @default(now())
-// }
-
-// model Question {
-// id Int @id @default(autoincrement())
-// Poll Poll? @relation(fields: [pollId], references: [id])
-// pollId Int?
-// title String
-// variants Variant[]
-// }
-
-// model Variant {
-// id Int @id @default(autoincrement())
-// Question Question? @relation(fields: [questionId], references: [id])
-// questionId Int?
-// text String
-// count Int @default(0)
-// }
-
model Form {
title String
choisesQuestions ChoisesQuestion[]
inputQuestions InputQuestion[]
submissions FormSubmission[]
dateCreated DateTime @default(now())
+ author User @relation(fields: [userId], references: [id])
- id Int @id
+ id Int @id @default(autoincrement())
userId Int
- author User @relation(fields: [userId], references: [id])
}
model ChoisesQuestion {
title String
variants Variant[]
type ChoiseType
number Int
- id Int @id
+ id Int @id @default(autoincrement())
Form Form? @relation(fields: [formId], references: [id])
formId Int?
}
model Variant {
text String
- id Int @id
+ id Int @id @default(autoincrement())
ChoisesQuestion ChoisesQuestion? @relation(fields: [choisesQuestionId], references: [id])
choisesQuestionId Int?
}
model InputQuestion {
title String
number Int
- id Int @id
+ id Int @id @default(autoincrement())
Form Form? @relation(fields: [formId], references: [id])
formId Int?
}
+enum ChoiseType {
+ SELECT
+ CHECK
+ CHOOSE
+}
+
+model User {
+ name String
+ forms Form[]
+
+ id Int @id @default(autoincrement())
+ formsSubmissions FormSubmission[]
+}
+
model FormSubmission {
answers Answer[]
date DateTime @default(now())
+ user User @relation(fields: [userId], references: [id])
-
- id Int @id
- user User @relation(fields: [userId], references: [id])
+ id Int @id @default(autoincrement())
+ userId Int
Form Form? @relation(fields: [formId], references: [id])
formId Int?
- userId Int
}
model Answer {
- id Int @id
- userInput String
- userChoise Int
- type AnswerType
+ userInput String
+ userChoise Int
+ type AnswerType
+
+ id Int @id @default(autoincrement())
FormSubmission FormSubmission? @relation(fields: [formSubmissionId], references: [id])
formSubmissionId Int?
}
-enum ChoiseType {
- SELECT
- CHECK
- CHOOSE
-}
-
enum AnswerType {
INPUT
CHOISE
}
-
-model User {
- id Int @id
- name String
-
- forms Form[]
- formsSubmissions FormSubmission[]
-}
```

View File

@@ -0,0 +1,91 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
datasource db {
provider = "postgres"
url = "***"
}
generator client {
provider = "prisma-client-js"
}
model Form {
title String
choisesQuestions ChoisesQuestion[]
inputQuestions InputQuestion[]
submissions FormSubmission[]
dateCreated DateTime @default(now())
author User @relation(fields: [userId], references: [id])
id Int @id @default(autoincrement())
userId Int
}
model ChoisesQuestion {
title String
variants Variant[]
type ChoiseType
number Int
id Int @id @default(autoincrement())
Form Form? @relation(fields: [formId], references: [id])
formId Int?
}
model Variant {
text String
id Int @id @default(autoincrement())
ChoisesQuestion ChoisesQuestion? @relation(fields: [choisesQuestionId], references: [id])
choisesQuestionId Int?
}
model InputQuestion {
title String
number Int
id Int @id @default(autoincrement())
Form Form? @relation(fields: [formId], references: [id])
formId Int?
}
enum ChoiseType {
SELECT
CHECK
CHOOSE
}
model User {
name String
forms Form[]
id Int @id @default(autoincrement())
formsSubmissions FormSubmission[]
}
model FormSubmission {
answers Answer[]
date DateTime @default(now())
user User @relation(fields: [userId], references: [id])
id Int @id @default(autoincrement())
userId Int
Form Form? @relation(fields: [formId], references: [id])
formId Int?
}
model Answer {
userInput String
userChoise Int
type AnswerType
id Int @id @default(autoincrement())
FormSubmission FormSubmission? @relation(fields: [formSubmissionId], references: [id])
formSubmissionId Int?
}
enum AnswerType {
INPUT
CHOISE
}

View File

@@ -0,0 +1,180 @@
{
"version": "0.3.14-fixed",
"steps": [
{
"tag": "CreateDirective",
"location": {
"path": {
"tag": "Field",
"model": "Form",
"field": "id"
},
"directive": "default"
}
},
{
"tag": "CreateArgument",
"location": {
"tag": "Directive",
"path": {
"tag": "Field",
"model": "Form",
"field": "id"
},
"directive": "default"
},
"argument": "",
"value": "autoincrement()"
},
{
"tag": "CreateDirective",
"location": {
"path": {
"tag": "Field",
"model": "ChoisesQuestion",
"field": "id"
},
"directive": "default"
}
},
{
"tag": "CreateArgument",
"location": {
"tag": "Directive",
"path": {
"tag": "Field",
"model": "ChoisesQuestion",
"field": "id"
},
"directive": "default"
},
"argument": "",
"value": "autoincrement()"
},
{
"tag": "CreateDirective",
"location": {
"path": {
"tag": "Field",
"model": "Variant",
"field": "id"
},
"directive": "default"
}
},
{
"tag": "CreateArgument",
"location": {
"tag": "Directive",
"path": {
"tag": "Field",
"model": "Variant",
"field": "id"
},
"directive": "default"
},
"argument": "",
"value": "autoincrement()"
},
{
"tag": "CreateDirective",
"location": {
"path": {
"tag": "Field",
"model": "InputQuestion",
"field": "id"
},
"directive": "default"
}
},
{
"tag": "CreateArgument",
"location": {
"tag": "Directive",
"path": {
"tag": "Field",
"model": "InputQuestion",
"field": "id"
},
"directive": "default"
},
"argument": "",
"value": "autoincrement()"
},
{
"tag": "CreateDirective",
"location": {
"path": {
"tag": "Field",
"model": "FormSubmission",
"field": "id"
},
"directive": "default"
}
},
{
"tag": "CreateArgument",
"location": {
"tag": "Directive",
"path": {
"tag": "Field",
"model": "FormSubmission",
"field": "id"
},
"directive": "default"
},
"argument": "",
"value": "autoincrement()"
},
{
"tag": "CreateDirective",
"location": {
"path": {
"tag": "Field",
"model": "Answer",
"field": "id"
},
"directive": "default"
}
},
{
"tag": "CreateArgument",
"location": {
"tag": "Directive",
"path": {
"tag": "Field",
"model": "Answer",
"field": "id"
},
"directive": "default"
},
"argument": "",
"value": "autoincrement()"
},
{
"tag": "CreateDirective",
"location": {
"path": {
"tag": "Field",
"model": "User",
"field": "id"
},
"directive": "default"
}
},
{
"tag": "CreateArgument",
"location": {
"tag": "Directive",
"path": {
"tag": "Field",
"model": "User",
"field": "id"
},
"directive": "default"
},
"argument": "",
"value": "autoincrement()"
}
]
}

View File

@@ -1,3 +1,4 @@
# Prisma Migrate lockfile v1
20201003131039-initial-structure
20201006125838-initial-migration
20201006185953-improved-schema-structure