Wiped out the DB to get the migration to work

This commit is contained in:
Kurt Hutten
2020-10-30 17:21:06 +11:00
parent 62d26aea45
commit fa0f42d88b
8 changed files with 1236 additions and 31 deletions

View File

@@ -0,0 +1,91 @@
# Migration `20201030061957-rejig-schema`
This migration has been generated by Kurt Hutten at 10/30/2020, 5:19:57 PM.
You can check out the [state of the schema](./schema.prisma) after the migration.
## Database Steps
```sql
CREATE TABLE "User" (
"userName" TEXT NOT NULL,
"email" TEXT NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
"image" TEXT,
"bio" TEXT,
PRIMARY KEY ("userName")
)
CREATE TABLE "Part" (
"id" TEXT NOT NULL,
"title" TEXT NOT NULL,
"description" TEXT,
"code" TEXT,
"mainImage" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
"authorUserName" TEXT NOT NULL,
FOREIGN KEY ("authorUserName") REFERENCES "User"("userName") ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY ("title","authorUserName")
)
CREATE TABLE "PartReaction" (
"emote" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"partId" TEXT NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
FOREIGN KEY ("userId") REFERENCES "User"("userName") ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY ("partId") REFERENCES "Part"("id") ON DELETE CASCADE ON UPDATE CASCADE
)
CREATE TABLE "Comment" (
"id" TEXT NOT NULL,
"text" TEXT NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
FOREIGN KEY ("id") REFERENCES "User"("userName") ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY ("id") REFERENCES "Part"("id") ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY ("id")
)
CREATE UNIQUE INDEX "User.email_unique" ON "User"("email")
CREATE UNIQUE INDEX "Part.id_unique" ON "Part"("id")
CREATE UNIQUE INDEX "Part.title_authorUserName_unique" ON "Part"("title", "authorUserName")
CREATE UNIQUE INDEX "PartReaction.emote_userId_partId_unique" ON "PartReaction"("emote", "userId", "partId")
```
## Changes
```diff
diff --git schema.prisma schema.prisma
migration 20201029214206-rejig-schema..20201030061957-rejig-schema
--- datamodel.dml
+++ datamodel.dml
@@ -1,7 +1,7 @@
datasource DS {
provider = ["sqlite", "postgresql"]
- url = "***"
+ url = "***"
}
generator client {
provider = "prisma-client-js"
@@ -19,9 +19,9 @@
// JSCAD
// }
model User {
- userName String @id @default(uuid())
+ userName String @id
email String @unique
// role should probably be a list [] and also use enums, neither are supported by sqllight, so we need to set up postgresql in dev
// maybe let netlify handle roles for now.
// role String @default("user")
```

View File

@@ -0,0 +1,76 @@
datasource DS {
provider = ["sqlite", "postgresql"]
url = "***"
}
generator client {
provider = "prisma-client-js"
binaryTargets = "native"
}
// sqlLight does not suport enums so we can't use enums until we set up postgresql in dev mode
// enum Role {
// USER
// ADMIN
// }
// enum PartType {
// CASCADESTUDIO
// JSCAD
// }
model User {
userName String @id
email String @unique
// role should probably be a list [] and also use enums, neither are supported by sqllight, so we need to set up postgresql in dev
// maybe let netlify handle roles for now.
// role String @default("user")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
image String? // url maybe id or file storage service? cloudinary?
bio String? //mark down
Part Part[]
Reaction PartReaction[]
Comment Comment[]
}
model Part {
id String @unique @default(uuid())
title String
description String? // markdown string
code String?
mainImage String? // link to cloudinary
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
author User @relation(fields: [authorUserName], references: [userName])
authorUserName String
Comment Comment[]
Reaction PartReaction[]
@@id([title, authorUserName])
@@unique([title, authorUserName])
}
model PartReaction {
emote String // an emoji
userId String
user User @relation(fields: [userId], references: [userName])
partId String
part Part @relation(fields: [partId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([emote, userId, partId])
}
model Comment {
id String @id @default(uuid())
text String // the comment, should I allow mark down?
user User @relation(fields: [id], references: [userName])
part Part @relation(fields: [id], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

View File

@@ -0,0 +1,38 @@
{
"version": "0.3.14-fixed",
"steps": [
{
"tag": "DeleteDirective",
"location": {
"path": {
"tag": "Field",
"model": "Part",
"field": "updatedAt"
},
"directive": "default"
}
},
{
"tag": "DeleteDirective",
"location": {
"path": {
"tag": "Field",
"model": "Part",
"field": "authorUserName"
},
"directive": "default"
}
},
{
"tag": "DeleteDirective",
"location": {
"path": {
"tag": "Field",
"model": "User",
"field": "userName"
},
"directive": "default"
}
}
]
}