Files
Showy/docs-vault/Database.md
X4Lo eb3a12f6cb Add Discovery Videos feature
Let users upload videos, tag them with one or more entries, and watch
them from a new Discovery Videos page.

Backend:
- Add Video and VideoEntry models and relations
- Add video controller and /video routes
- Add video thumbnail generation service (ffmpeg-static)
- Add video upload storage location and config

Frontend:
- Add DiscoveryVideosPage with sidebar link and route
- Add AddVideoDialog, VideoDropzone, EntryMultiSelect, VideoCard
  and VideoPlayerDialog components
- Add discoveryVideos API client and useDiscoveryVideos hook
- Add format helpers, video types and normalizers
- Add skeleton for the page

Docs:
- Document the feature in docs-vault
2026-11-03 15:57:53 +00:00

4.1 KiB

title, tags
title tags
Database
backend
database
mysql
sequelize

Database

Overview

MySQL database named Showzy, managed by Sequelize 6 ORM.

  • 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

Entity Relationship Diagram

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
    Entry }o--o{ Video : links-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 —
Video Entry belongsToMany VideoEntry CASCADE

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 Movies and TV series Yes
Models#Season TV seasons Yes
Models#Episode TV episodes Yes
Models#EntrySeen Movie watch records No
Models#EpisodeSeen Episode watch records Yes
Models#Media Polymorphic image records Yes
Models#Collection TMDB + user collections Yes
Models#UserCollectionEntry Collection ↔ Entry join No
Models#Credit Cast/crew credits Yes
Models#People Person profiles Yes
Models#EntryId External IDs (TMDB, IMDB, TVDB) No
Models#EntryRating Multi-source ratings No
Models#EntryGenre Entry ↔ Genre join No
Models#EntryNetwork Entry ↔ Network join No
Models#Genre Genres (seeded from TMDB) No
Models#Network TV networks No
Models#Franchise Franchise grouping (unused) No
Models#Video Discovery videos Yes
Models#VideoEntry Video ↔ Entry join Yes

Important Files

  • 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