Lab5 - оценка 4

This commit is contained in:
2026-11-10 13:55:56 +03:00
parent 276dbdad8a
commit e138dfb13d
53 changed files with 7477 additions and 24 deletions
@@ -0,0 +1,18 @@
-- LAB 4: разрешаем пустой текст, если сообщение содержит хотя бы одно вложение.
--
-- Контракт lab4:
-- либо text непустой (1..4000),
-- либо attachment_ids содержит хотя бы один элемент.
--
-- Старое ограничение lab3 требовало char_length(text) >= 1 всегда,
-- поэтому оно ломает сообщения вида {"text":"","attachment_ids":[...]}.
ALTER TABLE messages
DROP CONSTRAINT IF EXISTS messages_text_check;
ALTER TABLE messages
ADD CONSTRAINT messages_text_check CHECK (
(char_length(text) >= 1 AND char_length(text) <= 4000)
OR
(char_length(text) = 0 AND cardinality(attachment_ids) > 0)
);