Entertainment Data Modeling: From Actor-Role Mapping to Table Schema Design

    This article uses a single cast record—an actor appears in a work and plays a role—to derive a relational schema for entertainment platforms. It covers entity relationships, master data and mapping tables, composite unique keys for actors playing multiple roles, time-field granularity and range constraints, and a scoped-assignment pattern that offers a useful analogy to RBAC.

    1. Business Entities from a Single Cast Record

    The core data of a film and TV platform comes from one business fact: an actor appears in a film in a given year, plays a role, and the film is directed by a director. This fact involves four types of entities: actors, directors, works, and roles. Actors and directors each have attributes such as name; works have a title and a release year; roles exist only in the context of a work.

    The relationships between entities determine the shape of the schema:

    • Actors and works have a many-to-many relationship. An actor can appear in multiple works, and a work can have multiple actors.
    • Directors and works usually have a one-to-many relationship. A director can direct multiple works, and a work generally has one main director.
    • Roles must be understood in the context of a work. The same role name in different works may refer to completely different characters.

    Determine these relationships before designing the schema; this significantly reduces the cost of later changes.

    2. Master Data Tables and Mapping Table Design

    Actors, directors, and works each get a master data table. A master data table stores only the entity’s own attributes and does not copy information from other entities.

    1. CREATE TABLE actor (
    2. actor_id BIGINT PRIMARY KEY AUTO_INCREMENT,
    3. name VARCHAR(100) NOT NULL,
    4. foreign_name VARCHAR(100),
    5. created_at DATETIME(3) DEFAULT CURRENT_TIMESTAMP(3)
    6. );
    7. CREATE TABLE director (
    8. director_id BIGINT PRIMARY KEY AUTO_INCREMENT,
    9. name VARCHAR(100) NOT NULL,
    10. created_at DATETIME(3) DEFAULT CURRENT_TIMESTAMP(3)
    11. );
    12. CREATE TABLE work (
    13. work_id BIGINT PRIMARY KEY AUTO_INCREMENT,
    14. title VARCHAR(200) NOT NULL,
    15. release_year INT,
    16. director_id BIGINT,
    17. created_at DATETIME(3) DEFAULT CURRENT_TIMESTAMP(3),
    18. FOREIGN KEY (director_id) REFERENCES director(director_id)
    19. );

    The actor–work mapping table carries the “plays a role” attribute:

    1. CREATE TABLE actor_work_mapping (
    2. mapping_id BIGINT PRIMARY KEY AUTO_INCREMENT,
    3. actor_id BIGINT NOT NULL,
    4. work_id BIGINT NOT NULL,
    5. role_name VARCHAR(200) NOT NULL,
    6. created_at DATETIME(3) DEFAULT CURRENT_TIMESTAMP(3),
    7. FOREIGN KEY (actor_id) REFERENCES actor(actor_id),
    8. FOREIGN KEY (work_id) REFERENCES work(work_id),
    9. UNIQUE KEY uk_actor_work_role (actor_id, work_id, role_name)
    10. );

    The unique key must include role_name. If it used only (actor_id, work_id), a second record for the same actor playing two roles in the same work would fail on duplicate insert. With role_name included, the same actor can appear multiple times in the same work, while the same role can be recorded only once.

    Insert data for one actor playing multiple roles:

    1. INSERT INTO actor_work_mapping (actor_id, work_id, role_name)
    2. VALUES (1001, 2001, 'Police Captain'),
    3. (1001, 2001, 'Retired Man');

    Query all roles for a given actor in a given work:

    1. SELECT role_name
    2. FROM actor_work_mapping
    3. WHERE actor_id = ? AND work_id = ?;

    There is a trade-off here. role_name is free text, so “Police Captain” and “Police Captain ” (with a trailing space) would be treated as two roles and produce duplicate records. Trim leading and trailing spaces and normalize the format before writing. If the platform needs to perform statistics by role, it should split out a separate role table and use role_id in the unique key. At the current stage, free text plus a unique key is sufficient.

    The mapping table does not need a separate appearance time field. The release time belongs to the work itself; storing another copy in the mapping table will eventually lead to inconsistent values between the two places.

    3. Granularity and Range of Time Fields

    Time data in film and TV data falls roughly into three categories: year only, full date, and system write time. Each category should use a different type.

    Use INT when only the year is known. Store 1991 as an integer. If the year is stored as a string, sorting results will be wrong. For example, the string ‘999’ compares greater than ‘1991’ character by character, so older films can be sorted after newer ones.

    Query by year range with stable sorting:

    1. SELECT work_id, title, release_year
    2. FROM work
    3. WHERE release_year BETWEEN 1990 AND 1995
    4. ORDER BY release_year DESC, work_id DESC;

    Adding work_id as the second sort key ensures stable ordering of records with the same year during pagination.

    The year field may be NULL to indicate “unknown.” Do not use 0 in place of unknown, because 0 is treated as a valid numeric value in sorting and range queries. MySQL 8.0.16 and later support CHECK constraints, so the year range can be restricted:

    1. ALTER TABLE work
    2. ADD CONSTRAINT chk_release_year CHECK (release_year BETWEEN 1895 AND 2100);

    The lower bound of 1895 corresponds to the year of the first public film screening. The upper bound should be determined by the business; for example, pre-sale works may require later years.

    Use DATE when the full date is known. If only the year and month are known, the date can be set uniformly to the first day of that month, with an additional precision field (such as YEAR, MONTH, or DAY). This lets the interface distinguish real dates from inferred dates and avoids treating the first day as the exact release date.

    Do not use TIMESTAMP for system timestamps. TIMESTAMP is stored in UTC in MySQL, and its range is 1970-01-01 00:00:01 UTC to 2038-01-19 03:14:07 UTC. 1991 falls within that range, but many classic films predate 1970, and TIMESTAMP cannot store them. Using DATETIME(3) for audit fields is more reliable: it does not perform time zone conversion, and its range is much wider than TIMESTAMP.

    4. Understanding RBAC Through a Scope Model

    An actor plays different roles in different works, which is similar to the scope concept in RBAC (role-based access control): the same subject has different roles in different contexts. This analogy helps explain the design idea, but the rules are not the same. RBAC permission checks also consider role inheritance, deny rules, and similar factors, whereas film roles do not have these requirements.

    The user–role assignment table needs to include a scope field:

    1. CREATE TABLE user_role_assignment (
    2. assignment_id BIGINT PRIMARY KEY AUTO_INCREMENT,
    3. user_id BIGINT NOT NULL,
    4. role_id BIGINT NOT NULL,
    5. scope_id BIGINT NOT NULL COMMENT 'Resource or tenant context ID',
    6. UNIQUE KEY uk_user_role_scope (user_id, role_id, scope_id)
    7. );

    The unique key prevents the same user from being granted the same role in the same scope more than once. Setting scope_id to NOT NULL is intentional.