feat(prisma): define models for Url, Property, Item, ItemProperty, SelectedProperty, and DeletedProperty
This commit is contained in:
parent
d171cf7b62
commit
fe92d175a6
1 changed files with 87 additions and 1 deletions
|
@ -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")
|
||||
}
|
Loading…
Add table
Reference in a new issue