Skip to content

Commit

Permalink
feat: user attributes table (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
HungLV46 authored Aug 16, 2024
1 parent 84be06e commit 3c8c7fa
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Warnings:
- A unique constraint covering the columns `[product_id,collection_id]` on the table `product_collections` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateTable
CREATE TABLE "user_attributes" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"value" TEXT NOT NULL,
"user_id" INTEGER NOT NULL,

CONSTRAINT "user_attributes_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE INDEX "user_attributes_name_value_idx" ON "user_attributes"("name", "value");

-- CreateIndex
CREATE INDEX "user_attributes_user_id_idx" ON "user_attributes"("user_id");

-- CreateIndex
CREATE UNIQUE INDEX "user_attributes_name_value_user_id_key" ON "user_attributes"("name", "value", "user_id");

-- CreateIndex
CREATE UNIQUE INDEX "product_collections_product_id_collection_id_key" ON "product_collections"("product_id", "collection_id");

-- AddForeignKey
ALTER TABLE "user_attributes" ADD CONSTRAINT "user_attributes_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
18 changes: 17 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,28 @@ model User {
banner_img String
additional_info Json?
products Product[]
products Product[]
user_attributes UserAttribute[]
@@index(name)
@@index(wallet_address)
@@map("users")
}

model UserAttribute {
id Int @id @default(autoincrement())
name String
value String
user_id Int
user User @relation(fields: [user_id], references: [id])
@@unique([name, value, user_id])
@@index([name, value])
@@index(user_id)
@@map("user_attributes")
}

model Product {
id Int @id @default(autoincrement())
name String
Expand Down Expand Up @@ -109,6 +124,7 @@ model ProductCollection {
product Product @relation(fields: [product_id], references: [id])
collection Collection @relation(fields: [collection_id], references: [id])
@@unique([product_id, collection_id])
@@index([product_id])
@@index([collection_id])
@@map("product_collections")
Expand Down

0 comments on commit 3c8c7fa

Please sign in to comment.