Implement lab 3 level 4 failover and idempotency
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
-- +goose Up
|
||||
|
||||
CREATE TABLE message_idempotency
|
||||
(
|
||||
user_id UUID NOT NULL REFERENCES users(id),
|
||||
chat_id UUID NOT NULL REFERENCES chats(id),
|
||||
idempotency_key VARCHAR(128) NOT NULL,
|
||||
message_id UUID NOT NULL REFERENCES messages(id),
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
expires_at TIMESTAMPTZ NOT NULL DEFAULT (now() + interval '24 hours'),
|
||||
|
||||
PRIMARY KEY (user_id, chat_id, idempotency_key),
|
||||
UNIQUE (message_id),
|
||||
|
||||
CONSTRAINT message_idempotency_key_format_check
|
||||
CHECK (idempotency_key COLLATE "C" ~ '^[A-Za-z0-9._:-]{1,128}$'),
|
||||
CONSTRAINT message_idempotency_expiry_check
|
||||
CHECK (expires_at > created_at)
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
|
||||
DROP TABLE IF EXISTS message_idempotency;
|
||||
Reference in New Issue
Block a user