fix(database): align UUID defaults and add draft uniqueness constraint

- Create unique index for message_draft when thread_id is NULL
- Drop default values from ID columns across multiple message-related tables
- Ensure imks-managed IDs align with application-generated UUID v7 values
- Make top-level drafts unique per channel and user combination
This commit is contained in:
zhenyi
2026-06-11 12:14:46 +08:00
parent 821537186e
commit 40241e5db3
@@ -0,0 +1,32 @@
-- 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;