Database Documentation

Streamix uses PostgreSQL. There are no migration files: every table is created and extended by idempotent ensure*Schema() functions (CREATE TABLE IF NOT EXISTS, ALTER TABLE … ADD COLUMN IF NOT EXISTS) that run on first use, from the installer and from the seed scripts. Set DB_SCHEMA_READY=1 to skip these checks once the database is provisioned.

Module Schema file
Catalogue, assets, profiles, merchandising, streaming, plan limits, recommendations src/lib/ott-schema.ts (ensureOttSchema() runs them all)
HLS transcode columns src/lib/ott/transcode.ts
Renewal columns src/lib/ott/renewal.ts
Engagement: message log, push subscriptions, search log, settings src/lib/ott/engagement-schema.ts
Profile transfer codes src/lib/ott/profile-transfer.ts
Sign-in codes src/lib/login-code.ts
Help Centre src/lib/help-schema.ts
Members, billing, CMS, settings, access control, integrations src/lib/vendor-schema.ts, src/lib/auth-schema.ts

Conventions: snake_case columns, SERIAL ids, TIMESTAMPTZ times, money in integer minor units with a currency code, and a public_id column (added by ensurePublicId()) on records addressed from URLs or the API.

For diagrams see the Entity Relationship Diagram and Data Model Diagram.

Catalogue

Table Purpose Key columns
titles A film or series type (movie/series), title, slug (unique, case-insensitive), synopsis, short_synopsis, release_year, runtime_minutes, maturity_rating_id, maturity_descriptors (JSON), original_language, is_original, is_featured, quality (SD/HD/4K), has_hdr, has_audio_description, status (draft/scheduled/published/archived), available_from, available_until, countries_allow, countries_deny (JSON arrays of ISO codes), views, popularity, seo_title, seo_description, published_at
seasons Season of a series title_id, number (unique per title), name, synopsis, release_year
episodes Episode title_id, season_id, number (unique per season), name, synopsis, runtime_seconds, still_image, intro_start, intro_end, recap_start, recap_end, credits_start (seconds), status, available_from
maturity_ratings Age ratings per country country_code (* = any), code, label, level (0/7/13/16/18), is_kids, description
content_categories Genres are rows with type = 'genre' (tree via parent) shared category table from the core
title_genres Title ↔ genre title_id, genre_id, sort_order
tags / title_tags Moods ("Suspenseful", "Witty") kind (mood), name, slug
people / title_credits Cast and crew name, slug, photo, bio; credits: role (actor, director, creator, writer…), character_name, sort_order

Media

Table Purpose Key columns
video_assets The playable file of a movie, episode or trailer (one per owner) owner_type (title/episode/trailer), owner_id, provider (hls/mp4/mux/cloudflare), source_url, playback_url, playback_id, thumbnails_vtt, duration_seconds, width, height, max_resolution, status, drm_key_id (reserved)
↳ transcode columns HLS conversion state transcode_status (none/queued/processing/ready/failed), transcode_progress, transcode_error, transcode_attempts, transcode_started_at, transcode_heartbeat_at, transcoded_at, hls_url, renditions (JSON)
media_tracks Subtitle, caption and audio tracks of an asset asset_id, kind (subtitles/captions/audio/forced/description), language, label, url, is_default
trailers Trailers, teasers and clips (each has its own video_assets row) title_id, kind, name, image, is_primary
artwork Images per title kind (boxart 16:9, poster 2:3, backdrop, logo, still), language, url, is_primary

Profiles and viewer state

Table Purpose Key columns
profiles Viewer profiles of an account customer_id, name, avatar_id, is_kids, maturity_level, language, subtitle_style (JSON), autoplay_next, autoplay_previews, pin_hash (bcrypt, NULL = unlocked)
avatars Avatar picker set_name, url, is_kids, is_active
profile_blocked_titles Titles hidden from a profile profile_id, title_id
my_list My List profile_id, title_id, added_at
playback_progress Resume point per profile and title/episode position_seconds, duration_seconds, completed, hidden, watched_seconds, updated_at; unique on (profile_id, title_id, COALESCE(episode_id, 0))
title_ratings Thumbs value: -1 not for me, 1 like, 2 love
title_reminders "Remind me" profile_id, title_id, notified_at
profile_notifications Bell inbox kind, title_id, message, link, image, read_at
profile_transfers One-time transfer codes code_hash, profile_id, from_customer, to_customer, expires_at, used_at

