Updated the Obsidian docs-vault
This commit is contained in:
1 parent
72fd77ee01
commit
260282a0e2
36 files changed
+3497
-144
No files matched your search
+102
-11
@@ -1,21 +1,112 @@
|
||||
---
|
||||
title: Database
|
||||
tags:
|
||||
- backend
|
||||
- database
|
||||
- mysql
|
||||
- sequelize
|
||||
---
|
||||
|
||||
# Database
|
||||
|
||||
## Overview
|
||||
|
||||
MySQL database named "Showzy", managed by Sequelize ORM. Schema sync uses `{ alter: doUpdate }` where `doUpdate = false` by default.
|
||||
MySQL database named **Showzy**, managed by Sequelize 6 ORM.
|
||||
|
||||
## Key Models
|
||||
- Connection: `localhost`, user `root`, password `password`
|
||||
- Sync mode: `sequelize.sync({ alter: false })` — no auto-alter in production
|
||||
- Logging: writes SQL to `sequelize.log`
|
||||
- Genre seeding: 27 TMDB genres auto-seeded on startup
|
||||
|
||||
- `Entry` — Movies and TV series
|
||||
- `Season` — TV seasons (belongs to Entry)
|
||||
- `Episode` — TV episodes (belongs to Season)
|
||||
- `EntrySeen` — Movie watch records (has `accuracy` field: EXACT, ESTIMATED, UNKNOWN)
|
||||
- `EpisodeSeen` — Episode watch records (has `accuracy` field: EXACT, ESTIMATED, UNKNOWN)
|
||||
- `Media` — Image file references (posters, logos, backdrops, stills)
|
||||
- `Collection`, `Genre`, `Network`, `People`, `Credit`, `Franchise`
|
||||
## Entity Relationship Diagram
|
||||
|
||||
```mermaid
|
||||
erDiagram
|
||||
Entry ||--o| EntryId : has
|
||||
Entry ||--o| EntryRating : has
|
||||
Entry ||--o{ EntrySeen : has
|
||||
Entry ||--o{ Season : has
|
||||
Entry ||--o{ Credit : has
|
||||
Entry }o--o{ Genre : tagged
|
||||
Entry }o--o{ Network : airs-on
|
||||
Entry }o--o{ Collection : belongs-to
|
||||
|
||||
Season ||--o{ Episode : contains
|
||||
Episode ||--o{ EpisodeSeen : has
|
||||
|
||||
Credit }o--|| People : references
|
||||
|
||||
Media ||--|| Entry : polymorphic
|
||||
Media ||--|| Season : polymorphic
|
||||
Media ||--|| Episode : polymorphic
|
||||
Media ||--|| Collection : polymorphic
|
||||
Media ||--|| People : polymorphic
|
||||
```
|
||||
|
||||
## Relationships
|
||||
|
||||
Defined in `backend/config/relations.js`:
|
||||
|
||||
| Source | Target | Type | Through | On Delete |
|
||||
|---|---|---|---|---|
|
||||
| Entry | EntryId | `hasOne` | — | CASCADE |
|
||||
| Entry | EntryRating | `hasOne` | — | CASCADE |
|
||||
| Entry | EntrySeen | `hasMany` | — | CASCADE |
|
||||
| Entry | Season | `hasMany` | — | CASCADE |
|
||||
| Entry | Credit | `hasMany` | — | — |
|
||||
| Entry | Genre | `belongsToMany` | EntryGenre | — |
|
||||
| Entry | Network | `belongsToMany` | EntryNetwork | — |
|
||||
| Entry | Collection | `belongsToMany` | UserCollectionEntry | — |
|
||||
| Season | Episode | `hasMany` | — | CASCADE |
|
||||
| Episode | EpisodeSeen | `hasMany` | — | — |
|
||||
| Credit | People | `belongsTo` | — | — |
|
||||
| Credit | Entry | `belongsTo` | — | — |
|
||||
| People | Credit | `hasMany` (as 'roles') | — | — |
|
||||
| Media | * | Polymorphic scopes | `mediaable` + `mediaableId` | — |
|
||||
|
||||
### Polymorphic Media Scopes
|
||||
|
||||
Media uses `mediaable` (string: 'entry', 'people', 'collection', 'season', 'episode') and `mediaableId` to associate with any entity.
|
||||
|
||||
## Hooks
|
||||
|
||||
Defined in `backend/config/sequelizeHooks.js`:
|
||||
|
||||
- **UserCollectionEntry.afterCreate** — Updates collection `updatedAt`, auto-assigns `order`
|
||||
- **UserCollectionEntry.afterUpdate** — Updates collection `updatedAt`, re-orders other entries
|
||||
- **UserCollectionEntry.afterDestroy** — Updates collection `updatedAt`, cleanup
|
||||
|
||||
## All Models
|
||||
|
||||
See [[Models]] for detailed field definitions of every model.
|
||||
|
||||
### Quick Reference
|
||||
|
||||
| Model | Purpose | Timestamps |
|
||||
|---|---|---|
|
||||
| [[Models#Entry\|Entry]] | Movies and TV series | Yes |
|
||||
| [[Models#Season\|Season]] | TV seasons | Yes |
|
||||
| [[Models#Episode\|Episode]] | TV episodes | Yes |
|
||||
| [[Models#EntrySeen\|EntrySeen]] | Movie watch records | No |
|
||||
| [[Models#EpisodeSeen\|EpisodeSeen]] | Episode watch records | Yes |
|
||||
| [[Models#Media\|Media]] | Polymorphic image records | Yes |
|
||||
| [[Models#Collection\|Collection]] | TMDB + user collections | Yes |
|
||||
| [[Models#UserCollectionEntry\|UserCollectionEntry]] | Collection ↔ Entry join | No |
|
||||
| [[Models#Credit\|Credit]] | Cast/crew credits | Yes |
|
||||
| [[Models#People\|People]] | Person profiles | Yes |
|
||||
| [[Models#EntryId\|EntryId]] | External IDs (TMDB, IMDB, TVDB) | No |
|
||||
| [[Models#EntryRating\|EntryRating]] | Multi-source ratings | No |
|
||||
| [[Models#EntryGenre\|EntryGenre]] | Entry ↔ Genre join | No |
|
||||
| [[Models#EntryNetwork\|EntryNetwork]] | Entry ↔ Network join | No |
|
||||
| [[Models#Genre\|Genre]] | Genres (seeded from TMDB) | No |
|
||||
| [[Models#Network\|Network]] | TV networks | No |
|
||||
| [[Models#Franchise\|Franchise]] | Franchise grouping (unused) | No |
|
||||
|
||||
## Important Files
|
||||
|
||||
- `backend/config/database.js` — Connection config
|
||||
- `backend/config/relations.js` — Model associations
|
||||
- `backend/config/database.js` — Sequelize connection
|
||||
- `backend/config/relations.js` — All associations
|
||||
- `backend/config/dataInitializer.js` — Genre seeding
|
||||
- `backend/config/sequelizeHooks.js` — Collection order hooks
|
||||
- `backend/models/` — All model definitions
|
||||
- `backend/models/` — All Sequelize model definitions
|
||||
Reference in new issue
Block a user