Concept
Phase 2A starts where most tutorials end: with the database saying what the system means. Cinemas and screens are small, but they already carry real invariants: zone IDs, source-aware identity, coordinates, ownership, and capacity.
Task
- Create the Flyway V1 migration with cinemas and screens.
- Add source-system-aware uniqueness for cinemas.
- Add check constraints for coordinates and screen capacity.
- Update the ERD and schema notes with each invariant.
Run
docker compose up -d postgres./gradlew flywayMigrate./gradlew test --tests "*Phase2ASchemaContractTest"Expected Result
- Flyway applies V1.
- The schema contract test finds the cinema and screen constraints.
Common Traps
- Using a fixed UTC offset instead of an IANA zone ID.
- Making source_external_id unique without source_system.
- Leaving capacity validation only in Java.
Hint Ladder
Hint 1
The timezone column is a string, but Java validates it with ZoneId.
Hint 2
Two providers can both call something 123. The source is part of the identity.
Hint 3
A screen cannot exist without a cinema, so make the FK non-null.
Solution
See palabas-api/src/main/resources/db/migration/V1__schema.sql.
Boot 3 to 4 Delta
Boot is not the main lesson here. The important delta is resisting ddl-auto and letting Flyway own schema history.