Merchandising and recommendations

Table Purpose Key columns
billboards Hero title per page page (home/tv/movies/kids/latest/genre), genre_id, title_id, starts_at, ends_at, is_active, sort_order
browse_rows Rows per page page, genre_id, name (may contain {profile}), row_type, filters (JSON), card_shape, item_limit, audience (all/adults/kids), is_active, sort_order
browse_row_items Titles of a manual row row_id, title_id, sort_order
top10_snapshots Daily Top 10 period_date, country_code, type (all/movie/series), rank, title_id, hours_viewed, is_override
title_similar Precomputed similar titles title_id, similar_id, score, cowatch, content, co_viewers, computed_at

Row types: continue_watching, top10, my_list, because_you_watched, trending, new_releases, originals, genre, coming_soon, manual, top_picks, you_will_love.

Streams and devices

Table Purpose Key columns
devices Browsers/devices that signed in customer_id, device_key, name, device_type, user_agent, ip, country_code, city, last_seen_at, signed_out_at
playback_sessions Live and past streams customer_id, profile_id, device_id, title_id, episode_id, resolution, ip, started_at, last_heartbeat_at, ended_at. Live = not ended and heartbeat within 90 s.

Members, plans and billing

Table Purpose Key columns
customers Member accounts name, email, email_verified, phone, password_hash, otp_* (verification/reset), notification_prefs, is_active, is_blacklisted, plus generic profile fields inherited from the core
customer_login_codes Sign-in codes customer_id, code_hash, expires_at, attempts, used_at
customer_oauth_accounts Linked social logins provider and subject per member
subscription_plans Plans name, slug, price_cents, currency_code, interval (day/month/year/lifetime), interval_count, trial_days, features (JSON), is_active, is_featured; streaming limits max_streams, max_resolution, has_hdr, spatial_audio, download_devices, has_ads, extra_member_slots
subscriptions A member's membership customer_id, plan_id, snapshot plan_name/price_cents/currency_code, amount_paid_cents, coupon_id, status (pending/active/cancelled/on_hold/expired/refunded), started_at, expires_at, cancelled_at, on_hold_at, expiring_notified_at, expired_notified_at
transactions Payments customer_id, subscription_id, amount_cents, currency_code, provider, provider_ref (unique per provider), status, purpose (subscribe/renewal), meta
coupons / coupon_redemptions Discounts and their use code, type, value, limits; redemptions per member
gift_cards Gift card records (model exists; not used by checkout yet)

A member can stream when a subscription is active or cancelled and expires_at is NULL or in the future.

Engagement and settings

Table Purpose
member_message_log One row per lifecycle message sent (kind, ref_key), the claim that prevents duplicates
push_subscriptions Web push endpoints per member/profile, with failure count
search_log Search terms, result counts and an HMAC of the profile (never the id)
settings JSON settings by section (streaming, landing, general, web_push, …)
customer_notification_prefs Per-template opt-outs (communication settings)
help_categories / help_articles Help Centre content and feedback counts

Platform (core)

Admin users, roles, permissions, activity_log; integration_connections (encrypted provider credentials); app_license; api_tokens; webhooks; notification_templates, message_templates, notification_logs; app_settings, theme_settings, theme_chrome, chrome_templates, card_templates; builder_pages, menus, hero_sliders; pages, about, blogs, blog_categories, faqs, gallery, testimonials, hero_slides; contacts, enquiries, newsletter (lead forms); media_assets; translations, languages, countries, currencies, locations.

vendor-schema.ts still contains provisioning functions for generic commerce tables inherited from the shared core (products, orders, shipping and similar). Streamix does not call them, so they are not created on a fresh install.

Maintenance scripts

Script Use
npm run db:init Core schema
npx tsx scripts/drop-legacy-tables.ts Remove tables left over from the pre-streaming product (old audio/video library modules, their engagement tables, and unused tables from unrelated templates); dry run by default, --apply to drop
npm run db:reset Destructive: truncates everything except admin users and roles

© CreativeCape Solutions · creative-cape.com · support@creative-cape.com