api shell
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
CREATE TABLE users (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
username VARCHAR(32) UNIQUE NOT NULL,
|
||||
display_name VARCHAR(64) NOT NULL,
|
||||
avatar_url TEXT,
|
||||
password_hash TEXT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE conversations (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
next_sequence BIGINT NOT NULL DEFAULT 0
|
||||
);
|
||||
|
||||
CREATE TABLE conversation_participants (
|
||||
conversation_id UUID REFERENCES conversations(id),
|
||||
user_id UUID REFERENCES users(id),
|
||||
last_read_seq BIGINT NOT NULL DEFAULT 0,
|
||||
joined_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (conversation_id, user_id),
|
||||
UNIQUE (conversation_id, user_id)
|
||||
);
|
||||
|
||||
CREATE TABLE messages (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
conversation_id UUID REFERENCES conversations(id) NOT NULL,
|
||||
sender_id UUID REFERENCES users(id) NOT NULL,
|
||||
sequence BIGINT NOT NULL,
|
||||
message_type VARCHAR(16) NOT NULL,
|
||||
body TEXT,
|
||||
media_metadata JSONB,
|
||||
client_msg_id UUID NOT NULL,
|
||||
status VARCHAR(16) NOT NULL DEFAULT 'sent',
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
UNIQUE (conversation_id, sequence),
|
||||
UNIQUE (client_msg_id)
|
||||
);
|
||||
|
||||
CREATE TABLE sticker_packs (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
name VARCHAR(64) NOT NULL,
|
||||
author VARCHAR(64),
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE stickers (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
pack_id UUID REFERENCES sticker_packs(id) NOT NULL,
|
||||
emoji_tag VARCHAR(8),
|
||||
image_url TEXT NOT NULL,
|
||||
thumbnail_url TEXT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
Reference in New Issue
Block a user