Changed prisma schema and migrated changes

This commit is contained in:
2020-10-03 18:30:35 +05:00
parent 29c80e0fe0
commit 7770685f4b
8 changed files with 814 additions and 2 deletions

View File

@ -0,0 +1,103 @@
# 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

@ -0,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

@ -0,0 +1,551 @@
{
"version": "0.3.14-fixed",
"steps": [
{
"tag": "CreateSource",
"source": "db"
},
{
"tag": "CreateArgument",
"location": {
"tag": "Source",
"source": "db"
},
"argument": "provider",
"value": "\"sqlite\""
},
{
"tag": "CreateArgument",
"location": {
"tag": "Source",
"source": "db"
},
"argument": "url",
"value": "\"***\""
},
{
"tag": "CreateModel",
"model": "User"
},
{
"tag": "CreateField",
"model": "User",
"field": "id",
"type": "Int",
"arity": "Required"
},
{
"tag": "CreateDirective",
"location": {
"path": {
"tag": "Field",
"model": "User",
"field": "id"
},
"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",
"field": "name",
"type": "String",
"arity": "Required"
},
{
"tag": "CreateField",
"model": "User",
"field": "email",
"type": "String",
"arity": "Optional"
},
{
"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",
"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"
}
]
}