189 lines
6.7 KiB
Markdown
189 lines
6.7 KiB
Markdown
# Migration `20201029214206-rejig-schema`
|
|
|
|
This migration has been generated by Kurt Hutten at 10/30/2020, 8:42:06 AM.
|
|
You can check out the [state of the schema](./schema.prisma) after the migration.
|
|
|
|
# explanation
|
|
|
|
The previous schema was really just thrown together to progress with parts of the client.
|
|
No relations had been included so this change in reality can be consider the initial schema.
|
|
|
|
## Database Steps
|
|
|
|
```sql
|
|
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")
|
|
)
|
|
|
|
PRAGMA foreign_keys=OFF;
|
|
CREATE TABLE "new_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 DEFAULT CURRENT_TIMESTAMP,
|
|
"authorUserName" TEXT NOT NULL DEFAULT 'irevdev',
|
|
|
|
FOREIGN KEY ("authorUserName") REFERENCES "User"("userName") ON DELETE CASCADE ON UPDATE CASCADE,
|
|
PRIMARY KEY ("title","authorUserName")
|
|
);
|
|
INSERT INTO "new_Part" ("id", "title", "description", "mainImage", "createdAt", "code") SELECT "id", "title", "description", "mainImage", "createdAt", "code" FROM "Part";
|
|
DROP TABLE "Part";
|
|
ALTER TABLE "new_Part" RENAME TO "Part";
|
|
CREATE UNIQUE INDEX "Part.id_unique" ON "Part"("id");
|
|
CREATE UNIQUE INDEX "Part.title_authorUserName_unique" ON "Part"("title", "authorUserName");
|
|
CREATE TABLE "new_User" (
|
|
"userName" TEXT NOT NULL DEFAULT 'irevdev',
|
|
"email" TEXT NOT NULL,
|
|
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"updatedAt" DATETIME NOT NULL,
|
|
"image" TEXT,
|
|
"bio" TEXT,
|
|
PRIMARY KEY ("userName")
|
|
);
|
|
INSERT INTO "new_User" ("email", "createdAt", "updatedAt", "image", "bio") SELECT "email", "createdAt", "updatedAt", "image", "bio" FROM "User";
|
|
DROP TABLE "User";
|
|
ALTER TABLE "new_User" RENAME TO "User";
|
|
CREATE UNIQUE INDEX "User.email_unique" ON "User"("email");
|
|
PRAGMA foreign_key_check;
|
|
PRAGMA foreign_keys=ON
|
|
|
|
CREATE UNIQUE INDEX "PartReaction.emote_userId_partId_unique" ON "PartReaction"("emote", "userId", "partId")
|
|
|
|
PRAGMA foreign_keys=off;
|
|
DROP TABLE "Post";
|
|
PRAGMA foreign_keys=on
|
|
|
|
PRAGMA foreign_keys=off;
|
|
DROP TABLE "Contact";
|
|
PRAGMA foreign_keys=on
|
|
```
|
|
|
|
## Changes
|
|
|
|
```diff
|
|
diff --git schema.prisma schema.prisma
|
|
migration 20201019072122-add-simplify-user-model..20201029214206-rejig-schema
|
|
--- datamodel.dml
|
|
+++ datamodel.dml
|
|
@@ -1,48 +1,76 @@
|
|
datasource DS {
|
|
provider = ["sqlite", "postgresql"]
|
|
- url = "***"
|
|
+ url = "***"
|
|
}
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
binaryTargets = "native"
|
|
}
|
|
-model Post {
|
|
- id Int @id @default(autoincrement())
|
|
- title String
|
|
- body String
|
|
+// 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 @default("irevdev")
|
|
+ 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 Int @id @default(autoincrement())
|
|
- title String
|
|
- description String // markdown string
|
|
- code String @default("// Welcome to Cascade Studio! Here are some useful functions:\n// Translate(), Rotate(), Scale(), Union(), Difference(), Intersection()\n// Box(), Sphere(), Cylinder(), Cone(), Text3D(), Polygon()\n// Offset(), Extrude(), RotatedExtrude(), Revolve(), Pipe(), Loft(),\n// FilletEdges(), ChamferEdges(),\n// Slider(), Button(), Checkbox()\nlet holeRadius = Slider(\"Radius\", 30 , 20 , 40);\nlet sphere = Sphere(50);\nlet cylinderZ = Cylinder(holeRadius, 200, true);\nlet cylinderY = Rotate([0,1,0], 90, Cylinder(holeRadius, 200, true));\nlet cylinderX = Rotate([1,0,0], 90, Cylinder(holeRadius, 200, true));\nTranslate([0, 0, 50], Difference(sphere, [cylinderX, cylinderY, cylinderZ]));\n\nTranslate([-25, 0, 40], Text3D(\"Hi!\"));\n// Don't forget to push imported or oc-defined shapes into sceneShapes to add them to the workspace!")
|
|
- mainImage String // link to cloudinary
|
|
- createdAt DateTime @default(now())
|
|
- // userId
|
|
- //likes, comments, reactions
|
|
+ id String @unique @default(uuid())
|
|
+ title String
|
|
+ description String? // markdown string
|
|
+ code String?
|
|
+ mainImage String? // link to cloudinary
|
|
+ createdAt DateTime @default(now())
|
|
+ updatedAt DateTime @default(now()) @updatedAt
|
|
+ author User @relation(fields: [authorUserName], references: [userName])
|
|
+ authorUserName String @default("irevdev")
|
|
+
|
|
+ Comment Comment[]
|
|
+ Reaction PartReaction[]
|
|
+ @@id([title, authorUserName])
|
|
+ @@unique([title, authorUserName])
|
|
}
|
|
-model Contact {
|
|
- id Int @id @default(autoincrement())
|
|
- name String
|
|
- email String
|
|
- message String
|
|
+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 User {
|
|
- id Int @id @default(autoincrement())
|
|
- email String @unique
|
|
- // userName String @unique
|
|
- // issuer String @unique
|
|
+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
|
|
-
|
|
- image String? // url maybe id or file storage service? cloudinary?
|
|
- bio String? //mark down
|
|
}
|
|
```
|
|
|
|
|