Files
khb_microservices/packages/khb_common/migrations/012_person_additional_emails.sql
Yuri Yaryshev 9e4b039e5e
All checks were successful
ci / test (push) Successful in 25s
ci / deploy (push) Successful in 1m46s
person: дополнительные почты (additional_emails) и уникальность основной почты
Миграция 012: колонка additional_emails (почты через ";") и уникальный индекс по
lower(email); блоки условные, на сервере (таблица принадлежит роли Mathesar) уже
созданное не трогают. Документация person: команда внесена в таблицу.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-15 17:56:01 +03:00

15 lines
1.3 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 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 $$;