From fe92d175a62ed3b7da01d3ca14fee0eaf5348601 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 18 Jun 2025 14:22:17 +0300 Subject: [PATCH] feat(prisma): define models for Url, Property, Item, ItemProperty, SelectedProperty, and DeletedProperty --- prisma/schema.prisma | 88 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 0972a97..cf2308c 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -8,5 +8,91 @@ generator client { datasource db { provider = "sqlite" - url = env("DATABASE_URL") + url = "file:./dev.db" } + +// URLs table - Each comparison page has its own URL +model Url { + id Int @id @default(autoincrement()) + url String @unique + createdAt DateTime @default(now()) @map("created_at") + + // Relations + items Item[] + selectedProperties SelectedProperty[] + deletedProperties DeletedProperty[] + + @@map("urls") +} + +// Properties table - All available properties (core + custom) +model Property { + id Int @id @default(autoincrement()) + name String @unique + globalUsageCount Int @default(0) @map("global_usage_count") + + // Relations + itemProperties ItemProperty[] + selectedProperties SelectedProperty[] + deletedProperties DeletedProperty[] + + @@map("properties") +} + +// Items table - Individual items that can appear in multiple URLs +model Item { + id String @id + urlId Int @map("url_id") + wikidataId String? @map("wikidata_id") + itemOrder Int @default(0) @map("item_order") + globalItemId String @unique @map("global_item_id") + + // Relations + url Url @relation(fields: [urlId], references: [id], onDelete: Cascade) + itemProperties ItemProperty[] @relation("ItemToItemProperty") + deletedProperties DeletedProperty[] + + @@map("items") +} + +// Junction table for item properties (including core properties like name, description) +model ItemProperty { + globalItemId String @map("global_item_id") + propertyId Int @map("property_id") + value String + + // Relations + item Item @relation("ItemToItemProperty", fields: [globalItemId], references: [globalItemId], onDelete: Cascade) + property Property @relation(fields: [propertyId], references: [id], onDelete: Cascade) + + @@id([globalItemId, propertyId]) + @@map("item_properties") +} + +// Selected properties for each URL (excludes core properties) +model SelectedProperty { + urlId Int @map("url_id") + propertyId Int @map("property_id") + + // Relations + url Url @relation(fields: [urlId], references: [id], onDelete: Cascade) + property Property @relation(fields: [propertyId], references: [id], onDelete: Cascade) + + @@id([urlId, propertyId]) + @@map("selected_properties") +} + +// Soft delete tracking for properties per URL +model DeletedProperty { + urlId Int @map("url_id") + globalItemId String @map("global_item_id") + propertyId Int @map("property_id") + + // Relations + url Url @relation(fields: [urlId], references: [id], onDelete: Cascade) + item Item @relation(fields: [globalItemId], references: [globalItemId], onDelete: Cascade) + property Property @relation(fields: [propertyId], references: [id], onDelete: Cascade) + + @@id([urlId, globalItemId, propertyId]) + @@map("deleted_properties") +} \ No newline at end of file