diff --git a/README.md b/README.md index 307ee58..7fa32f0 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,4 @@ Backend used with QuestionForm application. - Prisma - Graphql -- Graphql-yoga +- Apollo Server diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 069c3db..0000000 --- a/package-lock.json +++ /dev/null @@ -1,73 +0,0 @@ -{ - "name": "backend", - "version": "1.0.0", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "@prisma/cli": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/@prisma/cli/-/cli-2.7.1.tgz", - "integrity": "sha512-0uA+gWkNQ35DveVHDPltiTCTr4wcXtEhnPs463IEM+Xn8dTv9x0gtZiYHSuQM3t7uwlOxj1rurBsqSbiljynfQ==", - "dev": true - }, - "@prisma/client": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/@prisma/client/-/client-2.7.1.tgz", - "integrity": "sha512-IEWDCuvIaQTira8/jAyf+uY+AuPPUFDIXMSN4zEA/gvoJv2woq7RmkaubS+NQVgDbbyOR6F3UcXLiFTYQDzZkQ==", - "requires": { - "pkg-up": "^3.1.0" - } - }, - "find-up": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", - "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", - "requires": { - "locate-path": "^3.0.0" - } - }, - "locate-path": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", - "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", - "requires": { - "p-locate": "^3.0.0", - "path-exists": "^3.0.0" - } - }, - "p-limit": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", - "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", - "requires": { - "p-try": "^2.0.0" - } - }, - "p-locate": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", - "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", - "requires": { - "p-limit": "^2.0.0" - } - }, - "p-try": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", - "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==" - }, - "path-exists": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=" - }, - "pkg-up": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/pkg-up/-/pkg-up-3.1.0.tgz", - "integrity": "sha512-nDywThFk1i4BQK4twPQ6TA4RT8bDY96yeuCVBWL3ePARCiEKDRSrNGbFIgUJpLp+XeIR65v8ra7WuJOFUBtkMA==", - "requires": { - "find-up": "^3.0.0" - } - } - } -} diff --git a/package.json b/package.json index bf79765..a09e584 100644 --- a/package.json +++ b/package.json @@ -5,14 +5,18 @@ "license": "MIT", "dependencies": { "@prisma/client": "^2.7.1", - "graphql-yoga": "^1.18.3" + "@types/jsonwebtoken": "^8.5.0", + "apollo-server": "^2.18.2", + "graphql": "^15.3.0", + "jsonwebtoken": "^8.5.1", + "jwks-rsa": "^1.10.1" }, "scripts": { - "dev": "ts-node src/index.ts" + "dev": "ts-node-dev src/index.ts" }, "devDependencies": { - "@prisma/cli": "^2.7.1", "ts-node": "^9.0.0", + "ts-node-dev": "^1.0.0-pre.63", "typescript": "^4.0.3" } } diff --git a/prisma/dev.db b/prisma/dev.db deleted file mode 100644 index 6f8ead2..0000000 Binary files a/prisma/dev.db and /dev/null differ diff --git a/prisma/migrations/20201003131039-initial-structure/README.md b/prisma/migrations/20201003131039-initial-structure/README.md deleted file mode 100644 index 84cc855..0000000 --- a/prisma/migrations/20201003131039-initial-structure/README.md +++ /dev/null @@ -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) -+} -``` - - diff --git a/prisma/migrations/20201003131039-initial-structure/schema.prisma b/prisma/migrations/20201003131039-initial-structure/schema.prisma deleted file mode 100644 index 5a286f8..0000000 --- a/prisma/migrations/20201003131039-initial-structure/schema.prisma +++ /dev/null @@ -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) -} \ No newline at end of file diff --git a/prisma/migrations/20201006125838-initial-migration/README.md b/prisma/migrations/20201006125838-initial-migration/README.md new file mode 100644 index 0000000..4407c56 --- /dev/null +++ b/prisma/migrations/20201006125838-initial-migration/README.md @@ -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[] ++} +``` + + diff --git a/prisma/migrations/20201006125838-initial-migration/schema.prisma b/prisma/migrations/20201006125838-initial-migration/schema.prisma new file mode 100644 index 0000000..6e9caa0 --- /dev/null +++ b/prisma/migrations/20201006125838-initial-migration/schema.prisma @@ -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[] +} diff --git a/prisma/migrations/20201003131039-initial-structure/steps.json b/prisma/migrations/20201006125838-initial-migration/steps.json similarity index 52% rename from prisma/migrations/20201003131039-initial-structure/steps.json rename to prisma/migrations/20201006125838-initial-migration/steps.json index 868d111..f83decf 100644 --- a/prisma/migrations/20201003131039-initial-structure/steps.json +++ b/prisma/migrations/20201006125838-initial-migration/steps.json @@ -1,6 +1,23 @@ { "version": "0.3.14-fixed", "steps": [ + { + "tag": "CreateEnum", + "enum": "ChoiseType", + "values": [ + "SELECT", + "CHECK", + "CHOOSE" + ] + }, + { + "tag": "CreateEnum", + "enum": "AnswerType", + "values": [ + "INPUT", + "CHOISE" + ] + }, { "tag": "CreateSource", "source": "db" @@ -12,7 +29,7 @@ "source": "db" }, "argument": "provider", - "value": "\"sqlite\"" + "value": "\"postgres\"" }, { "tag": "CreateArgument", @@ -23,6 +40,678 @@ "argument": "url", "value": "\"***\"" }, + { + "tag": "CreateModel", + "model": "Form" + }, + { + "tag": "CreateField", + "model": "Form", + "field": "title", + "type": "String", + "arity": "Required" + }, + { + "tag": "CreateField", + "model": "Form", + "field": "choisesQuestions", + "type": "ChoisesQuestion", + "arity": "List" + }, + { + "tag": "CreateField", + "model": "Form", + "field": "inputQuestions", + "type": "InputQuestion", + "arity": "List" + }, + { + "tag": "CreateField", + "model": "Form", + "field": "submissions", + "type": "FormSubmission", + "arity": "List" + }, + { + "tag": "CreateField", + "model": "Form", + "field": "dateCreated", + "type": "DateTime", + "arity": "Required" + }, + { + "tag": "CreateDirective", + "location": { + "path": { + "tag": "Field", + "model": "Form", + "field": "dateCreated" + }, + "directive": "default" + } + }, + { + "tag": "CreateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "Form", + "field": "dateCreated" + }, + "directive": "default" + }, + "argument": "", + "value": "now()" + }, + { + "tag": "CreateField", + "model": "Form", + "field": "id", + "type": "Int", + "arity": "Required" + }, + { + "tag": "CreateDirective", + "location": { + "path": { + "tag": "Field", + "model": "Form", + "field": "id" + }, + "directive": "id" + } + }, + { + "tag": "CreateField", + "model": "Form", + "field": "userId", + "type": "Int", + "arity": "Required" + }, + { + "tag": "CreateField", + "model": "Form", + "field": "author", + "type": "User", + "arity": "Required" + }, + { + "tag": "CreateDirective", + "location": { + "path": { + "tag": "Field", + "model": "Form", + "field": "author" + }, + "directive": "relation" + } + }, + { + "tag": "CreateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "Form", + "field": "author" + }, + "directive": "relation" + }, + "argument": "fields", + "value": "[userId]" + }, + { + "tag": "CreateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "Form", + "field": "author" + }, + "directive": "relation" + }, + "argument": "references", + "value": "[id]" + }, + { + "tag": "CreateModel", + "model": "ChoisesQuestion" + }, + { + "tag": "CreateField", + "model": "ChoisesQuestion", + "field": "title", + "type": "String", + "arity": "Required" + }, + { + "tag": "CreateField", + "model": "ChoisesQuestion", + "field": "variants", + "type": "Variant", + "arity": "List" + }, + { + "tag": "CreateField", + "model": "ChoisesQuestion", + "field": "type", + "type": "ChoiseType", + "arity": "Required" + }, + { + "tag": "CreateField", + "model": "ChoisesQuestion", + "field": "number", + "type": "Int", + "arity": "Required" + }, + { + "tag": "CreateField", + "model": "ChoisesQuestion", + "field": "id", + "type": "Int", + "arity": "Required" + }, + { + "tag": "CreateDirective", + "location": { + "path": { + "tag": "Field", + "model": "ChoisesQuestion", + "field": "id" + }, + "directive": "id" + } + }, + { + "tag": "CreateField", + "model": "ChoisesQuestion", + "field": "Form", + "type": "Form", + "arity": "Optional" + }, + { + "tag": "CreateDirective", + "location": { + "path": { + "tag": "Field", + "model": "ChoisesQuestion", + "field": "Form" + }, + "directive": "relation" + } + }, + { + "tag": "CreateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "ChoisesQuestion", + "field": "Form" + }, + "directive": "relation" + }, + "argument": "fields", + "value": "[formId]" + }, + { + "tag": "CreateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "ChoisesQuestion", + "field": "Form" + }, + "directive": "relation" + }, + "argument": "references", + "value": "[id]" + }, + { + "tag": "CreateField", + "model": "ChoisesQuestion", + "field": "formId", + "type": "Int", + "arity": "Optional" + }, + { + "tag": "CreateModel", + "model": "Variant" + }, + { + "tag": "CreateField", + "model": "Variant", + "field": "text", + "type": "String", + "arity": "Required" + }, + { + "tag": "CreateField", + "model": "Variant", + "field": "id", + "type": "Int", + "arity": "Required" + }, + { + "tag": "CreateDirective", + "location": { + "path": { + "tag": "Field", + "model": "Variant", + "field": "id" + }, + "directive": "id" + } + }, + { + "tag": "CreateField", + "model": "Variant", + "field": "ChoisesQuestion", + "type": "ChoisesQuestion", + "arity": "Optional" + }, + { + "tag": "CreateDirective", + "location": { + "path": { + "tag": "Field", + "model": "Variant", + "field": "ChoisesQuestion" + }, + "directive": "relation" + } + }, + { + "tag": "CreateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "Variant", + "field": "ChoisesQuestion" + }, + "directive": "relation" + }, + "argument": "fields", + "value": "[choisesQuestionId]" + }, + { + "tag": "CreateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "Variant", + "field": "ChoisesQuestion" + }, + "directive": "relation" + }, + "argument": "references", + "value": "[id]" + }, + { + "tag": "CreateField", + "model": "Variant", + "field": "choisesQuestionId", + "type": "Int", + "arity": "Optional" + }, + { + "tag": "CreateModel", + "model": "InputQuestion" + }, + { + "tag": "CreateField", + "model": "InputQuestion", + "field": "title", + "type": "String", + "arity": "Required" + }, + { + "tag": "CreateField", + "model": "InputQuestion", + "field": "number", + "type": "Int", + "arity": "Required" + }, + { + "tag": "CreateField", + "model": "InputQuestion", + "field": "id", + "type": "Int", + "arity": "Required" + }, + { + "tag": "CreateDirective", + "location": { + "path": { + "tag": "Field", + "model": "InputQuestion", + "field": "id" + }, + "directive": "id" + } + }, + { + "tag": "CreateField", + "model": "InputQuestion", + "field": "Form", + "type": "Form", + "arity": "Optional" + }, + { + "tag": "CreateDirective", + "location": { + "path": { + "tag": "Field", + "model": "InputQuestion", + "field": "Form" + }, + "directive": "relation" + } + }, + { + "tag": "CreateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "InputQuestion", + "field": "Form" + }, + "directive": "relation" + }, + "argument": "fields", + "value": "[formId]" + }, + { + "tag": "CreateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "InputQuestion", + "field": "Form" + }, + "directive": "relation" + }, + "argument": "references", + "value": "[id]" + }, + { + "tag": "CreateField", + "model": "InputQuestion", + "field": "formId", + "type": "Int", + "arity": "Optional" + }, + { + "tag": "CreateModel", + "model": "FormSubmission" + }, + { + "tag": "CreateField", + "model": "FormSubmission", + "field": "answers", + "type": "Answer", + "arity": "List" + }, + { + "tag": "CreateField", + "model": "FormSubmission", + "field": "date", + "type": "DateTime", + "arity": "Required" + }, + { + "tag": "CreateDirective", + "location": { + "path": { + "tag": "Field", + "model": "FormSubmission", + "field": "date" + }, + "directive": "default" + } + }, + { + "tag": "CreateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "FormSubmission", + "field": "date" + }, + "directive": "default" + }, + "argument": "", + "value": "now()" + }, + { + "tag": "CreateField", + "model": "FormSubmission", + "field": "id", + "type": "Int", + "arity": "Required" + }, + { + "tag": "CreateDirective", + "location": { + "path": { + "tag": "Field", + "model": "FormSubmission", + "field": "id" + }, + "directive": "id" + } + }, + { + "tag": "CreateField", + "model": "FormSubmission", + "field": "user", + "type": "User", + "arity": "Required" + }, + { + "tag": "CreateDirective", + "location": { + "path": { + "tag": "Field", + "model": "FormSubmission", + "field": "user" + }, + "directive": "relation" + } + }, + { + "tag": "CreateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "FormSubmission", + "field": "user" + }, + "directive": "relation" + }, + "argument": "fields", + "value": "[userId]" + }, + { + "tag": "CreateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "FormSubmission", + "field": "user" + }, + "directive": "relation" + }, + "argument": "references", + "value": "[id]" + }, + { + "tag": "CreateField", + "model": "FormSubmission", + "field": "Form", + "type": "Form", + "arity": "Optional" + }, + { + "tag": "CreateDirective", + "location": { + "path": { + "tag": "Field", + "model": "FormSubmission", + "field": "Form" + }, + "directive": "relation" + } + }, + { + "tag": "CreateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "FormSubmission", + "field": "Form" + }, + "directive": "relation" + }, + "argument": "fields", + "value": "[formId]" + }, + { + "tag": "CreateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "FormSubmission", + "field": "Form" + }, + "directive": "relation" + }, + "argument": "references", + "value": "[id]" + }, + { + "tag": "CreateField", + "model": "FormSubmission", + "field": "formId", + "type": "Int", + "arity": "Optional" + }, + { + "tag": "CreateField", + "model": "FormSubmission", + "field": "userId", + "type": "Int", + "arity": "Required" + }, + { + "tag": "CreateModel", + "model": "Answer" + }, + { + "tag": "CreateField", + "model": "Answer", + "field": "id", + "type": "Int", + "arity": "Required" + }, + { + "tag": "CreateDirective", + "location": { + "path": { + "tag": "Field", + "model": "Answer", + "field": "id" + }, + "directive": "id" + } + }, + { + "tag": "CreateField", + "model": "Answer", + "field": "userInput", + "type": "String", + "arity": "Required" + }, + { + "tag": "CreateField", + "model": "Answer", + "field": "userChoise", + "type": "Int", + "arity": "Required" + }, + { + "tag": "CreateField", + "model": "Answer", + "field": "type", + "type": "AnswerType", + "arity": "Required" + }, + { + "tag": "CreateField", + "model": "Answer", + "field": "FormSubmission", + "type": "FormSubmission", + "arity": "Optional" + }, + { + "tag": "CreateDirective", + "location": { + "path": { + "tag": "Field", + "model": "Answer", + "field": "FormSubmission" + }, + "directive": "relation" + } + }, + { + "tag": "CreateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "Answer", + "field": "FormSubmission" + }, + "directive": "relation" + }, + "argument": "fields", + "value": "[formSubmissionId]" + }, + { + "tag": "CreateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "Answer", + "field": "FormSubmission" + }, + "directive": "relation" + }, + "argument": "references", + "value": "[id]" + }, + { + "tag": "CreateField", + "model": "Answer", + "field": "formSubmissionId", + "type": "Int", + "arity": "Optional" + }, { "tag": "CreateModel", "model": "User" @@ -45,31 +734,6 @@ "directive": "id" } }, - { - "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()" - }, { "tag": "CreateField", "model": "User", @@ -80,472 +744,16 @@ { "tag": "CreateField", "model": "User", - "field": "email", - "type": "String", - "arity": "Optional" + "field": "forms", + "type": "Form", + "arity": "List" }, { "tag": "CreateField", "model": "User", - "field": "createdAt", - "type": "DateTime", - "arity": "Required" - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "User", - "field": "createdAt" - }, - "directive": "default" - } - }, - { - "tag": "CreateArgument", - "location": { - "tag": "Directive", - "path": { - "tag": "Field", - "model": "User", - "field": "createdAt" - }, - "directive": "default" - }, - "argument": "", - "value": "now()" - }, - { - "tag": "CreateField", - "model": "User", - "field": "polls", - "type": "Poll", + "field": "formsSubmissions", + "type": "FormSubmission", "arity": "List" - }, - { - "tag": "CreateModel", - "model": "Poll" - }, - { - "tag": "CreateField", - "model": "Poll", - "field": "id", - "type": "Int", - "arity": "Required" - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "Poll", - "field": "id" - }, - "directive": "id" - } - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "Poll", - "field": "id" - }, - "directive": "default" - } - }, - { - "tag": "CreateArgument", - "location": { - "tag": "Directive", - "path": { - "tag": "Field", - "model": "Poll", - "field": "id" - }, - "directive": "default" - }, - "argument": "", - "value": "autoincrement()" - }, - { - "tag": "CreateField", - "model": "Poll", - "field": "User", - "type": "User", - "arity": "Optional" - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "Poll", - "field": "User" - }, - "directive": "relation" - } - }, - { - "tag": "CreateArgument", - "location": { - "tag": "Directive", - "path": { - "tag": "Field", - "model": "Poll", - "field": "User" - }, - "directive": "relation" - }, - "argument": "fields", - "value": "[userId]" - }, - { - "tag": "CreateArgument", - "location": { - "tag": "Directive", - "path": { - "tag": "Field", - "model": "Poll", - "field": "User" - }, - "directive": "relation" - }, - "argument": "references", - "value": "[id]" - }, - { - "tag": "CreateField", - "model": "Poll", - "field": "userId", - "type": "Int", - "arity": "Optional" - }, - { - "tag": "CreateField", - "model": "Poll", - "field": "title", - "type": "String", - "arity": "Required" - }, - { - "tag": "CreateField", - "model": "Poll", - "field": "description", - "type": "String", - "arity": "Optional" - }, - { - "tag": "CreateField", - "model": "Poll", - "field": "slug", - "type": "String", - "arity": "Required" - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "Poll", - "field": "slug" - }, - "directive": "unique" - } - }, - { - "tag": "CreateField", - "model": "Poll", - "field": "questions", - "type": "Question", - "arity": "List" - }, - { - "tag": "CreateField", - "model": "Poll", - "field": "createdAt", - "type": "DateTime", - "arity": "Required" - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "Poll", - "field": "createdAt" - }, - "directive": "default" - } - }, - { - "tag": "CreateArgument", - "location": { - "tag": "Directive", - "path": { - "tag": "Field", - "model": "Poll", - "field": "createdAt" - }, - "directive": "default" - }, - "argument": "", - "value": "now()" - }, - { - "tag": "CreateModel", - "model": "Question" - }, - { - "tag": "CreateField", - "model": "Question", - "field": "id", - "type": "Int", - "arity": "Required" - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "Question", - "field": "id" - }, - "directive": "id" - } - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "Question", - "field": "id" - }, - "directive": "default" - } - }, - { - "tag": "CreateArgument", - "location": { - "tag": "Directive", - "path": { - "tag": "Field", - "model": "Question", - "field": "id" - }, - "directive": "default" - }, - "argument": "", - "value": "autoincrement()" - }, - { - "tag": "CreateField", - "model": "Question", - "field": "Poll", - "type": "Poll", - "arity": "Optional" - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "Question", - "field": "Poll" - }, - "directive": "relation" - } - }, - { - "tag": "CreateArgument", - "location": { - "tag": "Directive", - "path": { - "tag": "Field", - "model": "Question", - "field": "Poll" - }, - "directive": "relation" - }, - "argument": "fields", - "value": "[pollId]" - }, - { - "tag": "CreateArgument", - "location": { - "tag": "Directive", - "path": { - "tag": "Field", - "model": "Question", - "field": "Poll" - }, - "directive": "relation" - }, - "argument": "references", - "value": "[id]" - }, - { - "tag": "CreateField", - "model": "Question", - "field": "pollId", - "type": "Int", - "arity": "Optional" - }, - { - "tag": "CreateField", - "model": "Question", - "field": "title", - "type": "String", - "arity": "Required" - }, - { - "tag": "CreateField", - "model": "Question", - "field": "variants", - "type": "Variant", - "arity": "List" - }, - { - "tag": "CreateModel", - "model": "Variant" - }, - { - "tag": "CreateField", - "model": "Variant", - "field": "id", - "type": "Int", - "arity": "Required" - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "Variant", - "field": "id" - }, - "directive": "id" - } - }, - { - "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": "CreateField", - "model": "Variant", - "field": "Question", - "type": "Question", - "arity": "Optional" - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "Variant", - "field": "Question" - }, - "directive": "relation" - } - }, - { - "tag": "CreateArgument", - "location": { - "tag": "Directive", - "path": { - "tag": "Field", - "model": "Variant", - "field": "Question" - }, - "directive": "relation" - }, - "argument": "fields", - "value": "[questionId]" - }, - { - "tag": "CreateArgument", - "location": { - "tag": "Directive", - "path": { - "tag": "Field", - "model": "Variant", - "field": "Question" - }, - "directive": "relation" - }, - "argument": "references", - "value": "[id]" - }, - { - "tag": "CreateField", - "model": "Variant", - "field": "questionId", - "type": "Int", - "arity": "Optional" - }, - { - "tag": "CreateField", - "model": "Variant", - "field": "text", - "type": "String", - "arity": "Required" - }, - { - "tag": "CreateField", - "model": "Variant", - "field": "count", - "type": "Int", - "arity": "Required" - }, - { - "tag": "CreateDirective", - "location": { - "path": { - "tag": "Field", - "model": "Variant", - "field": "count" - }, - "directive": "default" - } - }, - { - "tag": "CreateArgument", - "location": { - "tag": "Directive", - "path": { - "tag": "Field", - "model": "Variant", - "field": "count" - }, - "directive": "default" - }, - "argument": "", - "value": "0" } ] } \ No newline at end of file diff --git a/prisma/migrations/20201006185953-improved-schema-structure/README.md b/prisma/migrations/20201006185953-improved-schema-structure/README.md new file mode 100644 index 0000000..5238480 --- /dev/null +++ b/prisma/migrations/20201006185953-improved-schema-structure/README.md @@ -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[] +-} +``` + + diff --git a/prisma/migrations/20201006185953-improved-schema-structure/schema.prisma b/prisma/migrations/20201006185953-improved-schema-structure/schema.prisma new file mode 100644 index 0000000..c179522 --- /dev/null +++ b/prisma/migrations/20201006185953-improved-schema-structure/schema.prisma @@ -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 +} diff --git a/prisma/migrations/20201006185953-improved-schema-structure/steps.json b/prisma/migrations/20201006185953-improved-schema-structure/steps.json new file mode 100644 index 0000000..1dc082b --- /dev/null +++ b/prisma/migrations/20201006185953-improved-schema-structure/steps.json @@ -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()" + } + ] +} \ No newline at end of file diff --git a/prisma/migrations/migrate.lock b/prisma/migrations/migrate.lock index 0a8e6d9..c1de62a 100644 --- a/prisma/migrations/migrate.lock +++ b/prisma/migrations/migrate.lock @@ -1,3 +1,4 @@ # Prisma Migrate lockfile v1 -20201003131039-initial-structure \ No newline at end of file +20201006125838-initial-migration +20201006185953-improved-schema-structure \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index c9f7611..841fd90 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -2,45 +2,90 @@ // learn more about it in the docs: https://pris.ly/d/prisma-schema datasource db { - provider = "sqlite" - url = "file:./dev.db" + provider = "postgres" + url = env("DATABASE_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 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 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? +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 { - id Int @id @default(autoincrement()) - Question Question? @relation(fields: [questionId], references: [id]) - questionId Int? - text String - count Int @default(0) + 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 } diff --git a/src/index.ts b/src/index.ts index cc2c64b..e69de29 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,14 +0,0 @@ -import { GraphQLServer } from "graphql-yoga" - -const typeDefs = `` - -const resolvers = {} - -const server = new GraphQLServer({ - typeDefs, - resolvers, -}) - -server.start(({ port }) => - console.log(`Server is running on http://localhost:${port}`) -) diff --git a/src/typeDefs.graphql b/src/typeDefs.graphql new file mode 100644 index 0000000..5ab1fed --- /dev/null +++ b/src/typeDefs.graphql @@ -0,0 +1,53 @@ +type Query { + forms: [Form] + form(id: Int!): Form! +} + +type Form { + id: Int! + title: String! + choisesQuestions: [ChoisesQuestion!]! + inputQuestions: [InputQuestion!]! + submissions: [FormSubmission!]! + dateCreated: String! +} + +type ChoisesQuestion { + title: String! + variants: [Variant!]! + type: ChoiseType! + number: Int! +} + +type Variant { + text: String! +} + +type InputQuestion { + title: String! + number: Int! +} + +type FormSubmission { + id: Int! + answers: [Answer!]! + date: String! +} + +type Answer { + id: Int! + userInput: String + userChoise: Int + type: AnswerType! +} + +enum ChoiseType { + SELECT + CHECK + CHOOSE +} + +enum AnswerType { + INPUT + CHOISE +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..c9f603c --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,69 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ + "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ + // "lib": [], /* Specify library files to be included in the compilation. */ + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + // "outDir": "./", /* Redirect output structure to the directory. */ + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + + /* Advanced Options */ + "skipLibCheck": true, /* Skip type checking of declaration files. */ + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + } +}