-- person: основная почта (email, @khbuild.pro) и дополнительные почты через ";" (additional_emails), например yuyaryshev@gmail.com. -- Условные блоки: на сервере таблицу person после подключения Mathesar ведёт другая роль и колонка с индексом уже созданы вручную, -- поэтому ALTER и CREATE INDEX выполняются, только если их ещё нет (иначе khb_app не владелец и миграция упала бы). do $$ begin if not exists (select 1 from information_schema.columns where table_schema = 'public' and table_name = 'person' and column_name = 'additional_emails') then alter table person add column additional_emails text; comment on column person.email is 'Основная почта на @khbuild.pro'; comment on column person.additional_emails is 'Дополнительные почты через ";", например yuyaryshev@gmail.com'; end if; if not exists (select 1 from pg_indexes where schemaname = 'public' and indexname = 'person_email_lower_key') then create unique index person_email_lower_key on person (lower(email)) where email is not null; end if; end $$;