Files
tg-archive/migrations/20260807000000_message_versions.sql
T
Elias Wendland 5a5f817df7
CI and release / Detect release commit (push) Successful in 2m42s
CI and release / Run tests (push) Successful in 7m18s
CI and release / Build and publish container (push) Failing after 5m12s
CI and release / Create release (push) Skipped
Initial commit
2026-08-07 11:54:42 +02:00

42 lines
1.2 KiB
SQL

CREATE TABLE message_versions (
uuid UUID PRIMARY KEY DEFAULT gen_random_uuid(),
message_id BIGINT NOT NULL,
version BIGINT NOT NULL,
content TEXT,
archived_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
UNIQUE (message_id, version),
FOREIGN KEY (message_id)
REFERENCES messages(message_id)
ON DELETE CASCADE
);
INSERT INTO message_versions (message_id, version, content)
SELECT message_id, 1, content
FROM messages;
ALTER TABLE attachments
ADD COLUMN message_version BIGINT NOT NULL DEFAULT 1;
ALTER TABLE attachments
DROP CONSTRAINT attachments_attachment_id_key;
ALTER TABLE attachments
ADD UNIQUE (message_id, message_version, attachment_id),
ADD FOREIGN KEY (message_id, message_version)
REFERENCES message_versions(message_id, version)
ON DELETE CASCADE;
ALTER TABLE embeds
ADD COLUMN message_version BIGINT NOT NULL DEFAULT 1;
ALTER TABLE embeds
DROP CONSTRAINT embeds_message_id_embed_index_key;
ALTER TABLE embeds
ADD UNIQUE (message_id, message_version, embed_index),
ADD FOREIGN KEY (message_id, message_version)
REFERENCES message_versions(message_id, version)
ON DELETE CASCADE;