172 lines
4.0 KiB
Markdown
172 lines
4.0 KiB
Markdown
# Modelo de datos — Entidades y esquema sugerido
|
||
|
||
## Diagrama ER (texto)
|
||
|
||
Game ↔ RomFile (1‑N)
|
||
Game ↔ Artwork (1‑N)
|
||
Game ↔ Platform (N‑N)
|
||
Game ↔ Tag (N‑N)
|
||
Game ↔ Purchase (1‑N)
|
||
Game ↔ PriceHistory (1‑N)
|
||
|
||
---
|
||
|
||
## Entidades principales (campos sugeridos)
|
||
|
||
### Game
|
||
|
||
- `id` (cuid) — identificador.
|
||
- `title` (string) — nombre principal.
|
||
- `slug` (string) — único, legible.
|
||
- `description` (text) — opcional.
|
||
- `releaseDate` (DateTime?) — fecha principal.
|
||
- `igdbId`, `rawgId`, `thegamesdbId` (Int?) — ids externos.
|
||
- `extra` (Json?) — campos flexibles.
|
||
- `createdAt`, `updatedAt`.
|
||
|
||
### Platform
|
||
|
||
- `id`, `name`, `slug`, `generation`.
|
||
|
||
### RomFile
|
||
|
||
- `id`, `path`, `filename`, `checksum` (unique), `size` (int), `format`, `hashes` (Json opcional), `status` (active/missing), `addedAt`, `lastSeenAt`, `gameId`.
|
||
|
||
### Artwork
|
||
|
||
- `id`, `gameId`, `type` (cover/screenshot), `sourceUrl`, `localPath`, `width`, `height`, `fetchedAt`.
|
||
|
||
### Purchase
|
||
|
||
- `id`, `gameId`, `priceCents` (int), `currency`, `store`, `date`, `receiptPath`.
|
||
|
||
### PriceHistory
|
||
|
||
- `id`, `gameId`, `priceCents`, `currency`, `recordedAt`, `source`.
|
||
|
||
### Tag
|
||
|
||
- `id`, `name` (unique), color.
|
||
|
||
### User (opcional)
|
||
|
||
- `id`, `name`, `email` (unique), `passwordHash`, `role`.
|
||
|
||
---
|
||
|
||
## Índices y constraints recomendados
|
||
|
||
- `RomFile.checksum` — **UNIQUE** (detectar duplicados).
|
||
- `Game`: índice por `title` y `slug` (`slug` único).
|
||
- Composite unique sugerido: `[primaryPlatformId, title, releaseDate]` para evitar duplicados de una misma versión/plataforma.
|
||
- Índices para búsquedas frecuentes (title, platform, tags).
|
||
|
||
---
|
||
|
||
## Fragmento `schema.prisma` (ejemplo)
|
||
|
||
```prisma
|
||
datasource db {
|
||
provider = "postgresql" // para dev puede usarse sqlite
|
||
url = env("DATABASE_URL")
|
||
}
|
||
|
||
generator client {
|
||
provider = "prisma-client-js"
|
||
}
|
||
|
||
model Game {
|
||
id String @id @default(cuid())
|
||
title String
|
||
slug String @unique
|
||
description String?
|
||
releaseDate DateTime?
|
||
igdbId Int? @unique
|
||
rawgId Int? @unique
|
||
thegamesdbId Int? @unique
|
||
platforms Platform[]
|
||
romFiles RomFile[]
|
||
artworks Artwork[]
|
||
tags Tag[]
|
||
extra Json?
|
||
createdAt DateTime @default(now())
|
||
updatedAt DateTime @updatedAt
|
||
@@index([title])
|
||
@@unique([slug])
|
||
}
|
||
|
||
model Platform {
|
||
id String @id @default(cuid())
|
||
name String @unique
|
||
slug String @unique
|
||
games Game[]
|
||
}
|
||
|
||
model RomFile {
|
||
id String @id @default(cuid())
|
||
path String
|
||
filename String
|
||
checksum String @unique
|
||
size Int
|
||
format String
|
||
hashes Json?
|
||
game Game? @relation(fields: [gameId], references: [id])
|
||
gameId String?
|
||
addedAt DateTime @default(now())
|
||
lastSeenAt DateTime?
|
||
status String @default("active")
|
||
@@index([checksum])
|
||
}
|
||
|
||
model Artwork {
|
||
id String @id @default(cuid())
|
||
game Game @relation(fields: [gameId], references: [id])
|
||
gameId String
|
||
type String
|
||
sourceUrl String
|
||
localPath String?
|
||
width Int?
|
||
height Int?
|
||
fetchedAt DateTime @default(now())
|
||
}
|
||
|
||
model Purchase {
|
||
id String @id @default(cuid())
|
||
game Game @relation(fields: [gameId], references: [id])
|
||
gameId String
|
||
priceCents Int
|
||
currency String
|
||
store String?
|
||
date DateTime
|
||
receiptPath String?
|
||
}
|
||
|
||
model Tag {
|
||
id String @id @default(cuid())
|
||
name String @unique
|
||
games Game[]
|
||
}
|
||
```
|
||
|
||
> Nota: para monedas se recomienda almacenar `priceCents` (int) para compatibilidad; si se usa Postgres se puede optar por `Decimal`.
|
||
|
||
---
|
||
|
||
## Migraciones y evolución del esquema
|
||
|
||
- Usar **Prisma Migrate** para versionar cambios.
|
||
- Preferir migraciones no destructivas (añadir columnas `NULL` y rellenarlas en background).
|
||
- Mantener seeds de desarrollo para pruebas manuales y reproducibles.
|
||
|
||
---
|
||
|
||
## Fuentes
|
||
|
||
- Prisma schema conventions, patterns para modelado relacional y técnicas de deduplicación de archivos.
|
||
|
||
---
|
||
|
||
**Metadatos**
|
||
Autor: Quasar (investigación automatizada)
|
||
Última actualización: 2026-02-07
|