Files
co-lite/openspec/changes/add-event-tickets/sql/01-ticket-attendees.sql
T

16 lines
1.1 KiB
SQL

-- Co-Lite change add-event-tickets: attendee naming and consent on tickets, and the keys self check-in matches on.
-- Target: `service-counter`. Additive only. Run before the new services-counter starts. Needs a user that may alter tables.
USE `service-counter`;
ALTER TABLE `ticket`
ADD COLUMN `attendee_named_at` datetime NULL COMMENT 'when the buyer last named the attendee',
ADD COLUMN `attendee_consent_at` datetime NULL COMMENT 'when the attendee agreed to be kept updated',
ADD COLUMN `attendee_notice_id` bigint NULL COMMENT 'privacy notice version they agreed to',
ADD KEY `idx_ticket_event_mobile` (`event_uuid`, `attendee_mobile_e164`),
ADD KEY `idx_ticket_event_email` (`event_uuid`, `attendee_email`);
-- Tickets of orders paid before this release get their code now (22 URL-safe characters, like the new ones).
UPDATE `ticket` t JOIN `shop_order` o ON o.id = t.order_id
SET t.code = LEFT(REPLACE(REPLACE(REPLACE(TO_BASE64(RANDOM_BYTES(16)), '+', '-'), '/', '_'), '=', ''), 22)
WHERE o.status = 'PAID' AND t.status = 'ACTIVE' AND t.code IS NULL;