The database is a relational PostgreSQL system designed to support the StreamFlix streaming platform. It adheres to 3rd Normal Form (3NF) to ensure data integrity and minimize redundancy.
- Database Name:
streamflix - Schema: Public
- User:
admin(Default)
Note: This description maps to the provided SQL schema.
- Accounts: Stores user login credentials and account status.
- Profile: Multiple profiles per account (like Netflix).
- Media: Base entity for content (Inheritance strategy).
- Movie: Extends Media.
- Series: Extends Media.
- Subscription: Manages user billing tiers.
accounts:id(PK),email(Unique),password_hash,is_verified,is_blocked.
profile:id(PK),account_id(FK),name,age_rating_id(FK).
role:- Lookup table for employee roles (
Junior,Mid-level,Senior).
- Lookup table for employee roles (
employee:- Internal staff linked to
accountsandrole.
- Internal staff linked to
media:id(PK),title,release_date,age_rating_id(FK),dtype(Discriminator).
movie:media_id(PK/FK),duration_seconds,video_url.
series:media_id(PK/FK),description.
season:id(PK),series_id(FK),season_number.
episode:id(PK),season_id(FK),title,video_url.
viewing_progress:- Tracks where a user left off. Links
profiletomovieORepisode.
- Tracks where a user left off. Links
watch_list:- Content saved for later. Links
profiletomedia.
- Content saved for later. Links
preference:- User preferences (genres, tags).
subscription_tier:- Defines plans (SD, HD, UHD) and prices.
subscription:- Active user subscriptions.
referral:- Tracks user invitations and discounts.
Views are used to enforce row-level security and role-based data access for employees.
view_junior_accounts:- Restricted view for Junior support staff. Shows only basic account info (no PII/financials).
view_midlevel_profiles:- For Mid-level staff. Adds profile visibility.
view_senior_full_access:- Full access view for Senior staff, including subscription and financial data.
get_profile_viewing_stats(profile_id):- Returns aggregated stats: total hours watched, movies count, episodes count.
get_popular_content(limit):- Returns top content based on view count and completion rate.
clean_expired_tokens():- Maintenance procedure to delete old verification tokens.
trg_auto_remove_from_watchlist:- Automatically removes a movie or series from the user's watchlist when they finish watching it.
trg_update_subscription_end_date:- Sets the end date to "today" when a subscription is cancelled.
trg_prevent_duplicate_watchlist:- Prevents adding the same content to a watchlist twice.
- Backup: Standard
pg_dumputility should be used.docker exec -t streamflix-db pg_dump -U admin streamflix > backup.sql
- Recovery: Restore using
psql.cat backup.sql | docker exec -i streamflix-db psql -U admin -d streamflix
The database initializes with:
- 7 Age Ratings (AL to 18+)
- 3 Subscription Tiers (SD, HD, UHD)
- 6 Movies (e.g., Inception, The Matrix)
- 1 Series (Breaking Bad) with 2 Seasons and 3 Episodes.