-- Align imks-managed IDs with application-generated UUID v7 values and
-- make top-level drafts unique when thread_id is NULL.

BEGIN;

CREATE UNIQUE INDEX IF NOT EXISTS uq_message_draft_channel_user_no_thread
    ON message_draft (channel_id, user_id)
    WHERE thread_id IS NULL;

ALTER TABLE message_attachment ALTER COLUMN id DROP DEFAULT;
ALTER TABLE message_embed ALTER COLUMN id DROP DEFAULT;
ALTER TABLE message_embed_field ALTER COLUMN id DROP DEFAULT;
ALTER TABLE message_poll ALTER COLUMN id DROP DEFAULT;
ALTER TABLE message_poll_option ALTER COLUMN id DROP DEFAULT;
ALTER TABLE message_poll_vote ALTER COLUMN id DROP DEFAULT;
ALTER TABLE message_pin ALTER COLUMN id DROP DEFAULT;
ALTER TABLE message_read_state ALTER COLUMN id DROP DEFAULT;
ALTER TABLE message_draft ALTER COLUMN id DROP DEFAULT;
ALTER TABLE message_edit ALTER COLUMN id DROP DEFAULT;
ALTER TABLE message_article ALTER COLUMN id DROP DEFAULT;
ALTER TABLE message_reaction ALTER COLUMN id DROP DEFAULT;
ALTER TABLE message_bookmark ALTER COLUMN id DROP DEFAULT;
ALTER TABLE message_mention ALTER COLUMN id DROP DEFAULT;
ALTER TABLE message_thread ALTER COLUMN id DROP DEFAULT;
ALTER TABLE message_thread_participant ALTER COLUMN id DROP DEFAULT;
ALTER TABLE message_notification ALTER COLUMN id DROP DEFAULT;
ALTER TABLE message_scheduled ALTER COLUMN id DROP DEFAULT;
ALTER TABLE message_sticker ALTER COLUMN id DROP DEFAULT;
ALTER TABLE message_forward ALTER COLUMN id DROP DEFAULT;
ALTER TABLE message_component ALTER COLUMN id DROP DEFAULT;

COMMIT;
