-- migrate:up -- The Linka Go accounts allowed to unlock the bikes for this reservation. They -- are plain addresses, not app users: somebody who never logs in can still be -- authorised, so this is not a link to `users`. ALTER TABLE reservations ADD COLUMN linka_emails TEXT[] NOT NULL DEFAULT '{}'; -- A check constraint cannot hold a subquery, so this catches the empty string -- rather than any blank one. The repository trims before writing, which turns a -- whitespace-only address into the empty string caught here. ALTER TABLE reservations ADD CONSTRAINT reservations_linka_emails_filled CHECK ( array_position(linka_emails, NULL) IS NULL AND NOT ('' = ANY (linka_emails))); -- migrate:down ALTER TABLE reservations DROP CONSTRAINT reservations_linka_emails_filled; ALTER TABLE reservations DROP COLUMN linka_emails;