Skip to content

Commit

Permalink
feat(prisma): rename "set" model to "board"
Browse files Browse the repository at this point in the history
This patch fixes an issue where the `Set` model name would conflict with
the built-in class names in Python and cause the Python Prisma client to
fail. This is a temporary fix, but I also think this will just be easier
to work with in general (as most languages have a `Set` class).

Ref: RobertCraigie/prisma-client-py#842
  • Loading branch information
nicholaschiang committed Dec 21, 2023
1 parent 6ac4aa1 commit 94273fb
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 22 deletions.
72 changes: 72 additions & 0 deletions prisma/migrations/20231124002958_rename_set_to_board/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Warnings:
- You are about to drop the `Set` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `_LookToSet` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `_SetToVariant` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropForeignKey
ALTER TABLE "Set" DROP CONSTRAINT "Set_authorId_fkey";

-- DropForeignKey
ALTER TABLE "_LookToSet" DROP CONSTRAINT "_LookToSet_A_fkey";

-- DropForeignKey
ALTER TABLE "_LookToSet" DROP CONSTRAINT "_LookToSet_B_fkey";

-- DropForeignKey
ALTER TABLE "_SetToVariant" DROP CONSTRAINT "_SetToVariant_A_fkey";

-- DropForeignKey
ALTER TABLE "_SetToVariant" DROP CONSTRAINT "_SetToVariant_B_fkey";

-- DropTable (manually updated to simply rename)
ALTER TABLE "Set" RENAME TO "Board";
ALTER TABLE "Board" RENAME CONSTRAINT "Set_pkey" TO "Board_pkey";

-- DropIndex
DROP INDEX "_LookToSet_AB_unique";

-- DropIndex
DROP INDEX "_LookToSet_B_index";

-- DropTable (manually updated to simply rename)
ALTER TABLE "_LookToSet" RENAME "A" TO "lookId";
ALTER TABLE "_LookToSet" RENAME "B" TO "boardId";
ALTER TABLE "_LookToSet" RENAME "boardId" TO "A";
ALTER TABLE "_LookToSet" RENAME "lookId" TO "B";
ALTER TABLE "_LookToSet" RENAME TO "_BoardToLook";

-- DropTable (manually updated to simply rename)
ALTER TABLE "_SetToVariant" RENAME TO "_BoardToVariant";

-- CreateIndex
CREATE UNIQUE INDEX "Board_name_authorId_key" ON "Board"("name", "authorId");

-- CreateIndex
CREATE UNIQUE INDEX "_BoardToLook_AB_unique" ON "_BoardToLook"("A", "B");

-- CreateIndex
CREATE INDEX "_BoardToLook_B_index" ON "_BoardToLook"("B");

-- CreateIndex
CREATE UNIQUE INDEX "_BoardToVariant_AB_unique" ON "_BoardToVariant"("A", "B");

-- CreateIndex
CREATE INDEX "_BoardToVariant_B_index" ON "_BoardToVariant"("B");

-- AddForeignKey
ALTER TABLE "Board" ADD CONSTRAINT "Board_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_BoardToLook" ADD CONSTRAINT "_BoardToLook_A_fkey" FOREIGN KEY ("A") REFERENCES "Board"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_BoardToLook" ADD CONSTRAINT "_BoardToLook_B_fkey" FOREIGN KEY ("B") REFERENCES "Look"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_BoardToVariant" ADD CONSTRAINT "_BoardToVariant_A_fkey" FOREIGN KEY ("A") REFERENCES "Board"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_BoardToVariant" ADD CONSTRAINT "_BoardToVariant_B_fkey" FOREIGN KEY ("B") REFERENCES "Variant"("id") ON DELETE CASCADE ON UPDATE CASCADE;
51 changes: 29 additions & 22 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ model User {
// The reviews written by the user.
reviews Review[]
// The user's sets (i.e. arbitrary groupings of saved looks).
sets Set[]
// The user's boards (i.e. arbitrary groupings of saved looks).
boards Board[]
// The looks this user has authored.
looks Look[]
Expand Down Expand Up @@ -501,8 +501,8 @@ model Variant {
// are different prices per size. Can be empty if the variant is sold out.
prices Price[]
// The user-curated sets that the product variant is a part of.
sets Set[]
// The user-curated boards that the product variant is a part of.
boards Board[]
// @todo each product can only have a single variant per color and size combo.
}
Expand Down Expand Up @@ -693,49 +693,56 @@ model Product {
// @todo products must have a unique name per brand(s).
}

// A set is an arbitrary grouping of looks created by a user to act as a sort of
// mood board. Users can "save" looks that they like to a "set" that can then be
// shared with other users. Users can discover sets by other users (e.g. I see a
// look that I like and then expore all the sets that include that look to find
// A board is an arbitrary grouping of looks created by a user to act as a sort of
// mood board. Users can "save" looks that they like to a "board" that can then be
// shared with other users. Users can discover boards by other users (e.g. I see a
// look that I like and then expore all the boards that include that look to find
// similar looks).
//
// Sets are separate from collections for simplicity. Collections are officially
// curated by a brand while sets are simple groupings of looks and products
// Boards are separate from collections for simplicity. Collections are officially
// curated by a brand while boards are simple groupings of looks and products
// created by users. I may opt to combine these two data models in the future,
// but for now, simply adding an additional data model was easiest.
//
// Users can import looks and products from anywhere to add to their sets (e.g.
// Users can import looks and products from anywhere to add to their boards (e.g.
// if I see an outfit I like on Instagram, I can click "share" to DOLCE and the
// app will add it as a look to the selected set... that look will then be
// app will add it as a look to the selected board... that look will then be
// automatically augmented with possible products to purchase).
//
// The name "set" was inspired by the website "Polyvore" which allowed users to
// add products to a shared index called a "set".
// @see {@link https://en.wikipedia.org/wiki/Polyvore}
model Set {
//
// NOTE: This model was renamed "Board" so as to not conflict with the language
// built-in "Set" class. This was causing issues with the Python Prisma client.
// @see {@link https://github.com/RobertCraigie/prisma-client-py/issues/842}
model Board {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
// The set's name (e.g. "Summer Essentials").
// The board's name (e.g. "Summer Essentials").
name String
// The set's description.
// The board's description.
description String?
// The set's author (i.e. the user who created the set).
// @todo I should support multiple author(s) for a set (i.e. shared "sets") or
// The board's author (i.e. the user who created the board).
// @todo I should support multiple author(s) for a board (i.e. shared "boards") or
// perhaps advanced access control (i.e. users who can view, can edit, etc).
author User @relation(fields: [authorId], references: [id], onDelete: Cascade, onUpdate: Cascade)
authorId Int
// The set's looks.
// The board's looks.
looks Look[]
// The set's product variants.
// The board's product variants.
// @todo perhaps we should also allow users to add products to a board without
// having to select a specific size and/or color (e.g. when they're adding
// products from the products list, they do not select a size)?
variants Variant[]
// A user can only have one set with a given name.
// A user can only have one board with a given name.
@@unique([name, authorId])
}

Expand Down Expand Up @@ -882,8 +889,8 @@ model Look {
// The look's picture (if known).
images Image[]
// The user-curated sets that the look is a part of.
sets Set[]
// The user-curated boards that the look is a part of.
boards Board[]
// Each look must have a unique number in the show or by the author.
@@unique([showId, number])
Expand Down

0 comments on commit 94273fb

Please sign in to comment.