Files
movies-diary/crates/adapters/postgres/migrations/0014_movie_profiles.sql
Gabriel Kaszewski 38d13fbff1 feat: implement TMDb enrichment for movie profiles
- Add SqliteMovieProfileRepository for managing movie profiles in SQLite.
- Create TmdbEnrichmentClient to fetch movie details from TMDb API.
- Implement enrichment event handling with EnrichmentHandler.
- Introduce periodic jobs for cleaning up expired import sessions and checking for stale movie profiles.
- Update application context to include movie profile repository.
- Add API endpoint to retrieve movie profiles.
- Extend domain models with new structures for movie enrichment (Genre, Keyword, CastMember, CrewMember, MovieProfile).
- Modify event system to include MovieEnrichmentRequested event.
- Enhance tests to cover new functionality and ensure stability.
2026-05-12 13:23:41 +02:00

55 lines
1.9 KiB
SQL

CREATE TABLE IF NOT EXISTS movie_profiles (
movie_id TEXT PRIMARY KEY NOT NULL REFERENCES movies(id) ON DELETE CASCADE,
tmdb_id BIGINT NOT NULL,
imdb_id TEXT,
overview TEXT,
tagline TEXT,
runtime_minutes INTEGER,
budget_usd BIGINT,
revenue_usd BIGINT,
vote_average DOUBLE PRECISION,
vote_count INTEGER,
original_language TEXT,
collection_name TEXT,
enriched_at TIMESTAMPTZ NOT NULL
);
CREATE TABLE IF NOT EXISTS movie_genres (
movie_id TEXT NOT NULL REFERENCES movies(id) ON DELETE CASCADE,
tmdb_id INTEGER NOT NULL,
name TEXT NOT NULL,
PRIMARY KEY (movie_id, tmdb_id)
);
CREATE TABLE IF NOT EXISTS movie_keywords (
movie_id TEXT NOT NULL REFERENCES movies(id) ON DELETE CASCADE,
tmdb_id INTEGER NOT NULL,
name TEXT NOT NULL,
PRIMARY KEY (movie_id, tmdb_id)
);
CREATE TABLE IF NOT EXISTS movie_cast (
movie_id TEXT NOT NULL REFERENCES movies(id) ON DELETE CASCADE,
tmdb_person_id BIGINT NOT NULL,
name TEXT NOT NULL,
character TEXT NOT NULL,
billing_order INTEGER NOT NULL,
profile_path TEXT,
PRIMARY KEY (movie_id, tmdb_person_id)
);
CREATE TABLE IF NOT EXISTS movie_crew (
movie_id TEXT NOT NULL REFERENCES movies(id) ON DELETE CASCADE,
tmdb_person_id BIGINT NOT NULL,
name TEXT NOT NULL,
job TEXT NOT NULL,
department TEXT NOT NULL,
profile_path TEXT,
PRIMARY KEY (movie_id, tmdb_person_id, job)
);
CREATE INDEX IF NOT EXISTS idx_movie_cast_person ON movie_cast (tmdb_person_id);
CREATE INDEX IF NOT EXISTS idx_movie_crew_person ON movie_crew (tmdb_person_id);
CREATE INDEX IF NOT EXISTS idx_movie_genres_name ON movie_genres (name);
CREATE INDEX IF NOT EXISTS idx_movie_keywords_name ON movie_keywords (name);