14 lines
637 B
SQL
14 lines
637 B
SQL
CREATE TABLE upload_intents (
|
|
id UUID PRIMARY KEY,
|
|
chat_id UUID NOT NULL,
|
|
owner_id UUID NOT NULL,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
expires_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP + INTERVAL '10 minutes',
|
|
state TEXT NOT NULL DEFAULT 'pending' CHECK (state IN ('pending', 'abandoned')),
|
|
next_cleanup_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP + INTERVAL '10 minutes',
|
|
CHECK (expires_at > created_at),
|
|
FOREIGN KEY (chat_id, owner_id) REFERENCES chat_members(chat_id, user_id)
|
|
);
|
|
|
|
CREATE INDEX upload_intents_cleanup_idx ON upload_intents (next_cleanup_at, id);
|