13a0c07d1b
Jenkins Production Deployment
Reviewed-on: #14 Co-authored-by: Patrick Müller <mail@pmueller.me> Co-committed-by: Patrick Müller <mail@pmueller.me>
33 lines
1.6 KiB
SQL
33 lines
1.6 KiB
SQL
-- Nachklang e.V. Calendar module — step 4 of docs/calendar-auth-migration.md,
|
|
-- the cutover. Apply manually against the CALENDAR_DB database, after 002,
|
|
-- and BEFORE deploying the API build that goes with it:
|
|
-- mysql -h <DB_HOST> -u <DB_USER> -p <CALENDAR_DB> < 003_allow_null_legacy_creator.sql
|
|
--
|
|
-- From the cutover on, an event's creator is an admin-module user id. There is
|
|
-- no legacy calendar user id to write any more, and `events.created_by_id` is
|
|
-- NOT NULL - so without this the very first event created after the deploy
|
|
-- fails to insert. `event_versions.version_created_by_id` is already nullable.
|
|
--
|
|
-- The foreign key to `users` is kept: it permits NULL, so it costs nothing
|
|
-- until step 5 drops the column and the table together.
|
|
--
|
|
-- Applying this early is harmless. Widening a column to accept NULL cannot
|
|
-- break the running pre-cutover build, which always supplies a value, so this
|
|
-- can go out ahead of the deploy rather than during it.
|
|
|
|
ALTER TABLE `events`
|
|
MODIFY COLUMN `created_by_id` INT(11) NULL DEFAULT NULL;
|
|
|
|
-- Re-run of 002's backfill, to catch anything created between the two
|
|
-- migrations while the legacy path was still writing events. Idempotent by
|
|
-- construction: it only touches rows that have no snapshot yet.
|
|
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;
|