--- 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` | INTEGER | | | `network_studio` | STRING(40) | | | `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` | DATEONLY | Used by [[Services#Lazy Refresh\|lazy refresh]] | **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) | | | `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 | | | `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 | | `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) | | | `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` | --- ## 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) | **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 | | `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(30) | | **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(30) | | `originCountry` | STRING(100) | | `homepage` | STRING(100) | | `logoPath` | STRING(200) | | `posterPath` | STRING(200) | | `backdropPath` | STRING(200) | **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.**