DROP INDEX IF EXISTS queue_tickets_personal_purge_idx;

ALTER TABLE queue_tickets
    DROP CONSTRAINT IF EXISTS queue_tickets_phone_pair_check,
    ADD CONSTRAINT queue_tickets_phone_nonce_check CHECK (octet_length(phone_nonce) = 12),
    ADD CONSTRAINT queue_tickets_phone_hmac_check CHECK (phone_hmac ~ '^[0-9a-f]{64}$');

ALTER TABLE queue_tickets
    ALTER COLUMN phone_ciphertext SET NOT NULL,
    ALTER COLUMN phone_nonce SET NOT NULL,
    ALTER COLUMN phone_hmac SET NOT NULL,
    DROP COLUMN IF EXISTS personal_data_purged_at;
