-- Nachklang e.V. Calendar module — step 5 preparation, brought forward. -- Apply manually against the CALENDAR_DB database, after 001: -- mysql -h -u -p < 002_snapshot_legacy_creator_names.sql -- -- Snapshots the creator's and last editor's *name* onto the event itself. -- -- Why: the creator is only ever rendered as a name (nothing authorises on it), -- and today that name comes from joining the calendar's own `users` table. -- Step 5 drops that table, which would silently erase the authorship of every -- event created before the cutover. There is no account backfill to save them -- either - that was dropped deliberately, see docs/calendar-auth-migration.md. -- One text column per reference keeps the history at no ongoing cost. -- -- These columns are an archive, not a source of truth. Nothing writes them -- after this backfill: events created from the cutover onwards carry an admin -- user id, whose name is resolved live so that renaming an account updates -- everywhere. The read path prefers the live admin name, falls back to this -- snapshot, and falls back again to the join until step 5 removes it. -- -- The backfill is written to be idempotent (`WHERE ... IS NULL`) so it can be -- re-run. Step 4's migration does exactly that, to catch anything created -- between this migration and the cutover. -- -- No charset clause: unlike 001's id columns these hold display text that is -- only ever compared against other calendar data, so they inherit the tables' -- utf8mb4_general_ci like the columns they are copied from. ALTER TABLE `events` ADD COLUMN `created_by_name` VARCHAR(255) NULL DEFAULT NULL AFTER `created_by_user_id`; ALTER TABLE `event_versions` ADD COLUMN `version_created_by_name` VARCHAR(255) NULL DEFAULT NULL AFTER `version_created_by_user_id`; UPDATE `events` e JOIN `users` u ON u.user_id = e.created_by_id SET e.created_by_name = u.full_name WHERE e.created_by_name IS NULL; UPDATE `event_versions` v JOIN `users` u ON u.user_id = v.version_created_by_id SET v.version_created_by_name = u.full_name WHERE v.version_created_by_name IS NULL;