World 2A / Quest 2A.2

Movie and Showtime Schema

Model showtimes as booking facts with stored occupancy windows.

Concept

A showtime is not just a movie and a start time. It occupies a screen until the movie snapshot and cleaning buffer are over. That occupancy window belongs on the row because constraints can only enforce what the row can see.

Task

  1. Create the movies table with normalized title, duration, and source identity.
  2. Create the showtimes table with starts_at, occupied_until, duration snapshot, cleaning buffer, price, and currency.
  3. Add checks for positive duration, non-negative price, and occupied_until after starts_at.

Run

./gradlew test --tests "*Phase2ASchemaContractTest"

Expected Result

  • The schema contract test sees the showtime checks.
  • schema-notes.md explains why occupied_until is stored.

Common Traps

  • Trying to compute occupied_until by joining movies inside a constraint.
  • Using floating point for money.
  • Skipping currency_code because the demo data is mostly PHP.

Hint Ladder

Hint 1

Historical showtimes should not move if a movie runtime is corrected later.

Hint 2

Use numeric for money.

Hint 3

The non-PH seed cinema is there to keep the model honest.

Solution

See the showtimes table in V1__schema.sql.