forked from mtusi2026/mtusi2026lab4
37 lines
955 B
PL/PgSQL
37 lines
955 B
PL/PgSQL
BEGIN;
|
|
|
|
-- Downgrading would destroy the only content of attachment-only messages.
|
|
-- Refuse instead of silently losing valid lab4 data.
|
|
DO $$
|
|
BEGIN
|
|
IF EXISTS (
|
|
SELECT 1
|
|
FROM messages
|
|
WHERE btrim(text) = ''
|
|
) THEN
|
|
RAISE EXCEPTION
|
|
'cannot downgrade while attachment-only messages exist';
|
|
END IF;
|
|
END;
|
|
$$;
|
|
|
|
DROP TRIGGER message_attachments_payload_check ON message_attachments;
|
|
DROP TRIGGER messages_payload_check ON messages;
|
|
DROP FUNCTION enforce_message_payload_from_link();
|
|
DROP FUNCTION enforce_message_payload_from_message();
|
|
|
|
DROP TABLE message_attachments;
|
|
DROP TABLE attachments;
|
|
|
|
ALTER TABLE messages
|
|
DROP CONSTRAINT messages_id_chat_unique,
|
|
DROP CONSTRAINT messages_text_length;
|
|
|
|
ALTER TABLE messages
|
|
ADD CONSTRAINT messages_text_length
|
|
CHECK (char_length(text) BETWEEN 1 AND 4000),
|
|
ADD CONSTRAINT messages_text_not_blank
|
|
CHECK (btrim(text) <> '');
|
|
|
|
COMMIT;
|