From 8748cc1098d64dc9ef96aa854d3316bd858e8590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Tonh=C3=A4user?= Date: Tue, 1 Dec 2026 00:35:36 +0100 Subject: [PATCH] Release 2.4.1: import older Immich albums into the calendar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Admin calendar: "Ältere Alben übernehmen" lists albums named "Titel | TT.MM.JJJJ" without an event (preview, all preselected, optional category) and creates linked events in one transaction. Albums without a date suffix are never offered. - Editorials now see all past events; the past list is collapsible and a click in the month view opens it. - Release notes 2.4.1 seeded (migration 0010). Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 2 +- AI_MEMORY.md | 1 + drizzle/0010_release_notes_2_4_1.sql | 6 + drizzle/meta/0010_snapshot.json | 2585 +++++++++++++++++++++ drizzle/meta/_journal.json | 7 + src/app/admin/kalender/AlbumImport.tsx | 121 + src/app/admin/kalender/actions.ts | 23 + src/app/admin/kalender/page.tsx | 14 +- src/app/redaktion/kalender/actions.ts | 1 + src/app/redaktion/kalender/page.tsx | 109 +- src/components/calendar/event-month.tsx | 2 + src/components/layout/release-notes.tsx | 4 +- src/modules/calendar/event-albums.test.ts | 14 +- src/modules/calendar/event-albums.ts | 18 + src/modules/calendar/service.test.ts | 78 +- src/modules/calendar/service.ts | 118 +- 16 files changed, 3025 insertions(+), 78 deletions(-) create mode 100644 drizzle/0010_release_notes_2_4_1.sql create mode 100644 drizzle/meta/0010_snapshot.json create mode 100644 src/app/admin/kalender/AlbumImport.tsx diff --git a/AGENTS.md b/AGENTS.md index 0f68977..ce7720c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -27,7 +27,7 @@ Kalender/Selbstbedienung/Sortierung/Beschreibung: `2.1.0`, Dateiname-Suche: `2.1.1`, Statistik/Collab/Rechnungsversand: `2.2.0`, Quartalsabrechnung + Sakani-Formulare: `2.2.1`, Versionshistorie: `2.2.2`, Kategorien/Vormerken/Monatskalender/Dashboard: `2.3.0`, -Mehrfach-Download/Toasts/Sakani-Feinschliff: `2.4.0`). +Mehrfach-Download/Toasts/Sakani-Feinschliff: `2.4.0`, Album-Import im Kalender: `2.4.1`). ## Sicherheit (bei jeder Änderung mitprüfen) diff --git a/AI_MEMORY.md b/AI_MEMORY.md index 3718cb6..9d7329e 100644 --- a/AI_MEMORY.md +++ b/AI_MEMORY.md @@ -100,4 +100,5 @@ Redaktionen können Bilder durchsuchen, einen Leuchtkasten verwenden, Bilder her - **Albenübersicht:** Blog-Listing-Optik (randloses 3:2-Cover, Anzahl, Titel, Beschreibung); Cover ist dekorativ (`alt=""`), der Titel im Link benennt es. Skeletons hinter Covern/Fotokacheln und in `loading.tsx`. - **Registrierung:** `RegistrationSteps` (Sakani `Stepper`, mobil vertikal). Die Bestätigungsmail führt auf `/registrieren/bestaetigt?schritt=freigabe` (Schritt 3), das Formular auf die Seite ohne Parameter (Schritt 2). - **Redaktionen:** `EditorialsTable` (Client, Sakani `Table` + Suche + Statusfilter; "Alle" ohne Archivierte). **Audit:** Ereignis als Auswahl der vorhandenen Typen (`selectDistinct`), deutsche Bezeichnungen (`EVENT_LABELS` in `src/app/admin/audit/page.tsx`, neue Audit-Typen dort ergänzen), Details aufklappbar. +- **Album-Import (2.4.1):** `/admin/kalender` → "Ältere Alben übernehmen". `parseAlbumEventName` (`event-albums.ts`) liest `Titel | TT.MM.JJJJ`; `listImportableAlbums` bietet nur datierte Alben ohne passenden Termin an (private Alben ohne Datum nie), `importAlbums` rechnet die Liste serverseitig neu, legt Termine mit expliziter `immich_album_id` in einer Transaktion an (max. 500), optional mit Kategorie, Audit `calendar_events_imported`. Redaktionen sehen seitdem ALLE vergangenen Termine (kein 30-Tage-Fenster mehr); die Liste "Vergangene Termine" ist einklappbar, ein Klick im Monatskalender öffnet sie. diff --git a/drizzle/0010_release_notes_2_4_1.sql b/drizzle/0010_release_notes_2_4_1.sql new file mode 100644 index 0000000..89b0486 --- /dev/null +++ b/drizzle/0010_release_notes_2_4_1.sql @@ -0,0 +1,6 @@ +-- Custom SQL migration file, put your code below! -- +INSERT INTO "release_notes" ("version", "audience", "body", "created_by_user_id") +VALUES + ('2.4.1', 'admin', 'Ältere Alben übernehmen: Unter Kalender zeigt „Alben aus Immich anzeigen“ alle Alben im Format „Titel | TT.MM.JJJJ“, die noch keinen Termin haben. Auswählen, optional eine Kategorie setzen und übernehmen; Titel und Datum kommen aus dem Albumnamen.', NULL), + ('2.4.1', 'editorial', 'Im Kalender stehen jetzt auch ältere Spiele. Sie können sie wie neue mit „Zu meinen Alben hinzufügen“ freischalten.', NULL) +ON CONFLICT ("version", "audience") DO NOTHING; diff --git a/drizzle/meta/0010_snapshot.json b/drizzle/meta/0010_snapshot.json new file mode 100644 index 0000000..1dbc7e0 --- /dev/null +++ b/drizzle/meta/0010_snapshot.json @@ -0,0 +1,2585 @@ +{ + "id": "0546354d-47aa-4619-b295-e02eda57ea46", + "prevId": "4b7779b1-b137-41ec-9d2b-5359564b1085", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.activity_events": { + "name": "activity_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "editorial_account_id": { + "name": "editorial_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "event_type": { + "name": "event_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "immich_album_id": { + "name": "immich_album_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "immich_asset_id": { + "name": "immich_asset_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "query": { + "name": "query", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "occurred_at": { + "name": "occurred_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "activity_events_occurred_at_idx": { + "name": "activity_events_occurred_at_idx", + "columns": [ + { + "expression": "occurred_at", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "activity_events_editorial_occurred_idx": { + "name": "activity_events_editorial_occurred_idx", + "columns": [ + { + "expression": "editorial_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "occurred_at", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "activity_events_type_occurred_idx": { + "name": "activity_events_type_occurred_idx", + "columns": [ + { + "expression": "event_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "occurred_at", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "activity_events_editorial_account_id_editorial_accounts_id_fk": { + "name": "activity_events_editorial_account_id_editorial_accounts_id_fk", + "tableFrom": "activity_events", + "columnsFrom": [ + "editorial_account_id" + ], + "tableTo": "editorial_accounts", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "activity_events_event_type_check": { + "name": "activity_events_event_type_check", + "value": "\"activity_events\".\"event_type\" in ('album_view', 'search', 'lightbox_view')" + } + }, + "isRLSEnabled": false + }, + "public.album_grants": { + "name": "album_grants", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "editorial_account_id": { + "name": "editorial_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "immich_album_id": { + "name": "immich_album_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "granted_at": { + "name": "granted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "granted_by_user_id": { + "name": "granted_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'admin'" + } + }, + "indexes": { + "album_grants_editorial_account_id_idx": { + "name": "album_grants_editorial_account_id_idx", + "columns": [ + { + "expression": "editorial_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "album_grants_immich_album_id_idx": { + "name": "album_grants_immich_album_id_idx", + "columns": [ + { + "expression": "immich_album_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "album_grants_editorial_active_album_unique": { + "name": "album_grants_editorial_active_album_unique", + "columns": [ + { + "expression": "editorial_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"immich_album_id\")", + "isExpression": true, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "where": "\"album_grants\".\"revoked_at\" is null", + "concurrently": false + } + }, + "foreignKeys": { + "album_grants_editorial_account_id_editorial_accounts_id_fk": { + "name": "album_grants_editorial_account_id_editorial_accounts_id_fk", + "tableFrom": "album_grants", + "columnsFrom": [ + "editorial_account_id" + ], + "tableTo": "editorial_accounts", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "album_grants_granted_by_user_id_user_id_fk": { + "name": "album_grants_granted_by_user_id_user_id_fk", + "tableFrom": "album_grants", + "columnsFrom": [ + "granted_by_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "album_grants_immich_album_id_uuid_check": { + "name": "album_grants_immich_album_id_uuid_check", + "value": "\"album_grants\".\"immich_album_id\" ~* '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'" + }, + "album_grants_source_check": { + "name": "album_grants_source_check", + "value": "\"album_grants\".\"source\" in ('admin', 'auto_rule', 'self_service')" + } + }, + "isRLSEnabled": false + }, + "public.announcements": { + "name": "announcements", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "event_date": { + "name": "event_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "announcements_created_by_user_id_user_id_fk": { + "name": "announcements_created_by_user_id_user_id_fk", + "tableFrom": "announcements", + "columnsFrom": [ + "created_by_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.audit_events": { + "name": "audit_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "event_type": { + "name": "event_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "actor_user_id": { + "name": "actor_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "actor_type": { + "name": "actor_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'system'" + }, + "entity_type": { + "name": "entity_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "previous_values": { + "name": "previous_values", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "new_values": { + "name": "new_values", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "occurred_at": { + "name": "occurred_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "request_id": { + "name": "request_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "audit_events_actor_user_id_user_id_fk": { + "name": "audit_events_actor_user_id_user_id_fk", + "tableFrom": "audit_events", + "columnsFrom": [ + "actor_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.account": { + "name": "account", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "account_user_id_user_id_fk": { + "name": "account_user_id_user_id_fk", + "tableFrom": "account", + "columnsFrom": [ + "user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.session": { + "name": "session", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "session_user_id_user_id_fk": { + "name": "session_user_id_user_id_fk", + "tableFrom": "session", + "columnsFrom": [ + "user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "session_token_unique": { + "name": "session_token_unique", + "columns": [ + "token" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.two_factor": { + "name": "two_factor", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "secret": { + "name": "secret", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "backup_codes": { + "name": "backup_codes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "verified": { + "name": "verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "failed_verification_count": { + "name": "failed_verification_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "locked_until": { + "name": "locked_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "two_factor_user_id_user_id_fk": { + "name": "two_factor_user_id_user_id_fk", + "tableFrom": "two_factor", + "columnsFrom": [ + "user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "two_factor_user_id_unique": { + "name": "two_factor_user_id_unique", + "columns": [ + "user_id" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user": { + "name": "user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email_verified": { + "name": "email_verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "portal_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'EDITORIAL'" + }, + "two_factor_enabled": { + "name": "two_factor_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_email_unique": { + "name": "user_email_unique", + "columns": [ + "email" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.verification": { + "name": "verification", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.album_auto_rules": { + "name": "album_auto_rules", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "editorial_account_id": { + "name": "editorial_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "keyword": { + "name": "keyword", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "album_auto_rules_editorial_account_id_keyword_idx": { + "name": "album_auto_rules_editorial_account_id_keyword_idx", + "columns": [ + { + "expression": "editorial_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"keyword\")", + "isExpression": true, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "album_auto_rules_editorial_account_id_editorial_accounts_id_fk": { + "name": "album_auto_rules_editorial_account_id_editorial_accounts_id_fk", + "tableFrom": "album_auto_rules", + "columnsFrom": [ + "editorial_account_id" + ], + "tableTo": "editorial_accounts", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "album_auto_rules_created_by_user_id_user_id_fk": { + "name": "album_auto_rules_created_by_user_id_user_id_fk", + "tableFrom": "album_auto_rules", + "columnsFrom": [ + "created_by_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.billing_report_items": { + "name": "billing_report_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "billing_report_id": { + "name": "billing_report_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "usage_id": { + "name": "usage_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "immich_asset_id_snapshot": { + "name": "immich_asset_id_snapshot", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "filename_snapshot": { + "name": "filename_snapshot", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "album_name_snapshot": { + "name": "album_name_snapshot", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "purpose_snapshot": { + "name": "purpose_snapshot", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "internal_reference_snapshot": { + "name": "internal_reference_snapshot", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "price_cents": { + "name": "price_cents", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "collab": { + "name": "collab", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "billing_report_items_report_usage_unique": { + "name": "billing_report_items_report_usage_unique", + "columns": [ + { + "expression": "billing_report_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "usage_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "billing_report_items_billing_report_id_billing_reports_id_fk": { + "name": "billing_report_items_billing_report_id_billing_reports_id_fk", + "tableFrom": "billing_report_items", + "columnsFrom": [ + "billing_report_id" + ], + "tableTo": "billing_reports", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "billing_report_items_usage_id_usages_id_fk": { + "name": "billing_report_items_usage_id_usages_id_fk", + "tableFrom": "billing_report_items", + "columnsFrom": [ + "usage_id" + ], + "tableTo": "usages", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.billing_reports": { + "name": "billing_reports", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "report_number": { + "name": "report_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "editorial_account_id": { + "name": "editorial_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "period_starts_at": { + "name": "period_starts_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "period_ends_at": { + "name": "period_ends_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "billing_address_snapshot": { + "name": "billing_address_snapshot", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "invoice_number": { + "name": "invoice_number", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "net_total_cents": { + "name": "net_total_cents", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "flatrate_cents_snapshot": { + "name": "flatrate_cents_snapshot", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "report_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'draft'" + }, + "pdf": { + "name": "pdf", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "pdf_sha256": { + "name": "pdf_sha256", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "invoice_pdf": { + "name": "invoice_pdf", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "invoice_pdf_sha256": { + "name": "invoice_pdf_sha256", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "invoice_pdf_filename": { + "name": "invoice_pdf_filename", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "invoice_uploaded_at": { + "name": "invoice_uploaded_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "invoice_email_status": { + "name": "invoice_email_status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'not_sent'" + }, + "invoice_email_sent_at": { + "name": "invoice_email_sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "invoice_email_error": { + "name": "invoice_email_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "finalized_at": { + "name": "finalized_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancellation_reason": { + "name": "cancellation_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "cancelled_by_user_id": { + "name": "cancelled_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "billing_reports_report_number_unique": { + "name": "billing_reports_report_number_unique", + "columns": [ + { + "expression": "report_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + }, + "billing_reports_invoice_number_unique": { + "name": "billing_reports_invoice_number_unique", + "columns": [ + { + "expression": "invoice_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "billing_reports_editorial_account_id_editorial_accounts_id_fk": { + "name": "billing_reports_editorial_account_id_editorial_accounts_id_fk", + "tableFrom": "billing_reports", + "columnsFrom": [ + "editorial_account_id" + ], + "tableTo": "editorial_accounts", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "billing_reports_created_by_user_id_user_id_fk": { + "name": "billing_reports_created_by_user_id_user_id_fk", + "tableFrom": "billing_reports", + "columnsFrom": [ + "created_by_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "billing_reports_cancelled_by_user_id_user_id_fk": { + "name": "billing_reports_cancelled_by_user_id_user_id_fk", + "tableFrom": "billing_reports", + "columnsFrom": [ + "cancelled_by_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "billing_reports_pdf_sha256_hex_check": { + "name": "billing_reports_pdf_sha256_hex_check", + "value": "\"billing_reports\".\"pdf_sha256\" ~ '^[0-9a-f]{64}$'" + }, + "billing_reports_invoice_pdf_sha256_hex_check": { + "name": "billing_reports_invoice_pdf_sha256_hex_check", + "value": "\"billing_reports\".\"invoice_pdf_sha256\" IS NULL OR \"billing_reports\".\"invoice_pdf_sha256\" ~ '^[0-9a-f]{64}$'" + }, + "billing_reports_invoice_email_status_check": { + "name": "billing_reports_invoice_email_status_check", + "value": "\"billing_reports\".\"invoice_email_status\" in ('not_sent', 'sent', 'failed')" + }, + "billing_reports_final_pdf_check": { + "name": "billing_reports_final_pdf_check", + "value": "\"billing_reports\".\"status\" <> 'final' OR (\"billing_reports\".\"pdf\" IS NOT NULL AND \"billing_reports\".\"pdf_sha256\" IS NOT NULL)" + } + }, + "isRLSEnabled": false + }, + "public.calendar_events": { + "name": "calendar_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "event_date": { + "name": "event_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "immich_album_id": { + "name": "immich_album_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "category_id": { + "name": "category_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "calendar_events_category_id_event_categories_id_fk": { + "name": "calendar_events_category_id_event_categories_id_fk", + "tableFrom": "calendar_events", + "columnsFrom": [ + "category_id" + ], + "tableTo": "event_categories", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "calendar_events_created_by_user_id_user_id_fk": { + "name": "calendar_events_created_by_user_id_user_id_fk", + "tableFrom": "calendar_events", + "columnsFrom": [ + "created_by_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.event_categories": { + "name": "event_categories", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "event_categories_name_lower_unique": { + "name": "event_categories_name_lower_unique", + "columns": [ + { + "expression": "lower(\"name\")", + "isExpression": true, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "event_categories_created_by_user_id_user_id_fk": { + "name": "event_categories_created_by_user_id_user_id_fk", + "tableFrom": "event_categories", + "columnsFrom": [ + "created_by_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "event_categories_color_check": { + "name": "event_categories_color_check", + "value": "\"event_categories\".\"color\" in ('blue', 'green', 'orange', 'purple', 'teal', 'gold', 'red', 'neutral')" + } + }, + "isRLSEnabled": false + }, + "public.event_reservations": { + "name": "event_reservations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "event_id": { + "name": "event_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "editorial_account_id": { + "name": "editorial_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "granted_at": { + "name": "granted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "event_reservations_event_editorial_unique": { + "name": "event_reservations_event_editorial_unique", + "columns": [ + { + "expression": "event_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "editorial_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "event_reservations_event_id_calendar_events_id_fk": { + "name": "event_reservations_event_id_calendar_events_id_fk", + "tableFrom": "event_reservations", + "columnsFrom": [ + "event_id" + ], + "tableTo": "calendar_events", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "event_reservations_editorial_account_id_editorial_accounts_id_fk": { + "name": "event_reservations_editorial_account_id_editorial_accounts_id_fk", + "tableFrom": "event_reservations", + "columnsFrom": [ + "editorial_account_id" + ], + "tableTo": "editorial_accounts", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.billing_address_versions": { + "name": "billing_address_versions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "editorial_account_id": { + "name": "editorial_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "company_name": { + "name": "company_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "contact_name": { + "name": "contact_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "address_line_1": { + "name": "address_line_1", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "address_line_2": { + "name": "address_line_2", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "postal_code": { + "name": "postal_code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "city": { + "name": "city", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "country_code": { + "name": "country_code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "valid_from": { + "name": "valid_from", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "superseded_by_id": { + "name": "superseded_by_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "billing_address_versions_editorial_account_id_editorial_accounts_id_fk": { + "name": "billing_address_versions_editorial_account_id_editorial_accounts_id_fk", + "tableFrom": "billing_address_versions", + "columnsFrom": [ + "editorial_account_id" + ], + "tableTo": "editorial_accounts", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "billing_address_versions_superseded_by_id_billing_address_versions_id_fk": { + "name": "billing_address_versions_superseded_by_id_billing_address_versions_id_fk", + "tableFrom": "billing_address_versions", + "columnsFrom": [ + "superseded_by_id" + ], + "tableTo": "billing_address_versions", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "billing_address_versions_created_by_user_id_user_id_fk": { + "name": "billing_address_versions_created_by_user_id_user_id_fk", + "tableFrom": "billing_address_versions", + "columnsFrom": [ + "created_by_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.editorial_accounts": { + "name": "editorial_accounts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "contact_name": { + "name": "contact_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "login_email": { + "name": "login_email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "account_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'pending_email'" + }, + "current_price_cents": { + "name": "current_price_cents", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "flatrate_active": { + "name": "flatrate_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "flatrate_price_cents": { + "name": "flatrate_price_cents", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "flatrate_asset_limit": { + "name": "flatrate_asset_limit", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "collab_enabled": { + "name": "collab_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "approval_notice_status": { + "name": "approval_notice_status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'not_requested'" + }, + "current_billing_address_version_id": { + "name": "current_billing_address_version_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "email_verified_at": { + "name": "email_verified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "accepted_terms_version": { + "name": "accepted_terms_version", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "accepted_terms_at": { + "name": "accepted_terms_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "privacy_acknowledged_at": { + "name": "privacy_acknowledged_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "archived_by_user_id": { + "name": "archived_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "editorial_accounts_user_id_user_id_fk": { + "name": "editorial_accounts_user_id_user_id_fk", + "tableFrom": "editorial_accounts", + "columnsFrom": [ + "user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "editorial_accounts_current_billing_address_version_id_billing_address_versions_id_fk": { + "name": "editorial_accounts_current_billing_address_version_id_billing_address_versions_id_fk", + "tableFrom": "editorial_accounts", + "columnsFrom": [ + "current_billing_address_version_id" + ], + "tableTo": "billing_address_versions", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "editorial_accounts_archived_by_user_id_user_id_fk": { + "name": "editorial_accounts_archived_by_user_id_user_id_fk", + "tableFrom": "editorial_accounts", + "columnsFrom": [ + "archived_by_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "editorial_accounts_user_id_unique": { + "name": "editorial_accounts_user_id_unique", + "columns": [ + "user_id" + ], + "nullsNotDistinct": false + }, + "editorial_accounts_login_email_unique": { + "name": "editorial_accounts_login_email_unique", + "columns": [ + "login_email" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.lightbox_items": { + "name": "lightbox_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "editorial_account_id": { + "name": "editorial_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "asset_id": { + "name": "asset_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "added_at": { + "name": "added_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "lightbox_items_editorial_asset_idx": { + "name": "lightbox_items_editorial_asset_idx", + "columns": [ + { + "expression": "editorial_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "asset_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "lightbox_items_editorial_account_id_editorial_accounts_id_fk": { + "name": "lightbox_items_editorial_account_id_editorial_accounts_id_fk", + "tableFrom": "lightbox_items", + "columnsFrom": [ + "editorial_account_id" + ], + "tableTo": "editorial_accounts", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rate_limits": { + "name": "rate_limits", + "schema": "", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "window_boundary": { + "name": "window_boundary", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "count": { + "name": "count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "rate_limits_key_window_boundary_pk": { + "name": "rate_limits_key_window_boundary_pk", + "columns": [ + "key", + "window_boundary" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.release_notes": { + "name": "release_notes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "version": { + "name": "version", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "audience": { + "name": "audience", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'both'" + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "release_notes_version_audience_unique": { + "name": "release_notes_version_audience_unique", + "columns": [ + { + "expression": "version", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "audience", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "release_notes_created_by_user_id_user_id_fk": { + "name": "release_notes_created_by_user_id_user_id_fk", + "tableFrom": "release_notes", + "columnsFrom": [ + "created_by_user_id" + ], + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "release_notes_audience_check": { + "name": "release_notes_audience_check", + "value": "\"release_notes\".\"audience\" in ('admin', 'editorial', 'both')" + }, + "release_notes_version_check": { + "name": "release_notes_version_check", + "value": "\"release_notes\".\"version\" ~ '^[0-9]+\\.[0-9]+(\\.[0-9]+)?$'" + } + }, + "isRLSEnabled": false + }, + "public.download_events": { + "name": "download_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "editorial_account_id": { + "name": "editorial_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "usage_id": { + "name": "usage_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "immich_asset_id": { + "name": "immich_asset_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "authorized_at": { + "name": "authorized_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "download_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'authorized'" + }, + "transferred_bytes": { + "name": "transferred_bytes", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "repeat_download_note": { + "name": "repeat_download_note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "request_id": { + "name": "request_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "idempotency_key": { + "name": "idempotency_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "intent_kind": { + "name": "intent_kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'new_usage'" + }, + "request_fingerprint": { + "name": "request_fingerprint", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "legacy_intent": { + "name": "legacy_intent", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": { + "download_events_editorial_authorized_id_idx": { + "name": "download_events_editorial_authorized_id_idx", + "columns": [ + { + "expression": "editorial_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "authorized_at", + "isExpression": false, + "asc": false, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "download_events_editorial_idempotency_key_unique": { + "name": "download_events_editorial_idempotency_key_unique", + "columns": [ + { + "expression": "editorial_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "idempotency_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "download_events_editorial_account_id_editorial_accounts_id_fk": { + "name": "download_events_editorial_account_id_editorial_accounts_id_fk", + "tableFrom": "download_events", + "columnsFrom": [ + "editorial_account_id" + ], + "tableTo": "editorial_accounts", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "download_events_usage_id_usages_id_fk": { + "name": "download_events_usage_id_usages_id_fk", + "tableFrom": "download_events", + "columnsFrom": [ + "usage_id" + ], + "tableTo": "usages", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "download_events_intent_kind_check": { + "name": "download_events_intent_kind_check", + "value": "\"download_events\".\"intent_kind\" in ('new_usage', 'repeat_download', 'legacy')" + }, + "download_events_request_fingerprint_hex_check": { + "name": "download_events_request_fingerprint_hex_check", + "value": "\"download_events\".\"request_fingerprint\" ~ '^[0-9a-f]{64}$'" + }, + "download_events_canonical_idempotency_key_check": { + "name": "download_events_canonical_idempotency_key_check", + "value": "\"download_events\".\"legacy_intent\" OR \"download_events\".\"idempotency_key\" ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'" + }, + "download_events_canonical_immich_asset_id_check": { + "name": "download_events_canonical_immich_asset_id_check", + "value": "\"download_events\".\"immich_asset_id\" ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'" + } + }, + "isRLSEnabled": false + }, + "public.usages": { + "name": "usages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "editorial_account_id": { + "name": "editorial_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "immich_asset_id": { + "name": "immich_asset_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "filename_snapshot": { + "name": "filename_snapshot", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "immich_album_id_snapshot": { + "name": "immich_album_id_snapshot", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "album_name_snapshot": { + "name": "album_name_snapshot", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "purpose": { + "name": "purpose", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "internal_reference": { + "name": "internal_reference", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "price_cents": { + "name": "price_cents", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "collab": { + "name": "collab", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "billing_status": { + "name": "billing_status", + "type": "usage_billing_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'open'" + }, + "billing_report_id": { + "name": "billing_report_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "usages_editorial_created_id_idx": { + "name": "usages_editorial_created_id_idx", + "columns": [ + { + "expression": "editorial_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": false, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "usages_created_at_idx": { + "name": "usages_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "usages_editorial_account_id_editorial_accounts_id_fk": { + "name": "usages_editorial_account_id_editorial_accounts_id_fk", + "tableFrom": "usages", + "columnsFrom": [ + "editorial_account_id" + ], + "tableTo": "editorial_accounts", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "usages_billing_report_id_billing_reports_id_fk": { + "name": "usages_billing_report_id_billing_reports_id_fk", + "tableFrom": "usages", + "columnsFrom": [ + "billing_report_id" + ], + "tableTo": "billing_reports", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "usages_canonical_immich_asset_id_check": { + "name": "usages_canonical_immich_asset_id_check", + "value": "\"usages\".\"immich_asset_id\" ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'" + }, + "usages_canonical_immich_album_id_check": { + "name": "usages_canonical_immich_album_id_check", + "value": "\"usages\".\"immich_album_id_snapshot\" ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'" + } + }, + "isRLSEnabled": false + } + }, + "enums": { + "public.portal_role": { + "name": "portal_role", + "schema": "public", + "values": [ + "ADMIN", + "EDITORIAL" + ] + }, + "public.report_status": { + "name": "report_status", + "schema": "public", + "values": [ + "draft", + "final", + "cancelled" + ] + }, + "public.account_status": { + "name": "account_status", + "schema": "public", + "values": [ + "pending_email", + "pending_approval", + "active", + "suspended", + "rejected" + ] + }, + "public.download_status": { + "name": "download_status", + "schema": "public", + "values": [ + "authorized", + "streaming", + "completed", + "failed_before_delivery", + "interrupted" + ] + }, + "public.usage_billing_status": { + "name": "usage_billing_status", + "schema": "public", + "values": [ + "open", + "billed", + "reopened", + "voided" + ] + } + }, + "schemas": {}, + "views": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 90ca691..522779d 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -71,6 +71,13 @@ "when": 1796079496182, "tag": "0009_release_notes_2_4_0", "breakpoints": true + }, + { + "idx": 10, + "version": "7", + "when": 1796081618450, + "tag": "0010_release_notes_2_4_1", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/app/admin/kalender/AlbumImport.tsx b/src/app/admin/kalender/AlbumImport.tsx new file mode 100644 index 0000000..aa126be --- /dev/null +++ b/src/app/admin/kalender/AlbumImport.tsx @@ -0,0 +1,121 @@ +"use client"; + +import { useMemo, useState, useTransition } from "react"; +import { Badge, Button, Checkbox } from "@sakaniui/react"; +import { IconDownload } from "@sakaniui/react/icons"; + +import { notifyResult } from "@/components/ui/feedback"; +import { Card, FormSelect } from "@/components/ui/sakani"; +import type { ImportableAlbum } from "@/modules/calendar/service"; + +import type { CalendarActionResult } from "./actions"; + +const dateFormat = new Intl.DateTimeFormat("de-DE", { dateStyle: "medium", timeZone: "UTC" }); + +/** + * Older Immich albums ("Titel | TT.MM.JJJJ") without an event: preview with + * everything preselected, untick what should stay out, pick a category. + */ +export function AlbumImport({ + albums, + categories, + action, +}: Readonly<{ + albums: ImportableAlbum[]; + categories: Array<{ id: string; name: string }>; + action: (state: CalendarActionResult, formData: FormData) => Promise; +}>) { + const [open, setOpen] = useState(false); + const [excluded, setExcluded] = useState>(new Set()); + const [pending, startTransition] = useTransition(); + const selected = useMemo(() => albums.filter((album) => !excluded.has(album.albumId)), [albums, excluded]); + + const toggle = (albumId: string, checked: boolean) => + setExcluded((previous) => { + const next = new Set(previous); + if (checked) next.delete(albumId); + else next.add(albumId); + return next; + }); + + const submit = (formData: FormData) => { + for (const album of selected) formData.append("albumId", album.albumId); + startTransition(async () => { + const result = await action({ ok: true, message: "" }, formData); + notifyResult(result); + if (result.ok) { + setOpen(false); + setExcluded(new Set()); + } + }); + }; + + return ( + + {albums.length > 0 && !open ? ( +
+ +
+ ) : null} + + {open ? ( +
+
+ + + {selected.length} ausgewählt +
+
    + {albums.map((album) => ( +
  • + toggle(album.albumId, event.target.checked)} + /> +
  • + ))} +
+
+ ({ label: category.name, value: category.id })), + ]} + /> +
+
+ + +
+
+ ) : null} +
+ ); +} diff --git a/src/app/admin/kalender/actions.ts b/src/app/admin/kalender/actions.ts index 54fce83..e2119c4 100644 --- a/src/app/admin/kalender/actions.ts +++ b/src/app/admin/kalender/actions.ts @@ -46,6 +46,28 @@ export async function createCalendarEventAction( }; } +/** Imports selected older Immich albums as calendar events. */ +export async function importAlbumsAction( + _prevState: CalendarActionResult, + formData: FormData, +): Promise { + const principal = await requireAdmin(new Headers(await headers())); + const albumIds = formData.getAll("albumId").filter((value): value is string => typeof value === "string"); + const categoryId = formData.get("categoryId"); + try { + const { imported } = await calendarService.importAlbums({ + albumIds, + categoryId: typeof categoryId === "string" && categoryId ? categoryId : null, + adminUserId: principal.userId, + }); + revalidatePath("/admin/kalender"); + revalidatePath("/redaktion/kalender"); + return { ok: true, message: imported === 1 ? "1 Termin übernommen." : `${imported} Termine übernommen.` }; + } catch (error) { + return { ok: false, message: calendarErrorMessage(error) }; + } +} + export async function deleteCalendarEventAction( _prevState: CalendarActionResult, formData: FormData, @@ -75,6 +97,7 @@ function calendarErrorMessage(error: unknown): string { INVALID_EVENT_DATE: "Bitte wählen Sie ein gültiges Datum.", INVALID_ALBUM: "Das gewählte Album existiert nicht mehr in Immich.", INVALID_CATEGORY: "Die gewählte Kategorie existiert nicht mehr.", + NOTHING_TO_IMPORT: "Bitte mindestens ein Album auswählen, das noch keinen Termin hat.", EVENT_NOT_FOUND: "Dieser Termin existiert nicht mehr.", RESERVATION_NOT_FOUND: "Diese Vormerkung existiert nicht mehr.", IMMICH_UNAVAILABLE: "Immich ist gerade nicht erreichbar. Bitte später erneut versuchen.", diff --git a/src/app/admin/kalender/page.tsx b/src/app/admin/kalender/page.tsx index c760b30..a9a4bdf 100644 --- a/src/app/admin/kalender/page.tsx +++ b/src/app/admin/kalender/page.tsx @@ -13,14 +13,16 @@ import { immichClient } from "@/modules/immich/client"; import { requireAdminPage } from "../access"; import { CalendarEventForm } from "./CalendarEventForm"; import { DeleteCalendarEventButton } from "./DeleteCalendarEventButton"; -import { createCalendarEventAction, deleteCalendarEventAction } from "./actions"; +import { AlbumImport } from "./AlbumImport"; +import { createCalendarEventAction, deleteCalendarEventAction, importAlbumsAction } from "./actions"; export default async function AdminCalendarPage() { await requireAdminPage(); - const [{ events, immichUnavailable }, albums, categories] = await Promise.all([ + const [{ events, immichUnavailable }, albums, categories, importable] = await Promise.all([ calendarService.listAdminEvents(), immichClient.listAlbums().catch(() => []), categoryService.listCategories(), + calendarService.listImportableAlbums(), ]); const today = isoDateInBerlin(new Date()); @@ -43,6 +45,14 @@ export default async function AdminCalendarPage() { defaultEventDate={today} /> + {importable.immichUnavailable ? null : ( + ({ id: category.id, name: category.name }))} + /> + )} + {immichUnavailable ? ( - {[ - { id: "upcoming", title: "Kommende Termine", list: upcoming }, - { id: "past", title: "Vergangene Termine", list: past }, - ] - .filter((group) => group.list.length > 0) - .map((group) => ( -
-

- {group.title} -

-
    - {group.list.map((event) => ( -
  • -
    -

    - {event.title} - {event.eventDate < today ? vorbei : null} -

    -

    - {formatIsoDateGerman(event.eventDate)} - {event.category ? ( - - · {event.category.name} - - ) : null} - {event.album ? null : · Album noch nicht angelegt} -

    -
    - -
  • - ))} -
-
- ))} + {upcoming.length > 0 ? ( +
+

+ Kommende Termine +

+ +
+ ) : null} + {past.length > 0 ? ( + // Imported older albums can make this long; the month view shows + // them too, and a click there opens this section (event-month.tsx). +
+ + + Vergangene Termine ({past.length}) + +
+ +
+
+ ) : null} )} ); } + +function EventList({ events, today }: Readonly<{ events: EditorialCalendarEvent[]; today: string }>) { + return ( +
    + {events.map((event) => ( +
  • +
    +

    + {event.title} + {event.eventDate < today ? vorbei : null} +

    +

    + {formatIsoDateGerman(event.eventDate)} + {event.category ? ( + + · {event.category.name} + + ) : null} + {event.album ? null : · Album noch nicht angelegt} +

    +
    + +
  • + ))} +
+ ); +} + diff --git a/src/components/calendar/event-month.tsx b/src/components/calendar/event-month.tsx index 700ff24..c4c4f47 100644 --- a/src/components/calendar/event-month.tsx +++ b/src/components/calendar/event-month.tsx @@ -50,6 +50,8 @@ export function EventMonth({ events }: Readonly<{ events: MonthEvent[] }>) { onDateChange={setMonth} onEventClick={(event) => { const target = document.getElementById(`termin-${event.id}`); + const section = target?.closest("details"); + if (section) section.open = true; target?.scrollIntoView({ behavior: "smooth", block: "center" }); target?.focus({ preventScroll: true }); }} diff --git a/src/components/layout/release-notes.tsx b/src/components/layout/release-notes.tsx index 4183e71..1452ab2 100644 --- a/src/components/layout/release-notes.tsx +++ b/src/components/layout/release-notes.tsx @@ -9,16 +9,18 @@ import { IconCheck } from "@sakaniui/react/icons"; // then sees the popup once more. ponytail: only the latest release is kept; // add a history list when users ask for older notes. export const RELEASE = { - version: "2.4", + version: "2.4.1", title: "Mehrfach-Download und neuer Feinschliff", notes: { redaktion: [ "ZIP-Download vom Merkzettel: Alle Bilder laufen als neue Nutzung. Nur bei Bildern, die Sie schon geladen haben, wählen Sie zwischen neuer Nutzung und kostenloser Wiederholung.", "Albenübersicht mit großen Vorschaubildern, Seitenzahlen unter den Fotos und Ladeanimationen.", "Bestätigungen und Hinweise erscheinen als kurze Meldung unten rechts.", + "Im Kalender stehen jetzt auch ältere Spiele; Sie können sie wie neue zu Ihren Alben hinzufügen.", "Seit 2.3: Kalender als Monatsansicht mit „Zu meinen Alben hinzufügen“.", ], admin: [ + "Ältere Alben übernehmen: Im Kalender zeigt „Alben aus Immich anzeigen“ alle Alben im Format „Titel | TT.MM.JJJJ“ ohne Termin; auswählen, Kategorie setzen, übernehmen.", "Speichern und Ändern bestätigt das Portal mit einer kurzen Meldung; Fehler bei Abrechnungen sind verständlich formuliert.", "Redaktionen als Tabelle mit Suche, Statusfilter und offenen Beträgen.", "Audit-Protokoll mit Ereignisauswahl, lesbaren Bezeichnungen und aufklappbaren Details.", diff --git a/src/modules/calendar/event-albums.test.ts b/src/modules/calendar/event-albums.test.ts index de7e36f..57c6cbb 100644 --- a/src/modules/calendar/event-albums.test.ts +++ b/src/modules/calendar/event-albums.test.ts @@ -1,6 +1,6 @@ import { expect, test } from "vitest"; -import { expectedAlbumNames, germanEventDate, matchEventAlbum } from "./event-albums"; +import { expectedAlbumNames, germanEventDate, matchEventAlbum, parseAlbumEventName } from "./event-albums"; const matchAlbum = { id: "2222222b-2222-4222-8222-22222222222b", albumName: "Hamburger SV - VfL Wolfsburg | 12.09.2026" }; const eventAlbum = { id: "3333333c-3333-4333-8333-33333333333c", albumName: "DFB-Pokal Finale" }; @@ -55,3 +55,15 @@ test("matchEventAlbum falls back to name matching when the explicit album is gon }; expect(matchEventAlbum(event, [matchAlbum])).toEqual(matchAlbum); }); + +test("parseAlbumEventName reads title and date from the album name", () => { + expect(parseAlbumEventName("Hamburger SV - VfL Wolfsburg | 12.12.2026")).toEqual({ + title: "Hamburger SV - VfL Wolfsburg", + eventDate: "2026-12-12", + }); + expect(parseAlbumEventName(" Finale|01.02.2024 ")).toEqual({ title: "Finale", eventDate: "2024-02-01" }); + expect(parseAlbumEventName("Privaturlaub Sylt")).toBeNull(); + expect(parseAlbumEventName("Kaputt | 31.02.2026")).toBeNull(); + expect(parseAlbumEventName(" | 12.12.2026")).toBeNull(); +}); + diff --git a/src/modules/calendar/event-albums.ts b/src/modules/calendar/event-albums.ts index 5d0dc88..126280b 100644 --- a/src/modules/calendar/event-albums.ts +++ b/src/modules/calendar/event-albums.ts @@ -44,3 +44,21 @@ export function matchEventAlbum( const names = new Set(expectedAlbumNames(event.title, event.eventDate)); return albums.find((album) => names.has(album.albumName.trim())) ?? null; } + +/** + * Reads "{Titel} | {TT.MM.JJJJ}" back into an event (album import). Albums + * without a valid date suffix (e.g. private ones) return null and are never + * offered for import. + */ +export function parseAlbumEventName(albumName: string): { title: string; eventDate: string } | null { + const match = /^(.+?)\s*\|\s*(\d{2})\.(\d{2})\.(\d{4})\s*$/.exec(albumName.trim()); + if (!match) return null; + const [, rawTitle, day, month, year] = match; + const date = new Date(Date.UTC(Number(year), Number(month) - 1, Number(day))); + if (date.getUTCFullYear() !== Number(year) || date.getUTCMonth() !== Number(month) - 1 || date.getUTCDate() !== Number(day)) { + return null; + } + const title = rawTitle.trim(); + return title ? { title, eventDate: `${year}-${month}-${day}` } : null; +} + diff --git a/src/modules/calendar/service.test.ts b/src/modules/calendar/service.test.ts index f8a5a48..4e271ba 100644 --- a/src/modules/calendar/service.test.ts +++ b/src/modules/calendar/service.test.ts @@ -63,6 +63,19 @@ function setup(options: { events.push(created); return created; }, + async insertEvents(rows) { + for (const [index, row] of rows.entries()) { + events.push( + event({ + id: `9999999${index}-9999-4999-8999-999999999999`, + title: row.title, + eventDate: row.eventDate, + immichAlbumId: row.immichAlbumId, + }), + ); + } + return rows.length; + }, async getEvent(id) { return events.find((candidate) => candidate.id === id) ?? null; }, @@ -271,7 +284,7 @@ test("matchesAutoRule matches keywords inside title or album name, ignoring case expect(matchesAutoRule([" "], ["anything"])).toBe(false); }); -test("listEditorialEvents derives access per event and keeps the past window", async () => { +test("listEditorialEvents derives access per event and keeps past events", async () => { const oldEvent = event({ id: "7777777a-7777-4777-8777-77777777777a", eventDate: "2026-01-01" }); const futureEvent = event({ id: "8888888b-8888-4888-8888-88888888888b", title: "Volleyball Finale", eventDate: "2026-09-20" }); const { service } = setup({ @@ -279,25 +292,20 @@ test("listEditorialEvents derives access per event and keeps the past window", a grantSources: [{ immichAlbumId: albumUuid, source: "auto_rule" }], reservations: [{ eventId: futureEvent.id, editorialId: editorialUuid, grantedAt: null }], }); - const { events, immichUnavailable } = await service.listEditorialEvents( - editorialUuid, - new Date("2026-09-10T08:00:00.000Z"), - ); + const { events, immichUnavailable } = await service.listEditorialEvents(editorialUuid); expect(immichUnavailable).toBe(false); - // The January event is outside the 30-day past window. + // Older events stay listed (imported albums remain reservable). expect(events.map((row) => [row.id, row.access])).toEqual([ + [oldEvent.id, "available"], [eventUuid, "auto_granted"], [futureEvent.id, "reserved"], ]); - expect(events[0].album).toEqual({ id: albumUuid, albumName: matchAlbum.albumName }); + expect(events.find((row) => row.id === eventUuid)!.album).toEqual({ id: albumUuid, albumName: matchAlbum.albumName }); }); test("listEditorialEvents degrades gracefully when Immich is down", async () => { const { service } = setup({ albums: null, keywords: ["Wolfsburg"] }); - const { events, immichUnavailable } = await service.listEditorialEvents( - editorialUuid, - new Date("2026-09-10T08:00:00.000Z"), - ); + const { events, immichUnavailable } = await service.listEditorialEvents(editorialUuid); expect(immichUnavailable).toBe(true); expect(events[0].album).toBeNull(); // The keyword still matches the title, so the auto rule will deliver the album. @@ -309,3 +317,51 @@ test("listAdminEvents attaches reservations per event", async () => { const { events } = await service.listAdminEvents(); expect(events[0].reservations).toEqual([{ editorialId: editorialUuid, editorialName: "Kicker Daily", grantedAt: null }]); }); + +const olderAlbum: ImmichAlbumSummary = { + id: "aaaaaaa1-aaaa-4aaa-8aaa-aaaaaaaaaaa1", + albumName: "VfB Lübeck - Holstein Kiel | 03.05.2025", + description: null, + albumThumbnailAssetId: null, + assetCount: 12, +}; +const privateAlbum: ImmichAlbumSummary = { ...olderAlbum, id: "bbbbbbb2-bbbb-4bbb-8bbb-bbbbbbbbbbb2", albumName: "Privaturlaub Sylt" }; + +test("listImportableAlbums offers dated albums without an event, newest first", async () => { + const newer = { ...olderAlbum, id: "ccccccc3-cccc-4ccc-8ccc-ccccccccccc3", albumName: "Pokalfinale | 20.05.2026" }; + const { service } = setup({ albums: [matchAlbum, olderAlbum, privateAlbum, newer] }); + const { albums } = await service.listImportableAlbums(); + // matchAlbum already belongs to the default event; the private album has no date. + expect(albums.map((album) => [album.title, album.eventDate])).toEqual([ + ["Pokalfinale", "2026-05-20"], + ["VfB Lübeck - Holstein Kiel", "2025-05-03"], + ]); +}); + +test("importAlbums creates linked events only for importable albums and audits", async () => { + const { service, events, audit } = setup({ albums: [matchAlbum, olderAlbum, privateAlbum] }); + const result = await service.importAlbums({ + albumIds: [olderAlbum.id, privateAlbum.id, matchAlbum.id], + categoryId: null, + adminUserId: userUuid, + }); + expect(result).toEqual({ imported: 1 }); + expect(events.at(-1)).toMatchObject({ title: "VfB Lübeck - Holstein Kiel", eventDate: "2025-05-03", immichAlbumId: olderAlbum.id }); + expect(audit.writeAudit).toHaveBeenCalledWith(expect.objectContaining({ type: "calendar_events_imported" })); + // A second run finds nothing left to import. + await expect( + service.importAlbums({ albumIds: [olderAlbum.id], categoryId: null, adminUserId: userUuid }), + ).rejects.toMatchObject({ code: "NOTHING_TO_IMPORT" }); +}); + +test("importAlbums rejects bad categories and an unreachable Immich", async () => { + const { service } = setup({ albums: [olderAlbum] }); + await expect( + service.importAlbums({ albumIds: [olderAlbum.id], categoryId: "nope", adminUserId: userUuid }), + ).rejects.toMatchObject({ code: "INVALID_CATEGORY" }); + const down = setup({ albums: null }); + await expect( + down.service.importAlbums({ albumIds: [olderAlbum.id], categoryId: null, adminUserId: userUuid }), + ).rejects.toMatchObject({ code: "IMMICH_UNAVAILABLE" }); +}); + diff --git a/src/modules/calendar/service.ts b/src/modules/calendar/service.ts index 2c0debf..08fd9fa 100644 --- a/src/modules/calendar/service.ts +++ b/src/modules/calendar/service.ts @@ -14,11 +14,7 @@ import { } from "@/db/schema"; import type * as schema from "@/db/schema"; import { albumGrantService, AlbumGrantError } from "@/modules/albums/grants"; -import { - isoDateInBerlin, - isValidIsoDate, - shiftIsoDate, -} from "@/modules/announcements/service"; +import { isValidIsoDate } from "@/modules/announcements/service"; import { writeAudit } from "@/modules/audit/write"; import { immichClient } from "@/modules/immich/client"; import type { ImmichClient } from "@/modules/immich/types"; @@ -31,11 +27,11 @@ import { import type { EventCategory } from "./categories"; import type { CategoryColor } from "./colors"; -import { matchEventAlbum } from "./event-albums"; +import { matchEventAlbum, parseAlbumEventName } from "./event-albums"; export const CALENDAR_EVENT_MAX_TITLE_LENGTH = 200; -/** Past events stay visible (and reservable) for this many days. */ -export const CALENDAR_PAST_DAYS = 30; +/** Upper bound for one album import, so one click cannot create thousands of rows. */ +export const CALENDAR_IMPORT_MAX = 500; export type CalendarEvent = { id: string; @@ -60,6 +56,9 @@ export type EditorialCalendarEvent = CalendarEvent & { access: EventAccessState; }; +/** An Immich album named "{Titel} | {TT.MM.JJJJ}" that has no calendar event yet. */ +export type ImportableAlbum = { albumId: string; albumName: string; title: string; eventDate: string; assetCount: number }; + export type AdminCalendarEvent = CalendarEvent & { album: LinkedAlbum | null; reservations: Array<{ editorialId: string; editorialName: string; grantedAt: Date | null }>; @@ -70,6 +69,7 @@ export type CalendarError = | "INVALID_EVENT_DATE" | "INVALID_ALBUM" | "INVALID_CATEGORY" + | "NOTHING_TO_IMPORT" | "EVENT_NOT_FOUND" | "RESERVATION_NOT_FOUND" | "IMMICH_UNAVAILABLE" @@ -115,6 +115,9 @@ export type CalendarRepository = { categoryId: string | null; adminUserId: string; }): Promise; + insertEvents( + rows: Array<{ title: string; eventDate: string; immichAlbumId: string; categoryId: string | null; adminUserId: string }>, + ): Promise; getEvent(id: string): Promise; listEvents(): Promise; deleteEvent(id: string): Promise; @@ -180,6 +183,28 @@ export function createCalendarService({ } } + /** + * Albums named "{Titel} | {TT.MM.JJJJ}" without a calendar event yet, + * newest first. Albums without a date suffix never appear here. + */ + async function listImportableAlbums(): Promise<{ albums: ImportableAlbum[]; immichUnavailable: boolean }> { + const [albums, events] = await Promise.all([loadAlbumsOrNull(), repository.listEvents()]); + if (!albums) return { albums: [], immichUnavailable: true }; + const linked = new Set( + events + .map((event) => matchEventAlbum(event, albums)?.id.toLowerCase()) + .filter((id): id is string => Boolean(id)), + ); + const importable = albums.flatMap((album) => { + if (linked.has(album.id.toLowerCase())) return []; + const parsed = parseAlbumEventName(album.albumName); + if (!parsed || parsed.title.length > CALENDAR_EVENT_MAX_TITLE_LENGTH) return []; + return [{ albumId: album.id, albumName: album.albumName, assetCount: album.assetCount, ...parsed }]; + }); + importable.sort((a, b) => b.eventDate.localeCompare(a.eventDate) || a.title.localeCompare(b.title)); + return { albums: importable, immichUnavailable: false }; + } + return { async createEvent(input: { title: string; @@ -278,13 +303,13 @@ export function createCalendarService({ }); }, - /** Editorial calendar: upcoming events plus the recent past window. */ + /** + * Editorial calendar: every event, past ones included (imported older + * albums stay reservable). + */ async listEditorialEvents( editorialId: string, - now: Date, ): Promise<{ events: EditorialCalendarEvent[]; immichUnavailable: boolean }> { - const today = isoDateInBerlin(now); - const minDate = shiftIsoDate(today, -CALENDAR_PAST_DAYS); const [allEvents, albums, grantSources, reservations, keywords] = await Promise.all([ repository.listEvents(), loadAlbumsOrNull(), @@ -295,9 +320,7 @@ export function createCalendarService({ const sourceByAlbum = new Map(grantSources.map((grant) => [grant.immichAlbumId.toLowerCase(), grant.source])); const pending = new Set(reservations.filter((row) => row.grantedAt === null).map((row) => row.eventId)); - const events = allEvents - .filter((event) => event.eventDate >= minDate) - .map((event) => { + const events = allEvents.map((event) => { const album = albums ? matchEventAlbum(event, albums) : null; return { ...event, @@ -312,6 +335,53 @@ export function createCalendarService({ return { events, immichUnavailable: albums === null }; }, + /** + * Creates one event per selected album, linked explicitly to it. The + * candidate list is recomputed here, so only importable albums count. + */ + listImportableAlbums, + + async importAlbums(input: { + albumIds: string[]; + categoryId: string | null; + adminUserId: string; + }): Promise<{ imported: number }> { + if (input.categoryId && !UUID_PATTERN.test(input.categoryId)) { + throw new CalendarServiceError("INVALID_CATEGORY"); + } + const { albums, immichUnavailable } = await listImportableAlbums(); + if (immichUnavailable) throw new CalendarServiceError("IMMICH_UNAVAILABLE"); + const wanted = new Set(input.albumIds.map((id) => id.toLowerCase())); + const selected = albums.filter((album) => wanted.has(album.albumId.toLowerCase())).slice(0, CALENDAR_IMPORT_MAX); + if (selected.length === 0) throw new CalendarServiceError("NOTHING_TO_IMPORT"); + + let imported: number; + try { + imported = await repository.insertEvents( + selected.map((album) => ({ + title: album.title, + eventDate: album.eventDate, + immichAlbumId: album.albumId, + categoryId: input.categoryId, + adminUserId: input.adminUserId, + })), + ); + } catch (error) { + if (postgresCode(error) === "23503") throw new CalendarServiceError("INVALID_CATEGORY"); + throw error; + } + + await audit.writeAudit({ + type: "calendar_events_imported", + actorUserId: input.adminUserId, + actorType: "admin", + entityType: "calendar_event", + entityId: "import", + metadata: { count: imported, categoryId: input.categoryId, albumIds: selected.map((album) => album.albumId) }, + }); + return { imported }; + }, + /** Admin overview: every event with its linked album and all reservations. */ async listAdminEvents(): Promise<{ events: AdminCalendarEvent[]; immichUnavailable: boolean }> { const [allEvents, albums, reservations] = await Promise.all([ @@ -493,6 +563,24 @@ export function createCalendarRepository(database: NodePgDatabase return toEvent(created); }, + async insertEvents(rows) { + return database.transaction(async (transaction) => { + const inserted = await transaction + .insert(calendarEvents) + .values( + rows.map((row) => ({ + title: row.title, + eventDate: row.eventDate, + immichAlbumId: row.immichAlbumId, + categoryId: row.categoryId, + createdByUserId: row.adminUserId, + })), + ) + .returning({ id: calendarEvents.id }); + return inserted.length; + }); + }, + async getEvent(id) { const [row] = await selectEvents().where(eq(calendarEvents.id, id)).limit(1); return row ? toEvent(row) : null;