- New notes: History, Artwork - Rewrite TMDB Integration: single detail request, entry mapper, rate limiter, refresh sync, stale-entry refresh, recommendations - Update pages, routing, API reference, models, database migrations, services, components, hooks, API clients, settings, media system, library, Electron (Tauri in progress) and known issues - Rewrite README for the current React/Express stack and setup
435 lines
12 KiB
Markdown
435 lines
12 KiB
Markdown
---
|
|
title: Models
|
|
tags:
|
|
- backend
|
|
- database
|
|
- models
|
|
- sequelize
|
|
aliases:
|
|
- Sequelize Models
|
|
---
|
|
|
|
# Models
|
|
|
|
Complete field reference for every Sequelize model. See [[Database]] for relationships.
|
|
|
|
All models in `backend/models/`.
|
|
|
|
---
|
|
|
|
## Entry
|
|
|
|
> [!info] File: `backend/models/Entry.js`
|
|
|
|
The core model — represents a movie or TV series.
|
|
|
|
| Field | Type | Default/Notes |
|
|
|---|---|---|
|
|
| `id` | INTEGER PK AUTO | |
|
|
| `title` | STRING(500) | |
|
|
| `original_title` | STRING(100) | |
|
|
| `release_date` | DATE | |
|
|
| `release_status` | STRING(50) | |
|
|
| `runtime` | INTEGER | Minutes |
|
|
| `tagline` | STRING(200) | |
|
|
| `storyline` | STRING(3000) | |
|
|
| `country` | STRING(30) | |
|
|
| `certification` | STRING(20) | e.g. `R`, `TV-14` (US first, then origin country) |
|
|
| `network_studio` | STRING(100) | First network, else first production company |
|
|
| `collection_id` | INTEGER | TMDB collection ID |
|
|
| `max_cast` | INTEGER | Default `10` |
|
|
| `credit_fetched` | BOOLEAN | Default `false` |
|
|
| `watchlist` | BOOLEAN | Default `false` |
|
|
| `favorit` | BOOLEAN | Default `false` |
|
|
| `hidden` | BOOLEAN | Default `false` |
|
|
| `showInCalendar` | BOOLEAN | Default `true` |
|
|
| `autoSync` | BOOLEAN | Default `true` |
|
|
| `note` | STRING(2000) | User notes |
|
|
| `is_tvseries` | BOOLEAN | `true` = TV, `false` = movie |
|
|
| `status` | STRING(20) | e.g. "Ended", "Returning Series" |
|
|
| `poster_path` | STRING(200) | TMDB poster path |
|
|
| `banner_path` | STRING(200) | TMDB backdrop path |
|
|
| `date_first_seen` | DATEONLY | |
|
|
| `date_last_seen` | DATEONLY | |
|
|
| `last_fetch` | DATE | Last TMDB refresh (date + time); used by the [[API Reference#Stale Entries Refresh\|stale refresh]] |
|
|
| `entry_sync_status` | STRING(50) | Nullable. e.g. `"RequireCreditsSync"` |
|
|
| `adult` | BOOLEAN | |
|
|
| `tmdb_popularity` | FLOAT | |
|
|
| `original_language` | STRING(10) | |
|
|
| `origin_country` | JSON | `string[]` |
|
|
| `homepage` | STRING(500) | |
|
|
| `budget` / `revenue` | BIGINT | Movies only |
|
|
| `tv_type` | STRING(30) | TV only, e.g. `Scripted` |
|
|
| `number_of_seasons` / `number_of_episodes` | INTEGER | TV only |
|
|
| `last_air_date` | DATEONLY | TV only |
|
|
| `in_production` | BOOLEAN | TV only |
|
|
| `spoken_languages`, `production_countries`, `production_companies` | JSON | Detail page only* |
|
|
| `keywords` | JSON | `string[]`, up to 30* |
|
|
| `tmdb_videos` | JSON | YouTube trailers/teasers, up to 12* (not `videos`: that name is the Discovery Videos association) |
|
|
| `watch_providers` | JSON | Per-country stream/rent/buy providers* |
|
|
| `alternative_titles` | JSON | * |
|
|
| `created_by`, `next_episode_to_air`, `last_episode_to_air` | JSON | TV only* |
|
|
|
|
\* Listed in `Entry.DETAIL_ONLY_ATTRIBUTES` and excluded from the library list query (`GET /entries`) to keep it small.
|
|
|
|
All TMDB fields are filled by `mappers/entryMapper.js` — see [[TMDB Integration#Entry Mapper]].
|
|
|
|
**Has:** [[#EntryId]] (1:1), [[#EntryRating]] (1:1), [[#EntrySeen]] (1:N), [[#Season]] (1:N), [[#Credit]] (1:N), Genres (M:N), Networks (M:N), Collections (M:N), Media (polymorphic)
|
|
|
|
---
|
|
|
|
## Season
|
|
|
|
> [!info] File: `backend/models/Season.js`
|
|
|
|
| Field | Type | Notes |
|
|
|---|---|---|
|
|
| `id` | INTEGER PK AUTO | |
|
|
| `tmdb_id` | STRING(30) | |
|
|
| `imdb_id` | STRING(30) | |
|
|
| `tvdb_id` | STRING(30) | From the season's `external_ids` |
|
|
| `entry_id` | INTEGER FK | → Entry |
|
|
| `name` | STRING(500) | |
|
|
| `overview` | STRING(3000) | |
|
|
| `season_number` | INTEGER | Display number (not DB id) |
|
|
| `episode_count` | INTEGER | |
|
|
| `air_date` | DATE | |
|
|
| `user_rating` | FLOAT | |
|
|
| `tmdb_rating` | FLOAT | |
|
|
| `imdb_rating` | FLOAT | |
|
|
| `poster_path` | STRING(200) | |
|
|
| `banner_path` | STRING(200) | |
|
|
|
|
**Has:** [[#Episode]] (1:N), Media (polymorphic)
|
|
|
|
> [!warning] Important
|
|
> `season_number` is the display number (0 = Specials, 1 = Season 1, etc.). `id` is the database primary key. Frontend pages should use `season_number` for display, not `id`.
|
|
|
|
---
|
|
|
|
## Episode
|
|
|
|
> [!info] File: `backend/models/Episode.js`
|
|
|
|
| Field | Type | Notes |
|
|
|---|---|---|
|
|
| `id` | INTEGER PK AUTO | |
|
|
| `tmdb_id` | STRING(30) | |
|
|
| `imdb_id` | STRING(30) | |
|
|
| `tvdb_id` | STRING(30) | |
|
|
| `season_id` | INTEGER FK | → Season |
|
|
| `name` | STRING(500) | |
|
|
| `overview` | STRING(3000) | |
|
|
| `episode_number` | INTEGER | |
|
|
| `episode_type` | STRING(60) | |
|
|
| `runtime` | INTEGER | Minutes |
|
|
| `air_date` | DATE | |
|
|
| `user_rating` | FLOAT | |
|
|
| `tmdb_rating` | FLOAT | |
|
|
| `tmdb_vote_count` | INTEGER | |
|
|
| `production_code` | STRING(50) | |
|
|
| `crew` | JSON | Directors + writers (`{ id, name, job, department, profile_path }`) |
|
|
| `guest_stars` | JSON | Up to 25 (`{ id, name, character, profile_path, order }`) |
|
|
| `still_path` | STRING(200) | |
|
|
| `date_first_seen` | DATEONLY | |
|
|
| `date_last_seen` | DATEONLY | |
|
|
|
|
**Has:** [[#EpisodeSeen]] (1:N), Media (polymorphic)
|
|
|
|
---
|
|
|
|
## EntrySeen
|
|
|
|
> [!info] File: `backend/models/EntrySeen.js`
|
|
|
|
Movie watch record. See [[Watch Tracking]].
|
|
|
|
| Field | Type | Notes |
|
|
|---|---|---|
|
|
| `id` | INTEGER PK AUTO | |
|
|
| `entry_id` | INTEGER FK | → Entry |
|
|
| `date_seen` | DATE | |
|
|
| `seen_with` | STRING(50) | |
|
|
| `accuracy` | ENUM | `'EXACT'`, `'ESTIMATED'`, `'UNKNOWN'`. Default `'EXACT'` |
|
|
|
|
**No timestamps.**
|
|
|
|
---
|
|
|
|
## EpisodeSeen
|
|
|
|
> [!info] File: `backend/models/EpisodeSeen.js`
|
|
|
|
Episode watch record. See [[Watch Tracking]].
|
|
|
|
| Field | Type | Notes |
|
|
|---|---|---|
|
|
| `id` | INTEGER PK AUTO | |
|
|
| `entry_id` | INTEGER FK | → Entry |
|
|
| `episode_id` | INTEGER FK | → Episode |
|
|
| `date_seen` | DATE | |
|
|
| `seen_with` | STRING(50) | |
|
|
| `accuracy` | ENUM | `'EXACT'`, `'ESTIMATED'`, `'UNKNOWN'`. Default `'EXACT'` |
|
|
|
|
**Has timestamps.**
|
|
|
|
---
|
|
|
|
## Media
|
|
|
|
> [!info] File: `backend/models/Media.js`
|
|
|
|
Polymorphic image record. See [[Media System]].
|
|
|
|
| Field | Type | Notes |
|
|
|---|---|---|
|
|
| `id` | INTEGER PK AUTO | |
|
|
| `mediaable` | STRING | `'entry'`, `'people'`, `'collection'`, `'season'`, `'episode'` |
|
|
| `mediaableId` | INTEGER | Polymorphic FK |
|
|
| `type` | STRING(50) | `'poster'`, `'backdrop'`, `'logo'`, `'still'`, `'profile'` |
|
|
| `path` | STRING(200) | UUID filename on disk |
|
|
| `tmdbPath` | STRING(200) | `tmdb_path` — TMDB `file_path` the image was downloaded from; null for custom uploads and images downloaded before it existed. Used by [[Artwork]] |
|
|
| `isLocal` | BOOLEAN | |
|
|
| `isSelected` | BOOLEAN | Default `false` — the "active" media |
|
|
| `isCustom` | BOOLEAN | Default `false` — user-uploaded |
|
|
| `isFavorit` | BOOLEAN | Default `false` |
|
|
|
|
---
|
|
|
|
## Collection
|
|
|
|
> [!info] File: `backend/models/Collection.js`
|
|
|
|
See [[Collections]].
|
|
|
|
| Field | Type | Notes |
|
|
|---|---|---|
|
|
| `id` | INTEGER PK AUTO | |
|
|
| `tmdbId` | STRING(30) | |
|
|
| `imdbId` | STRING(30) | |
|
|
| `tvdbId` | STRING(30) | |
|
|
| `name` | STRING(150) | |
|
|
| `description` | STRING(3000) | |
|
|
| `isUserCollection` | BOOLEAN | Default `false` — `true` = created by user |
|
|
| `userRating` | FLOAT | |
|
|
| `posterPath` | STRING(200) | |
|
|
| `backdropPath` | STRING(200) | |
|
|
| `isLocal` | BOOLEAN | Default `false` |
|
|
|
|
**Associated entries via [[#UserCollectionEntry]] join table.**
|
|
|
|
---
|
|
|
|
## UserCollectionEntry
|
|
|
|
> [!info] File: `backend/models/UserCollectionEntry.js`
|
|
|
|
Join table for Collection ↔ Entry (M:N). Managed by hooks in `sequelizeHooks.js`.
|
|
|
|
| Field | Type | Notes |
|
|
|---|---|---|
|
|
| `user_collection_id` | INTEGER PK, FK | → Collection |
|
|
| `entry_id` | INTEGER PK, FK | → Entry |
|
|
| `order` | INTEGER | Display order (auto-managed by hooks) |
|
|
|
|
**No timestamps.**
|
|
|
|
---
|
|
|
|
## Credit
|
|
|
|
> [!info] File: `backend/models/Credit.js`
|
|
|
|
| Field | Type | Notes |
|
|
|---|---|---|
|
|
| `id` | INTEGER PK AUTO | |
|
|
| `tmdb_credit_id` | STRING(100) | |
|
|
| `adult` | BOOLEAN | Default `false` |
|
|
| `profile_path` | STRING(200) | TMDB profile image |
|
|
| `character` | STRING(500) | Role name(s) for cast — multiple roles joined by `"; "` |
|
|
| `order` | INTEGER | Display order |
|
|
| `episode_count` | INTEGER | Total episode count (from TMDB aggregate_credits) |
|
|
| `cast_type` | ENUM | `'cast'`, `'crew'`. Default `'cast'` |
|
|
| `department` | STRING(100) | For crew |
|
|
| `job` | STRING(500) | Job title(s) for crew — multiple jobs joined by `"; "` |
|
|
| `entry_id` | INTEGER FK | → Entry |
|
|
| `people_id` | INTEGER FK | → People |
|
|
|
|
> [!info] TV Series Credits
|
|
> For TV series, TMDB returns `aggregate_credits` where a person can have multiple roles/jobs. These are joined with `"; "` into the `character` and `job` fields respectively. `episode_count` tracks the total episodes the person appeared in.
|
|
|
|
---
|
|
|
|
## People
|
|
|
|
> [!info] File: `backend/models/People.js`
|
|
|
|
See [[People]].
|
|
|
|
| Field | Type | Notes |
|
|
|---|---|---|
|
|
| `id` | INTEGER PK AUTO | |
|
|
| `tmdb_id` | STRING(100) | |
|
|
| `name` | STRING(100) | |
|
|
| `original_name` | STRING(200) | |
|
|
| `birthday` | DATEONLY | |
|
|
| `deathday` | DATEONLY | Nullable |
|
|
| `gender` | INTEGER | TMDB gender codes |
|
|
| `biography` | TEXT | |
|
|
| `place_of_birth` | STRING(100) | |
|
|
| `adult` | BOOLEAN | Default `false` |
|
|
| `popularity` | FLOAT | |
|
|
| `known_for_department` | STRING(50) | |
|
|
| `homepage` | STRING(200) | Nullable |
|
|
| `imdb_id` | STRING(20) | |
|
|
| `profile_path` | STRING(200) | |
|
|
| `last_fetch` | DATEONLY | For lazy-fetch |
|
|
| `profile_update` | DATEONLY | |
|
|
| `fully_fetched` | BOOLEAN | Default `false` — triggers TMDB fetch when `false` |
|
|
| `favorite` | BOOLEAN | Default `false` — user-favorited person |
|
|
| `pinned` | BOOLEAN | Default `false` — manually added, excluded from orphan cleanup |
|
|
|
|
---
|
|
|
|
## EntryId
|
|
|
|
> [!info] File: `backend/models/EntryId.js`
|
|
|
|
External ID storage (1:1 with Entry).
|
|
|
|
| Field | Type |
|
|
|---|---|
|
|
| `id` | INTEGER PK AUTO |
|
|
| `entry_id` | INTEGER FK → Entry |
|
|
| `tmdb_id` | STRING(30) |
|
|
| `imdb_id` | STRING(30) |
|
|
| `tvdb_id` | STRING(30) |
|
|
| `wikidata_id` | STRING(30) |
|
|
| `facebook_id` | STRING(100) |
|
|
| `instagram_id` | STRING(100) |
|
|
| `twitter_id` | STRING(100) |
|
|
|
|
All filled from TMDB `external_ids` (TV series only have their IMDb id there).
|
|
|
|
**No timestamps.**
|
|
|
|
---
|
|
|
|
## EntryRating
|
|
|
|
> [!info] File: `backend/models/EntryRating.js`
|
|
|
|
Multi-source ratings (1:1 with Entry).
|
|
|
|
| Field | Type |
|
|
|---|---|
|
|
| `id` | INTEGER PK AUTO |
|
|
| `entry_id` | INTEGER FK → Entry |
|
|
| `user_rating` | FLOAT |
|
|
| `tmdb_rating` | FLOAT |
|
|
| `tmdb_vote_count` | INTEGER |
|
|
| `imdb_rating` | FLOAT |
|
|
| `rotten_tomatoes_rating` | FLOAT |
|
|
|
|
**No timestamps.**
|
|
|
|
---
|
|
|
|
## EntryGenre
|
|
|
|
> [!info] File: `backend/models/EntryGenre.js`
|
|
|
|
Join table: Entry ↔ Genre. Composite PK: `(genre_id, entry_id)`. No timestamps.
|
|
|
|
---
|
|
|
|
## EntryNetwork
|
|
|
|
> [!info] File: `backend/models/EntryNetwork.js`
|
|
|
|
Join table: Entry ↔ Network. Composite PK: `(network_id, entry_id)`. Has `order` field. No timestamps.
|
|
|
|
---
|
|
|
|
## Genre
|
|
|
|
> [!info] File: `backend/models/Genre.js`
|
|
|
|
| Field | Type | Notes |
|
|
|---|---|---|
|
|
| `id` | INTEGER PK | TMDB genre ID (not auto-increment) |
|
|
| `name` | STRING(100) | |
|
|
|
|
**No timestamps.** Seeded with 27 TMDB genres on startup.
|
|
|
|
---
|
|
|
|
## Network
|
|
|
|
> [!info] File: `backend/models/Network.js`
|
|
|
|
| Field | Type |
|
|
|---|---|
|
|
| `id` | INTEGER PK (TMDB ID) |
|
|
| `name` | STRING(100) |
|
|
| `originCountry` | STRING(100) |
|
|
| `homepage` | STRING(100) |
|
|
| `logoPath` | STRING(200) |
|
|
| `posterPath` | STRING(200) |
|
|
| `backdropPath` | STRING(200) |
|
|
|
|
`originCountry` and `logoPath` are filled from TMDB's `origin_country` / `logo_path` and refreshed with the entry.
|
|
|
|
**No timestamps.**
|
|
|
|
---
|
|
|
|
## Franchise
|
|
|
|
> [!info] File: `backend/models/Franchise.js`
|
|
|
|
| Field | Type |
|
|
|---|---|
|
|
| `id` | INTEGER PK AUTO |
|
|
| `title` | STRING(50) |
|
|
| `overview` | STRING(300) |
|
|
| `user_rating` | FLOAT |
|
|
|
|
**No timestamps. Currently unused — reserved for future franchise grouping.**
|
|
|
|
---
|
|
|
|
## Video
|
|
|
|
> [!info] File: `backend/models/Video.js`
|
|
|
|
Personal video record for the [[Discovery Videos]] page.
|
|
|
|
| Field | Type | Notes |
|
|
|---|---|---|
|
|
| `id` | INTEGER PK AUTO | |
|
|
| `title` | STRING(500) | Derived from filename on upload, editable |
|
|
| `description` | TEXT | User description |
|
|
| `filename` | STRING(200) | UUID filename in `data/videos/` |
|
|
| `original_name` | STRING(500) | Original upload name |
|
|
| `mime_type` | STRING(100) | |
|
|
| `size` | BIGINT | Bytes |
|
|
| `duration` | INTEGER | Nullable — reserved for ffmpeg probing |
|
|
| `thumbnail_path` | STRING(200) | Nullable — reserved for thumbnails |
|
|
|
|
**Has:** Entries (M:N via [[#VideoEntry]])
|
|
|
|
---
|
|
|
|
## VideoEntry
|
|
|
|
> [!info] File: `backend/models/VideoEntry.js`
|
|
|
|
Join table: Video ↔ Entry (M:N). Table name `video_entries`. FK `ON DELETE CASCADE` on both sides.
|
|
|
|
| Field | Type | Notes |
|
|
|---|---|---|
|
|
| `id` | INTEGER PK AUTO | |
|
|
| `video_id` | INTEGER FK | → Video |
|
|
| `entry_id` | INTEGER FK | → Entry |
|