From 3c8c7fa12c8f4737a24f11659c2c01d123b881d6 Mon Sep 17 00:00:00 2001 From: HungLV46 <44282860+HungLV46@users.noreply.github.com> Date: Fri, 16 Aug 2024 15:59:38 +0700 Subject: [PATCH] feat: user attributes table (#5) --- .../migration.sql | 30 +++++++++++++++++++ prisma/schema.prisma | 18 ++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 prisma/migrations/20240816085726_create_user_attributes/migration.sql diff --git a/prisma/migrations/20240816085726_create_user_attributes/migration.sql b/prisma/migrations/20240816085726_create_user_attributes/migration.sql new file mode 100644 index 0000000..4c45e9d --- /dev/null +++ b/prisma/migrations/20240816085726_create_user_attributes/migration.sql @@ -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; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 728715e..c1b3a46 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -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 @@ -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")