diff --git a/GLOSSARY.md b/GLOSSARY.md index ca76564..29825c7 100644 --- a/GLOSSARY.md +++ b/GLOSSARY.md @@ -24,6 +24,10 @@ _Avoid_: Global number, overall number **Absolute numbering**: A User's choice, Series by Series, to address its Episodes by their Absolute number ("Ep. 1100") rather than `SxxEyy`, wherever a person reads them. Meant for Anime. + +**Named seasons**: +A User's choice, Series by Series, to title its seasons by their own name on TMDB ("Arc East Blue") rather than "Season 1". A season TMDB only numbers keeps its number. +_Avoid_: Arc mode _Avoid_: Anime mode **Day**: @@ -93,7 +97,7 @@ _Avoid_: Blur, hidden titles Loading a User's Series, Statuses, Watches and Ratings from a Snug Export or another tracker (CSV, export file or an Assistant); it never overrides what Snug already has, so an Export restores as-is only into an empty account. **Export**: -A copy of one User's TrackedSeries (Status, Saving up target, Absolute numbering), Watches and Ratings at a given time, as a file. Snug's Import reads it back without loss; another tracker or a spreadsheet can read it. Account settings and secrets are not part of it. +A copy of one User's TrackedSeries (Status, Saving up target, Absolute numbering, Named seasons), Watches and Ratings at a given time, as a file. Snug's Import reads it back without loss; another tracker or a spreadsheet can read it. Account settings and secrets are not part of it. _Avoid_: Backup, dump **Feed**: diff --git a/apps/server/drizzle/0013_season_names.sql b/apps/server/drizzle/0013_season_names.sql new file mode 100644 index 0000000..5c3b4a9 --- /dev/null +++ b/apps/server/drizzle/0013_season_names.sql @@ -0,0 +1,7 @@ +CREATE TABLE `seasons` ( + `series_id` integer NOT NULL, + `number` integer NOT NULL, + `name` text NOT NULL, + PRIMARY KEY(`series_id`, `number`), + FOREIGN KEY (`series_id`) REFERENCES `series`(`tmdb_id`) ON UPDATE no action ON DELETE cascade +); diff --git a/apps/server/drizzle/0014_named_seasons.sql b/apps/server/drizzle/0014_named_seasons.sql new file mode 100644 index 0000000..564df9d --- /dev/null +++ b/apps/server/drizzle/0014_named_seasons.sql @@ -0,0 +1 @@ +ALTER TABLE `tracked_series` ADD `named_seasons` integer DEFAULT false NOT NULL; \ No newline at end of file diff --git a/apps/server/drizzle/meta/0013_snapshot.json b/apps/server/drizzle/meta/0013_snapshot.json new file mode 100644 index 0000000..e941cbd --- /dev/null +++ b/apps/server/drizzle/meta/0013_snapshot.json @@ -0,0 +1,1246 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "02529d90-5a89-4d05-9f9f-c68c4b354ca8", + "prevId": "ce171b12-fc79-4655-af81-2cad40bb2a1f", + "tables": { + "app_settings": { + "name": "app_settings", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "episodes": { + "name": "episodes", + "columns": { + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "air_date": { + "name": "air_date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "runtime": { + "name": "runtime", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "episodes_series_id_series_tmdb_id_fk": { + "name": "episodes_series_id_series_tmdb_id_fk", + "tableFrom": "episodes", + "tableTo": "series", + "columnsFrom": [ + "series_id" + ], + "columnsTo": [ + "tmdb_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "episodes_series_id_season_number_pk": { + "columns": [ + "series_id", + "season", + "number" + ], + "name": "episodes_series_id_season_number_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "seasons": { + "name": "seasons", + "columns": { + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "seasons_series_id_series_tmdb_id_fk": { + "name": "seasons_series_id_series_tmdb_id_fk", + "tableFrom": "seasons", + "tableTo": "series", + "columnsFrom": [ + "series_id" + ], + "columnsTo": [ + "tmdb_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "seasons_series_id_number_pk": { + "columns": [ + "series_id", + "number" + ], + "name": "seasons_series_id_number_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "series": { + "name": "series", + "columns": { + "tmdb_id": { + "name": "tmdb_id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "tvdb_id": { + "name": "tvdb_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "year": { + "name": "year", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "overview": { + "name": "overview", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "''" + }, + "poster_path": { + "name": "poster_path", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "backdrop_path": { + "name": "backdrop_path", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ended": { + "name": "ended", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "fetched_at": { + "name": "fetched_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "account": { + "name": "account", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "account_user_id_user_id_fk": { + "name": "account_user_id_user_id_fk", + "tableFrom": "account", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "feed_token": { + "name": "feed_token", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "feed_token_token_unique": { + "name": "feed_token_token_unique", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": { + "feed_token_user_id_user_id_fk": { + "name": "feed_token_user_id_user_id_fk", + "tableFrom": "feed_token", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "mcp_token": { + "name": "mcp_token", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "mcp_token_token_unique": { + "name": "mcp_token_token_unique", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": { + "mcp_token_user_id_user_id_fk": { + "name": "mcp_token_user_id_user_id_fk", + "tableFrom": "mcp_token", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "session": { + "name": "session", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "session_token_unique": { + "name": "session_token_unique", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": { + "session_user_id_user_id_fk": { + "name": "session_user_id_user_id_fk", + "tableFrom": "session", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user": { + "name": "user", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email_verified": { + "name": "email_verified", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "user_email_unique": { + "name": "user_email_unique", + "columns": [ + "email" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user_preferences": { + "name": "user_preferences", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "data": { + "name": "data", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "user_preferences_user_id_user_id_fk": { + "name": "user_preferences_user_id_user_id_fk", + "tableFrom": "user_preferences", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "verification": { + "name": "verification", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "watchlist_token": { + "name": "watchlist_token", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "watchlist_token_token_unique": { + "name": "watchlist_token_token_unique", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": { + "watchlist_token_user_id_user_id_fk": { + "name": "watchlist_token_user_id_user_id_fk", + "tableFrom": "watchlist_token", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "webhook_token": { + "name": "webhook_token", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "webhook_token_token_unique": { + "name": "webhook_token_token_unique", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": { + "webhook_token_user_id_user_id_fk": { + "name": "webhook_token_user_id_user_id_fk", + "tableFrom": "webhook_token", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "jellyfin_events": { + "name": "jellyfin_events", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "received_at": { + "name": "received_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "summary": { + "name": "summary", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "outcome": { + "name": "outcome", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "payload": { + "name": "payload", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "jellyfin_events_user_id_user_id_fk": { + "name": "jellyfin_events_user_id_user_id_fk", + "tableFrom": "jellyfin_events", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "jellyfin_series": { + "name": "jellyfin_series", + "columns": { + "jellyfin_series_id": { + "name": "jellyfin_series_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "tmdb_id": { + "name": "tmdb_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "jellyfin_users": { + "name": "jellyfin_users", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "jellyfin_user_id": { + "name": "jellyfin_user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "jellyfin_users_user_id_user_id_fk": { + "name": "jellyfin_users_user_id_user_id_fk", + "tableFrom": "jellyfin_users", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "episode_alerts": { + "name": "episode_alerts", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "sent_at": { + "name": "sent_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "episode_alerts_user_id_user_id_fk": { + "name": "episode_alerts_user_id_user_id_fk", + "tableFrom": "episode_alerts", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "episode_alerts_user_id_series_id_season_number_pk": { + "columns": [ + "user_id", + "series_id", + "season", + "number" + ], + "name": "episode_alerts_user_id_series_id_season_number_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "push_subscriptions": { + "name": "push_subscriptions", + "columns": { + "endpoint": { + "name": "endpoint", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "p256dh": { + "name": "p256dh", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "auth": { + "name": "auth", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "push_subscriptions_user_id_user_id_fk": { + "name": "push_subscriptions_user_id_user_id_fk", + "tableFrom": "push_subscriptions", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "ratings": { + "name": "ratings", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "episode": { + "name": "episode", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "rating": { + "name": "rating", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "ratings_user_id_series_id_season_episode_pk": { + "columns": [ + "user_id", + "series_id", + "season", + "episode" + ], + "name": "ratings_user_id_series_id_season_episode_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "tracked_series": { + "name": "tracked_series", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "saving_target": { + "name": "saving_target", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "absolute_numbering": { + "name": "absolute_numbering", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "added_at": { + "name": "added_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "tracked_series_user_id_user_id_fk": { + "name": "tracked_series_user_id_user_id_fk", + "tableFrom": "tracked_series", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "tracked_series_user_id_series_id_pk": { + "columns": [ + "user_id", + "series_id" + ], + "name": "tracked_series_user_id_series_id_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "watches": { + "name": "watches", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "watched_at": { + "name": "watched_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "watches_user_id_series_id_season_number_pk": { + "columns": [ + "user_id", + "series_id", + "season", + "number" + ], + "name": "watches_user_id_series_id_season_number_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/apps/server/drizzle/meta/0014_snapshot.json b/apps/server/drizzle/meta/0014_snapshot.json new file mode 100644 index 0000000..b715c2b --- /dev/null +++ b/apps/server/drizzle/meta/0014_snapshot.json @@ -0,0 +1,1254 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "7f6c3824-4a03-44d7-a77c-459139702276", + "prevId": "02529d90-5a89-4d05-9f9f-c68c4b354ca8", + "tables": { + "app_settings": { + "name": "app_settings", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "episodes": { + "name": "episodes", + "columns": { + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "air_date": { + "name": "air_date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "runtime": { + "name": "runtime", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "episodes_series_id_series_tmdb_id_fk": { + "name": "episodes_series_id_series_tmdb_id_fk", + "tableFrom": "episodes", + "tableTo": "series", + "columnsFrom": [ + "series_id" + ], + "columnsTo": [ + "tmdb_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "episodes_series_id_season_number_pk": { + "columns": [ + "series_id", + "season", + "number" + ], + "name": "episodes_series_id_season_number_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "seasons": { + "name": "seasons", + "columns": { + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "seasons_series_id_series_tmdb_id_fk": { + "name": "seasons_series_id_series_tmdb_id_fk", + "tableFrom": "seasons", + "tableTo": "series", + "columnsFrom": [ + "series_id" + ], + "columnsTo": [ + "tmdb_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "seasons_series_id_number_pk": { + "columns": [ + "series_id", + "number" + ], + "name": "seasons_series_id_number_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "series": { + "name": "series", + "columns": { + "tmdb_id": { + "name": "tmdb_id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "tvdb_id": { + "name": "tvdb_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "year": { + "name": "year", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "overview": { + "name": "overview", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "''" + }, + "poster_path": { + "name": "poster_path", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "backdrop_path": { + "name": "backdrop_path", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ended": { + "name": "ended", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "fetched_at": { + "name": "fetched_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "account": { + "name": "account", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "account_user_id_user_id_fk": { + "name": "account_user_id_user_id_fk", + "tableFrom": "account", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "feed_token": { + "name": "feed_token", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "feed_token_token_unique": { + "name": "feed_token_token_unique", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": { + "feed_token_user_id_user_id_fk": { + "name": "feed_token_user_id_user_id_fk", + "tableFrom": "feed_token", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "mcp_token": { + "name": "mcp_token", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "mcp_token_token_unique": { + "name": "mcp_token_token_unique", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": { + "mcp_token_user_id_user_id_fk": { + "name": "mcp_token_user_id_user_id_fk", + "tableFrom": "mcp_token", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "session": { + "name": "session", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "session_token_unique": { + "name": "session_token_unique", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": { + "session_user_id_user_id_fk": { + "name": "session_user_id_user_id_fk", + "tableFrom": "session", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user": { + "name": "user", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email_verified": { + "name": "email_verified", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "user_email_unique": { + "name": "user_email_unique", + "columns": [ + "email" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user_preferences": { + "name": "user_preferences", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "data": { + "name": "data", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "user_preferences_user_id_user_id_fk": { + "name": "user_preferences_user_id_user_id_fk", + "tableFrom": "user_preferences", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "verification": { + "name": "verification", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "watchlist_token": { + "name": "watchlist_token", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "watchlist_token_token_unique": { + "name": "watchlist_token_token_unique", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": { + "watchlist_token_user_id_user_id_fk": { + "name": "watchlist_token_user_id_user_id_fk", + "tableFrom": "watchlist_token", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "webhook_token": { + "name": "webhook_token", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "webhook_token_token_unique": { + "name": "webhook_token_token_unique", + "columns": [ + "token" + ], + "isUnique": true + } + }, + "foreignKeys": { + "webhook_token_user_id_user_id_fk": { + "name": "webhook_token_user_id_user_id_fk", + "tableFrom": "webhook_token", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "jellyfin_events": { + "name": "jellyfin_events", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "received_at": { + "name": "received_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "summary": { + "name": "summary", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "outcome": { + "name": "outcome", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "payload": { + "name": "payload", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "jellyfin_events_user_id_user_id_fk": { + "name": "jellyfin_events_user_id_user_id_fk", + "tableFrom": "jellyfin_events", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "jellyfin_series": { + "name": "jellyfin_series", + "columns": { + "jellyfin_series_id": { + "name": "jellyfin_series_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "tmdb_id": { + "name": "tmdb_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "jellyfin_users": { + "name": "jellyfin_users", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "jellyfin_user_id": { + "name": "jellyfin_user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "jellyfin_users_user_id_user_id_fk": { + "name": "jellyfin_users_user_id_user_id_fk", + "tableFrom": "jellyfin_users", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "episode_alerts": { + "name": "episode_alerts", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "sent_at": { + "name": "sent_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "episode_alerts_user_id_user_id_fk": { + "name": "episode_alerts_user_id_user_id_fk", + "tableFrom": "episode_alerts", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "episode_alerts_user_id_series_id_season_number_pk": { + "columns": [ + "user_id", + "series_id", + "season", + "number" + ], + "name": "episode_alerts_user_id_series_id_season_number_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "push_subscriptions": { + "name": "push_subscriptions", + "columns": { + "endpoint": { + "name": "endpoint", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "p256dh": { + "name": "p256dh", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "auth": { + "name": "auth", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "push_subscriptions_user_id_user_id_fk": { + "name": "push_subscriptions_user_id_user_id_fk", + "tableFrom": "push_subscriptions", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "ratings": { + "name": "ratings", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "episode": { + "name": "episode", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "rating": { + "name": "rating", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "ratings_user_id_series_id_season_episode_pk": { + "columns": [ + "user_id", + "series_id", + "season", + "episode" + ], + "name": "ratings_user_id_series_id_season_episode_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "tracked_series": { + "name": "tracked_series", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "saving_target": { + "name": "saving_target", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "absolute_numbering": { + "name": "absolute_numbering", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "named_seasons": { + "name": "named_seasons", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "added_at": { + "name": "added_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "tracked_series_user_id_user_id_fk": { + "name": "tracked_series_user_id_user_id_fk", + "tableFrom": "tracked_series", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "tracked_series_user_id_series_id_pk": { + "columns": [ + "user_id", + "series_id" + ], + "name": "tracked_series_user_id_series_id_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "watches": { + "name": "watches", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "series_id": { + "name": "series_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "watched_at": { + "name": "watched_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "watches_user_id_series_id_season_number_pk": { + "columns": [ + "user_id", + "series_id", + "season", + "number" + ], + "name": "watches_user_id_series_id_season_number_pk" + } + }, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/apps/server/drizzle/meta/_journal.json b/apps/server/drizzle/meta/_journal.json index 34e1f73..72c2b10 100644 --- a/apps/server/drizzle/meta/_journal.json +++ b/apps/server/drizzle/meta/_journal.json @@ -92,6 +92,20 @@ "when": 1793647652521, "tag": "0012_jellyfin_users", "breakpoints": true + }, + { + "idx": 13, + "version": "6", + "when": 1794211910011, + "tag": "0013_season_names", + "breakpoints": true + }, + { + "idx": 14, + "version": "6", + "when": 1794212193932, + "tag": "0014_named_seasons", + "breakpoints": true } ] } \ No newline at end of file diff --git a/apps/server/src/modules/catalog/domain/series.ts b/apps/server/src/modules/catalog/domain/series.ts index b75006c..159ab15 100644 --- a/apps/server/src/modules/catalog/domain/series.ts +++ b/apps/server/src/modules/catalog/domain/series.ts @@ -17,6 +17,8 @@ export interface Series { ended: boolean; /** Regular seasons only; specials (season 0) are not tracked. */ episodes: Episode[]; + /** Season number → its own name on TMDB ("Arc East Blue"), only for seasons named more than "Season 1". */ + seasonNames?: Record; fetchedAt: Date; } diff --git a/apps/server/src/modules/catalog/infrastructure/drizzle-catalog-repository.test.ts b/apps/server/src/modules/catalog/infrastructure/drizzle-catalog-repository.test.ts new file mode 100644 index 0000000..f477b35 --- /dev/null +++ b/apps/server/src/modules/catalog/infrastructure/drizzle-catalog-repository.test.ts @@ -0,0 +1,30 @@ +import { expect, test } from "bun:test"; +import type { Series } from "@/modules/catalog/domain/series"; +import { testDb } from "@/shared/testing"; +import { DrizzleCatalogRepository } from "./drizzle-catalog-repository"; + +const onePiece = (seasonNames: Record): Series => ({ + tmdbId: 37854, + tvdbId: 81797, + name: "One Piece", + year: 1999, + overview: "", + posterPath: null, + backdropPath: null, + ended: false, + episodes: [ + { season: 1, number: 1, name: "Je suis Luffy !", airDate: "1999-10-20", runtime: 24 }, + { season: 2, number: 62, name: "Laboon", airDate: "2001-03-21", runtime: 24 }, + ], + seasonNames, + fetchedAt: new Date("2026-11-09T00:00:00Z"), +}); + +test("season names are saved with the Series, and replaced on the next refresh", async () => { + const repo = new DrizzleCatalogRepository(testDb().db); + await repo.save(onePiece({ 1: "Arc East Blue", 2: "Arc Grand Line" })); + expect((await repo.get(37854))?.seasonNames).toEqual({ 1: "Arc East Blue", 2: "Arc Grand Line" }); + + await repo.save(onePiece({ 1: "Arc East Blue" })); + expect((await repo.get(37854))?.seasonNames).toEqual({ 1: "Arc East Blue" }); +}); diff --git a/apps/server/src/modules/catalog/infrastructure/drizzle-catalog-repository.ts b/apps/server/src/modules/catalog/infrastructure/drizzle-catalog-repository.ts index 2776781..8f75f57 100644 --- a/apps/server/src/modules/catalog/infrastructure/drizzle-catalog-repository.ts +++ b/apps/server/src/modules/catalog/infrastructure/drizzle-catalog-repository.ts @@ -1,7 +1,7 @@ import { and, asc, eq, inArray, lt } from "drizzle-orm"; import type { Db } from "@/shared/db"; import type { CatalogRepository, Episode, Series } from "@/modules/catalog/domain/series"; -import { episodes, series } from "./schema"; +import { episodes, seasons, series } from "./schema"; export class DrizzleCatalogRepository implements CatalogRepository { constructor(private readonly db: Db) {} @@ -15,7 +15,7 @@ export class DrizzleCatalogRepository implements CatalogRepository { if (!tmdbIds.length) return result; const ids = [...tmdbIds]; const rows = this.db.select().from(series).where(inArray(series.tmdbId, ids)).all(); - for (const row of rows) result.set(row.tmdbId, { ...row, episodes: [] }); + for (const row of rows) result.set(row.tmdbId, { ...row, episodes: [], seasonNames: {} }); const eps = this.db .select() .from(episodes) @@ -23,14 +23,21 @@ export class DrizzleCatalogRepository implements CatalogRepository { .orderBy(asc(episodes.season), asc(episodes.number)) .all(); for (const { seriesId, ...ep } of eps) result.get(seriesId)?.episodes.push(ep satisfies Episode); + for (const season of this.db.select().from(seasons).where(inArray(seasons.seriesId, ids)).all()) { + const names = result.get(season.seriesId)?.seasonNames; + if (names) names[season.number] = season.name; + } return result; } - async save({ episodes: eps, ...row }: Series) { + async save({ episodes: eps, seasonNames = {}, ...row }: Series) { this.db.transaction((tx) => { tx.insert(series).values(row).onConflictDoUpdate({ target: series.tmdbId, set: row }).run(); tx.delete(episodes).where(eq(episodes.seriesId, row.tmdbId)).run(); if (eps.length) tx.insert(episodes).values(eps.map((episode) => ({ ...episode, seriesId: row.tmdbId }))).run(); + tx.delete(seasons).where(eq(seasons.seriesId, row.tmdbId)).run(); + const named = Object.entries(seasonNames).map(([number, name]) => ({ seriesId: row.tmdbId, number: Number(number), name })); + if (named.length) tx.insert(seasons).values(named).run(); }); } diff --git a/apps/server/src/modules/catalog/infrastructure/schema.ts b/apps/server/src/modules/catalog/infrastructure/schema.ts index d1f35e0..c91b2f4 100644 --- a/apps/server/src/modules/catalog/infrastructure/schema.ts +++ b/apps/server/src/modules/catalog/infrastructure/schema.ts @@ -27,6 +27,19 @@ export const episodes = sqliteTable( (t) => [primaryKey({ columns: [t.seriesId, t.season, t.number] })], ); +/** Seasons TMDB gives a name of their own ("Arc East Blue"); a season named "Season 1" has no row. */ +export const seasons = sqliteTable( + "seasons", + { + seriesId: integer("series_id") + .notNull() + .references(() => series.tmdbId, { onDelete: "cascade" }), + number: integer("number").notNull(), + name: text("name").notNull(), + }, + (t) => [primaryKey({ columns: [t.seriesId, t.number] })], +); + /** Instance-wide settings (e.g. the TMDB key). */ export const appSettings = sqliteTable("app_settings", { key: text("key").primaryKey(), diff --git a/apps/server/src/modules/catalog/infrastructure/tmdb-client.test.ts b/apps/server/src/modules/catalog/infrastructure/tmdb-client.test.ts index 772899c..9245dc8 100644 --- a/apps/server/src/modules/catalog/infrastructure/tmdb-client.test.ts +++ b/apps/server/src/modules/catalog/infrastructure/tmdb-client.test.ts @@ -1,6 +1,6 @@ import { expect, test } from "bun:test"; import type { Series } from "@/modules/catalog/domain/series"; -import { withEnglishFallback } from "./tmdb-client"; +import { seasonName, withEnglishFallback } from "./tmdb-client"; const series = (overview: string, names: string[]): Series => ({ tmdbId: 1, @@ -30,3 +30,20 @@ test("translations are kept", () => { expect(merged.overview).toBe("Un enfant disparaît…"); expect(merged.episodes[1]?.name).toBe("Mensonges"); }); + +test("a season keeps its own name, without the number TMDB sometimes repeats in it", () => { + expect(seasonName("S01 - Arc East Blue")).toBe("Arc East Blue"); + expect(seasonName("Book One: Water")).toBe("Book One: Water"); + expect(seasonName("Saison 2")).toBeNull(); + expect(seasonName("Season 12")).toBeNull(); + expect(seasonName("S03 - Saison 3")).toBeNull(); + expect(seasonName(" ")).toBeNull(); +}); + +test("season names TMDB has not translated fall back to English", () => { + const merged = withEnglishFallback( + { ...series("", []), seasonNames: { 1: "Arc East Blue" } }, + { ...series("", []), seasonNames: { 1: "East Blue", 2: "Entering into the Grand Line" } }, + ); + expect(merged.seasonNames).toEqual({ 1: "Arc East Blue", 2: "Entering into the Grand Line" }); +}); diff --git a/apps/server/src/modules/catalog/infrastructure/tmdb-client.ts b/apps/server/src/modules/catalog/infrastructure/tmdb-client.ts index 63710b9..f72a990 100644 --- a/apps/server/src/modules/catalog/infrastructure/tmdb-client.ts +++ b/apps/server/src/modules/catalog/infrastructure/tmdb-client.ts @@ -24,7 +24,7 @@ interface TmdbShow { status: string; networks: { name: string }[]; origin_country: string[]; - seasons: { season_number: number }[]; + seasons: { season_number: number; name?: string | null }[]; external_ids?: { tvdb_id: number | null }; [appended: `season/${number}`]: { episodes: TmdbEpisode[] } | undefined; } @@ -72,11 +72,24 @@ export async function isValidTmdbKey(key: string): Promise { /** TMDB's placeholder when an episode has no translated title ("Épisode 5", "Folge 5"…). */ const GENERIC_EPISODE_NAME = /^(episode|épisode|episodio|episódio|folge|aflevering|odcinek|エピソード)\s*\d+$/i; -/** Fills what TMDB has not translated (empty overview, placeholder episode names) from English. */ +/** TMDB's default season name, "Season 2" in each language: it says nothing the number doesn't. */ +const GENERIC_SEASON_NAME = /^(season|saison|staffel|temporada|stagione|seizoen|sezon|series|シーズン)\s*\d+$/i; + +/** + * A season's own name, or null when TMDB only numbers it. Drops a leading "S01 - ", which repeats the number: + * "S01 - Arc East Blue" → "Arc East Blue". + */ +export function seasonName(name: string): string | null { + const own = name.trim().replace(/^S\d+\s*[-–—:]\s*/i, ""); + return own && !GENERIC_SEASON_NAME.test(own) ? own : null; +} + +/** Fills what TMDB has not translated (empty overview, placeholder episode and season names) from English. */ export function withEnglishFallback(localized: Series, english: Series): Series { const englishNames = new Map(english.episodes.map((episode) => [`${episode.season}x${episode.number}`, episode.name])); return { ...localized, + seasonNames: { ...english.seasonNames, ...localized.seasonNames }, overview: localized.overview || english.overview, posterPath: localized.posterPath ?? english.posterPath, backdropPath: localized.backdropPath ?? english.backdropPath, @@ -109,6 +122,11 @@ export class TmdbClient implements SeriesSource { private async fetchIn(tmdbId: number, language: string): Promise { const show = await this.get(`/tv/${tmdbId}`, { language, append_to_response: "external_ids" }); const seasons = show.seasons.map((season) => season.season_number).filter((number) => number > 0); + const seasonNames: Record = {}; + for (const season of show.seasons) { + const name = season.season_number > 0 ? seasonName(season.name ?? "") : null; + if (name) seasonNames[season.season_number] = name; + } const release = releaseOf( show.networks.map((network) => network.name), show.origin_country, @@ -136,6 +154,7 @@ export class TmdbClient implements SeriesSource { backdropPath: show.backdrop_path, ended: show.status === "Ended" || show.status === "Canceled", episodes, + seasonNames, fetchedAt: new Date(), }; } diff --git a/apps/server/src/modules/import/application/import-service.test.ts b/apps/server/src/modules/import/application/import-service.test.ts index a453682..e5a177d 100644 --- a/apps/server/src/modules/import/application/import-service.test.ts +++ b/apps/server/src/modules/import/application/import-service.test.ts @@ -72,19 +72,19 @@ test("an Export imported into an empty account exports the same", async () => { const watch = (number: number, day: string) => ({ season: 1, number, watchedAt: startOf(day) }); await tracking.import("a", [ { seriesId: 1, status: "watching", watches: [watch(1, "2024-02-18")], ratings: [{ season: 0, rating: 9 }, { season: 2, rating: 7 }] }, - { seriesId: 2, status: "saving", watches: [watch(2, "2024-03-01"), watch(1, "2024-02-28")], savingTarget: 5, absoluteNumbering: true }, + { seriesId: 2, status: "saving", watches: [watch(2, "2024-03-01"), watch(1, "2024-02-28")], savingTarget: 5, absoluteNumbering: true, namedSeasons: true }, { seriesId: 3, status: "watchlist", watches: [] }, ]); const csv = await importer.exportCsv("a"); expect(csv).toBe( [ - "title,tmdb_id,season,episode,watched_at,status,rating,season_rating,saving_target,absolute_numbering", - "Dark,2,1,1,2024-02-28,saving,,,5,true", - "Dark,2,1,2,2024-03-01,saving,,,5,true", - '"Love, Death & ""Robots""",1,1,1,2024-02-18,watching,9,,0,false', - '"Love, Death & ""Robots""",1,2,,,watching,9,7,0,false', - "Severance,3,,,,watchlist,,,0,false", + "title,tmdb_id,season,episode,watched_at,status,rating,season_rating,saving_target,absolute_numbering,named_seasons", + "Dark,2,1,1,2024-02-28,saving,,,5,true,true", + "Dark,2,1,2,2024-03-01,saving,,,5,true,true", + '"Love, Death & ""Robots""",1,1,1,2024-02-18,watching,9,,0,false,false', + '"Love, Death & ""Robots""",1,2,,,watching,9,7,0,false,false', + "Severance,3,,,,watchlist,,,0,false,false", "", ].join("\n"), ); diff --git a/apps/server/src/modules/import/domain/csv-export.ts b/apps/server/src/modules/import/domain/csv-export.ts index f5a47fc..99b44b7 100644 --- a/apps/server/src/modules/import/domain/csv-export.ts +++ b/apps/server/src/modules/import/domain/csv-export.ts @@ -13,7 +13,7 @@ const cell = (value: Cell) => { /** * The Export: the Import's CSV (see csv-import.ts), so Snug reads it back without loss. One row per Watch, * watched_at as a Day; a rated season with no Watch gets a row of its own, a Series with neither gets one - * row with no season. The Series' own fields (status, rating, saving_target, absolute_numbering) repeat on each row. + * row with no season. The Series' own fields (status, rating, saving_target, absolute_numbering, named_seasons) repeat on each row. */ export function writeCsvExport(list: readonly TrackedSeries[], titleOf: (seriesId: number) => string): string { const sorted = [...list].sort((a, b) => titleOf(a.seriesId).localeCompare(titleOf(b.seriesId)) || a.seriesId - b.seriesId); @@ -31,6 +31,7 @@ export function writeCsvExport(list: readonly TrackedSeries[], titleOf: (seriesI season === null ? null : tracked.ratingOf(season), tracked.savingTarget, tracked.absoluteNumbering, + tracked.namedSeasons, ] .map(cell) .join(","); diff --git a/apps/server/src/modules/import/domain/csv-import.ts b/apps/server/src/modules/import/domain/csv-import.ts index 75c9409..ab13458 100644 --- a/apps/server/src/modules/import/domain/csv-import.ts +++ b/apps/server/src/modules/import/domain/csv-import.ts @@ -7,11 +7,11 @@ import { t } from "@/shared/i18n"; /** * CSV import, one row per watched Episode (or per Series to just add it): - * title,tmdb_id,season,episode,watched_at,status,rating,season_rating,saving_target,absolute_numbering + * title,tmdb_id,season,episode,watched_at,status,rating,season_rating,saving_target,absolute_numbering,named_seasons * Either `title` or `tmdb_id` is required; everything else is optional. `rating` rates the Series and * `season_rating` the row's season, out of 10; a row may give a season and its rating without an episode. - * `saving_target` (0 for a full season, or 3, 5, 10 Episodes) and `absolute_numbering` (true/false) are the - * Series' own, like `status`. It is also the Export's format (see csv-export.ts). + * `saving_target` (0 for a full season, or 3, 5, 10 Episodes), `absolute_numbering` and `named_seasons` (true/false) + * are the Series' own, like `status`. It is also the Export's format (see csv-export.ts). */ export interface CsvRow { @@ -26,6 +26,7 @@ export interface CsvRow { seasonRating?: number; savingTarget?: SavingTarget; absoluteNumbering?: boolean; + namedSeasons?: boolean; } export class CsvImportError extends Error { @@ -76,6 +77,7 @@ export const COLUMNS = [ "season_rating", "saving_target", "absolute_numbering", + "named_seasons", ] as const; export function parseCsvImport(text: string): CsvRow[] { @@ -131,11 +133,15 @@ export function parseCsvImport(text: string): CsvRow[] { row.savingTarget = SAVING_TARGETS.find((target) => String(target) === savingTarget); if (row.savingTarget === undefined) problems.push(t().csv.notASavingTarget(line, SAVING_TARGETS.join(", "))); } - const absoluteNumbering = get("absolute_numbering").toLowerCase(); - if (absoluteNumbering) { - row.absoluteNumbering = absoluteNumbering === "true" ? true : absoluteNumbering === "false" ? false : undefined; - if (row.absoluteNumbering === undefined) problems.push(t().csv.notABoolean(line, "absolute_numbering")); - } + const boolean = (column: "absolute_numbering" | "named_seasons") => { + const raw = get(column).toLowerCase(); + if (!raw) return undefined; + if (raw === "true" || raw === "false") return raw === "true"; + problems.push(t().csv.notABoolean(line, column)); + return undefined; + }; + row.absoluteNumbering = boolean("absolute_numbering"); + row.namedSeasons = boolean("named_seasons"); const status = get("status").toLowerCase(); if (status) { @@ -153,7 +159,7 @@ export function parseCsvImport(text: string): CsvRow[] { /** * Groups rows into one entry per Series. `seriesIdOf` turns a title into a TMDB id (null when not found). * Status: the last explicit one wins; otherwise Watching when something was watched, Watchlist when not. - * Ratings, saving_target and absolute_numbering: the last one given wins. + * Ratings, saving_target, absolute_numbering and named_seasons: the last one given wins. */ export function csvRowsToEntries(rows: CsvRow[], seriesIdOf: (title: string) => number | null, now: Date): ImportEntry[] { const entries = new Map(); @@ -168,6 +174,7 @@ export function csvRowsToEntries(rows: CsvRow[], seriesIdOf: (title: string) => if (row.status) Object.assign(entry, { status: row.status, explicit: true }); if (row.savingTarget !== undefined) entry.savingTarget = row.savingTarget; if (row.absoluteNumbering !== undefined) entry.absoluteNumbering = row.absoluteNumbering; + if (row.namedSeasons !== undefined) entry.namedSeasons = row.namedSeasons; const ratings = new Map((entry.ratings ?? []).map((rating) => [rating.season, rating.rating])); if (row.rating) ratings.set(WHOLE_SERIES, row.rating); if (row.seasonRating && row.season) ratings.set(row.season, row.seasonRating); diff --git a/apps/server/src/modules/mcp/tools.ts b/apps/server/src/modules/mcp/tools.ts index e66c24b..23688ec 100644 --- a/apps/server/src/modules/mcp/tools.ts +++ b/apps/server/src/modules/mcp/tools.ts @@ -206,7 +206,7 @@ export function registerTools( "series", { description: - "One series in detail, tracked or not: its seasons and episodes, the day each one was first watched (watchedAt, null when not watched), the next one. An episode's name is null when the user's spoiler shield hides it: don't look the title up elsewhere. Episodes carry their absolute number across seasons; with absoluteNumbering, the user calls them by it (\"episode 1156\").", + "One series in detail, tracked or not: its seasons (with their own name when TMDB gives one, e.g. a story arc; with namedSeasons, the user calls seasons by it) and episodes, the day each one was first watched (watchedAt, null when not watched), the next one. An episode's name is null when the user's spoiler shield hides it: don't look the title up elsewhere. Episodes carry their absolute number across seasons; with absoluteNumbering, the user calls them by it (\"episode 1156\").", inputSchema: { tmdbId }, annotations: { readOnlyHint: true }, }, @@ -224,11 +224,13 @@ export function registerTools( tracked: detail.tracked, status: detail.tracked ? detail.status : null, absoluteNumbering: detail.absoluteNumbering, + namedSeasons: detail.namedSeasons, progress: detail.progress, next: detail.next && { season: detail.next.season, number: detail.next.number, absolute: detail.next.absolute, airDate: detail.next.airDate }, rating: detail.rating, seasons: detail.seasons.map((season) => ({ number: season.number, + name: season.name, rating: season.rating, episodes: season.episodes.map((episode) => ({ number: episode.number, diff --git a/apps/server/src/modules/tracking/application/tracking-service.test.ts b/apps/server/src/modules/tracking/application/tracking-service.test.ts index 0f76d44..445c3c1 100644 --- a/apps/server/src/modules/tracking/application/tracking-service.test.ts +++ b/apps/server/src/modules/tracking/application/tracking-service.test.ts @@ -222,3 +222,22 @@ test("Absolute numbering is kept per User and Series, and the Episodes carry the await tracking.numberAbsolutely("u", 1, false); expect((await tracking.library("u"))[0]?.absoluteNumbering).toBe(false); }); + +test("Named seasons is kept per User and Series; the detail gives the names TMDB has", async () => { + const { db } = testDb(["u", "v"]); + const show = series(1, false, ["2026-10-01", "2026-10-08"]); + show.episodes = show.episodes.map((episode, index) => (index === 1 ? { ...episode, season: 2, number: 1 } : episode)); + show.seasonNames = { 1: "Arc East Blue" }; + const catalog: CatalogPort = { ensure: async () => show, getMany: async () => new Map([[1, show]]) }; + const tracking = new TrackingService(new DrizzleTrackedSeriesRepository(db), catalog, undefined, () => now); + await tracking.track("u", 1); + await tracking.track("v", 1); + + expect((await tracking.detail("u", 1)).namedSeasons).toBe(false); + await tracking.nameSeasons("u", 1, true); + const detail = await tracking.detail("u", 1); + expect(detail.namedSeasons).toBe(true); + expect(detail.absoluteNumbering).toBe(false); + expect(detail.seasons.map((season) => [season.number, season.name])).toEqual([[1, "Arc East Blue"], [2, null]]); + expect((await tracking.detail("v", 1)).namedSeasons).toBe(false); +}); diff --git a/apps/server/src/modules/tracking/application/tracking-service.ts b/apps/server/src/modules/tracking/application/tracking-service.ts index 99aa25d..7b83e30 100644 --- a/apps/server/src/modules/tracking/application/tracking-service.ts +++ b/apps/server/src/modules/tracking/application/tracking-service.ts @@ -40,6 +40,7 @@ export interface ImportEntry { /** Like `status`, they only apply to a Series not tracked yet. */ savingTarget?: SavingTarget; absoluteNumbering?: boolean; + namedSeasons?: boolean; } export class TrackingService { @@ -169,6 +170,15 @@ export class TrackingService { }); } + /** Named seasons on or off for a tracked Series. */ + async nameSeasons(userId: string, seriesId: number, on: boolean) { + await this.exclusive(userId, seriesId, async () => { + const tracked = await this.get(userId, seriesId); + tracked.nameSeasons(on); + await this.repo.save(tracked); + }); + } + async watchSeason(userId: string, seriesId: number, season: number) { const series = await this.catalog.ensure(seriesId); await this.exclusive(userId, seriesId, async () => { @@ -183,9 +193,10 @@ export class TrackingService { async import(userId: string, entries: ImportEntry[]): Promise { for (const entry of entries) { await this.exclusive(userId, entry.seriesId, async () => { + const found = await this.repo.find(userId, entry.seriesId); const tracked = - (await this.repo.find(userId, entry.seriesId)) ?? - TrackedSeries.start(userId, entry.seriesId, entry.status, this.now(), entry.savingTarget, entry.absoluteNumbering); + found ?? TrackedSeries.start(userId, entry.seriesId, entry.status, this.now(), entry.savingTarget, entry.absoluteNumbering); + if (!found && entry.namedSeasons !== undefined) tracked.nameSeasons(entry.namedSeasons); tracked.merge(entry.watches); tracked.mergeRatings(entry.ratings ?? []); await this.repo.save(tracked); @@ -245,7 +256,12 @@ export class TrackingService { const numbered = numberAbsolutely(series.episodes); const seasons = new Map(); for (const episode of series.episodes) { - const season = seasons.get(episode.season) ?? { number: episode.season, rating: tracked.ratingOf(episode.season), episodes: [] }; + const season = seasons.get(episode.season) ?? { + number: episode.season, + name: series.seasonNames?.[episode.season] ?? null, + rating: tracked.ratingOf(episode.season), + episodes: [], + }; season.episodes.push({ ...numbered(episode), watched: tracked.hasWatched(episode), @@ -260,6 +276,7 @@ export class TrackingService { tracked: !!found, overview: series.overview, ended: series.ended, + namedSeasons: tracked.namedSeasons, seasons: [...seasons.values()], }; } diff --git a/apps/server/src/modules/tracking/domain/tracked-series.ts b/apps/server/src/modules/tracking/domain/tracked-series.ts index 4f1032e..3fe39ca 100644 --- a/apps/server/src/modules/tracking/domain/tracked-series.ts +++ b/apps/server/src/modules/tracking/domain/tracked-series.ts @@ -59,6 +59,7 @@ export class TrackedSeries { private _savingTarget: SavingTarget = 0, private readonly _ratings = new Map(), private _absoluteNumbering = false, + private _namedSeasons = false, ) {} static start(userId: string, seriesId: number, status: Status, now: Date, savingTarget: SavingTarget = 0, absoluteNumbering = false) { @@ -74,10 +75,11 @@ export class TrackedSeries { savingTarget: SavingTarget; ratings?: Rating[]; absoluteNumbering?: boolean; + namedSeasons?: boolean; }) { const watches = new Map(p.watches.map((watch) => [keyOf(watch), watch])); const ratings = new Map((p.ratings ?? []).map((rating) => [rating.season, rating.rating])); - return new TrackedSeries(p.userId, p.seriesId, p.status, watches, p.addedAt, p.savingTarget, ratings, p.absoluteNumbering); + return new TrackedSeries(p.userId, p.seriesId, p.status, watches, p.addedAt, p.savingTarget, ratings, p.absoluteNumbering, p.namedSeasons); } get status() { @@ -97,6 +99,15 @@ export class TrackedSeries { this._absoluteNumbering = on; } + /** Named seasons: the User reads this Series' seasons by their own name on TMDB ("Arc East Blue"). */ + get namedSeasons() { + return this._namedSeasons; + } + + nameSeasons(on: boolean) { + this._namedSeasons = on; + } + get watches(): Watch[] { return [...this._watches.values()]; } diff --git a/apps/server/src/modules/tracking/http/routes.ts b/apps/server/src/modules/tracking/http/routes.ts index f7e6506..134c8d7 100644 --- a/apps/server/src/modules/tracking/http/routes.ts +++ b/apps/server/src/modules/tracking/http/routes.ts @@ -48,6 +48,11 @@ export const trackingRoutes = (tracking: TrackingService) => await tracking.numberAbsolutely(c.var.user.id, parse(id, c.req.param("id")), on); return c.body(null, 204); }) + .put("/series/:id/named-seasons", async (c) => { + const { on } = parse(z.object({ on: z.boolean() }), await jsonBody(c)); + await tracking.nameSeasons(c.var.user.id, parse(id, c.req.param("id")), on); + return c.body(null, 204); + }) .put("/series/:id/rating", async (c) => { await tracking.rate(c.var.user.id, parse(id, c.req.param("id")), parse(rating, await jsonBody(c))); return c.body(null, 204); diff --git a/apps/server/src/modules/tracking/infrastructure/drizzle-tracked-series-repository.ts b/apps/server/src/modules/tracking/infrastructure/drizzle-tracked-series-repository.ts index fed8a33..8f4db17 100644 --- a/apps/server/src/modules/tracking/infrastructure/drizzle-tracked-series-repository.ts +++ b/apps/server/src/modules/tracking/infrastructure/drizzle-tracked-series-repository.ts @@ -49,13 +49,14 @@ export class DrizzleTrackedSeriesRepository implements TrackedSeriesRepository { addedAt: t.addedAt, savingTarget: t.savingTarget, absoluteNumbering: t.absoluteNumbering, + namedSeasons: t.namedSeasons, }; this.db.transaction((tx) => { tx.insert(trackedSeries) .values(row) .onConflictDoUpdate({ target: [trackedSeries.userId, trackedSeries.seriesId], - set: { status: t.status, savingTarget: t.savingTarget, absoluteNumbering: t.absoluteNumbering }, + set: { status: t.status, savingTarget: t.savingTarget, absoluteNumbering: t.absoluteNumbering, namedSeasons: t.namedSeasons }, }) .run(); tx.delete(watches).where(key).run(); diff --git a/apps/server/src/modules/tracking/infrastructure/schema.ts b/apps/server/src/modules/tracking/infrastructure/schema.ts index 2845a69..acfb2c3 100644 --- a/apps/server/src/modules/tracking/infrastructure/schema.ts +++ b/apps/server/src/modules/tracking/infrastructure/schema.ts @@ -15,6 +15,8 @@ export const trackedSeries = sqliteTable( savingTarget: integer("saving_target").$type().notNull().default(0), /** Absolute numbering: Episodes read as "Ep. 1156" rather than SxxEyy. */ absoluteNumbering: integer("absolute_numbering", { mode: "boolean" }).notNull().default(false), + /** Named seasons: seasons titled by their own name on TMDB ("Arc East Blue") rather than "Season 1". */ + namedSeasons: integer("named_seasons", { mode: "boolean" }).notNull().default(false), addedAt: integer("added_at", { mode: "timestamp" }).notNull(), }, (t) => [primaryKey({ columns: [t.userId, t.seriesId] })], diff --git a/apps/web/src/components/series/season.tsx b/apps/web/src/components/series/season.tsx index b21e11b..bc4e8c4 100644 --- a/apps/web/src/components/series/season.tsx +++ b/apps/web/src/components/series/season.tsx @@ -28,6 +28,7 @@ export function Season({ series, season }: { series: SeriesDetail; season: Seaso const current = series.next?.season ?? series.seasons.at(-1)?.number; const showProgress = aired > 0 && (seasonProgress === "all" || season.number === current); const base = `/series/${series.seriesId}`; + const title = (series.namedSeasons && season.name) || t.series.season(season.number); const toggle = useMutation({ mutationFn: (e: { number: number; watched: boolean }) => @@ -58,7 +59,7 @@ export function Season({ series, season }: { series: SeriesDetail; season: Seaso aria-expanded={open} className="flex min-w-0 flex-1 items-center gap-3 py-4 pl-5 text-left" > -

{t.series.season(season.number)}

+

{title}

{t.series.episodesWatched(watched, season.episodes.length)} {series.tracked && showRatings && ( @@ -72,7 +73,7 @@ export function Season({ series, season }: { series: SeriesDetail; season: Seaso