2022-12-11 21:13:24 +00:00
|
|
|
CREATE TABLE background_job (
|
|
|
|
id UUID PRIMARY KEY,
|
|
|
|
job_type SMALLINT NOT NULL,
|
|
|
|
job_data JSONB NOT NULL,
|
|
|
|
job_status SMALLINT NOT NULL DEFAULT 1,
|
|
|
|
scheduled_for TIMESTAMP WITH TIME ZONE NOT NULL,
|
|
|
|
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
|
|
);
|
|
|
|
|
2022-10-03 20:36:17 +00:00
|
|
|
CREATE TABLE instance (
|
|
|
|
hostname VARCHAR(100) PRIMARY KEY
|
|
|
|
);
|
|
|
|
|
2021-04-09 00:22:17 +00:00
|
|
|
CREATE TABLE actor_profile (
|
|
|
|
id UUID PRIMARY KEY,
|
|
|
|
username VARCHAR(100) NOT NULL,
|
2022-10-03 20:36:17 +00:00
|
|
|
hostname VARCHAR(100) REFERENCES instance (hostname) ON DELETE RESTRICT,
|
|
|
|
acct VARCHAR(200) UNIQUE GENERATED ALWAYS AS (CASE WHEN hostname IS NULL THEN username ELSE username || '@' || hostname END) STORED,
|
2021-12-27 19:20:21 +00:00
|
|
|
display_name VARCHAR(200),
|
2021-04-09 00:22:17 +00:00
|
|
|
bio TEXT,
|
|
|
|
bio_source TEXT,
|
2023-01-06 21:49:15 +00:00
|
|
|
avatar JSONB,
|
|
|
|
banner JSONB,
|
2022-04-26 14:12:26 +00:00
|
|
|
identity_proofs JSONB NOT NULL DEFAULT '[]',
|
2022-07-23 15:47:53 +00:00
|
|
|
payment_options JSONB NOT NULL DEFAULT '[]',
|
2021-09-16 14:34:24 +00:00
|
|
|
extra_fields JSONB NOT NULL DEFAULT '[]',
|
2021-04-09 00:22:17 +00:00
|
|
|
follower_count INTEGER NOT NULL CHECK (follower_count >= 0) DEFAULT 0,
|
|
|
|
following_count INTEGER NOT NULL CHECK (following_count >= 0) DEFAULT 0,
|
2022-09-13 12:41:15 +00:00
|
|
|
subscriber_count INTEGER NOT NULL CHECK (subscriber_count >= 0) DEFAULT 0,
|
2021-04-09 00:22:17 +00:00
|
|
|
post_count INTEGER NOT NULL CHECK (post_count >= 0) DEFAULT 0,
|
|
|
|
actor_json JSONB,
|
2022-04-20 13:47:04 +00:00
|
|
|
actor_id VARCHAR(200) UNIQUE GENERATED ALWAYS AS (actor_json ->> 'id') STORED,
|
2022-07-08 19:54:12 +00:00
|
|
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
|
2022-10-03 20:36:17 +00:00
|
|
|
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
2022-12-03 21:06:15 +00:00
|
|
|
unreachable_since TIMESTAMP WITH TIME ZONE,
|
2022-10-03 20:36:17 +00:00
|
|
|
CHECK ((hostname IS NULL) = (actor_json IS NULL))
|
2021-04-09 00:22:17 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE user_invite_code (
|
|
|
|
code VARCHAR(100) PRIMARY KEY,
|
|
|
|
used BOOLEAN NOT NULL DEFAULT FALSE
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE user_account (
|
|
|
|
id UUID PRIMARY KEY REFERENCES actor_profile (id) ON DELETE CASCADE,
|
2021-12-24 17:46:01 +00:00
|
|
|
wallet_address VARCHAR(100) UNIQUE,
|
2022-02-15 19:26:06 +00:00
|
|
|
password_hash VARCHAR(200),
|
2021-04-09 00:22:17 +00:00
|
|
|
private_key TEXT NOT NULL,
|
|
|
|
invite_code VARCHAR(100) UNIQUE REFERENCES user_invite_code (code) ON DELETE SET NULL,
|
|
|
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()
|
|
|
|
);
|
|
|
|
|
2022-07-22 19:03:51 +00:00
|
|
|
CREATE TABLE oauth_token (
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
owner_id UUID NOT NULL REFERENCES user_account (id) ON DELETE CASCADE,
|
|
|
|
token VARCHAR(100) UNIQUE NOT NULL,
|
|
|
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
|
|
|
expires_at TIMESTAMP WITH TIME ZONE NOT NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE relationship (
|
|
|
|
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
|
|
|
source_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE,
|
|
|
|
target_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE,
|
|
|
|
relationship_type SMALLINT NOT NULL,
|
|
|
|
UNIQUE (source_id, target_id, relationship_type)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE follow_request (
|
|
|
|
id UUID PRIMARY KEY,
|
|
|
|
source_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE,
|
|
|
|
target_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE,
|
2022-12-12 23:50:40 +00:00
|
|
|
activity_id VARCHAR(250) UNIQUE,
|
2022-07-22 19:03:51 +00:00
|
|
|
request_status SMALLINT NOT NULL,
|
|
|
|
UNIQUE (source_id, target_id)
|
|
|
|
);
|
|
|
|
|
2021-04-09 00:22:17 +00:00
|
|
|
CREATE TABLE post (
|
|
|
|
id UUID PRIMARY KEY,
|
|
|
|
author_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE,
|
|
|
|
content TEXT NOT NULL,
|
2021-09-22 16:32:44 +00:00
|
|
|
in_reply_to_id UUID REFERENCES post (id) ON DELETE CASCADE,
|
2021-11-24 16:39:30 +00:00
|
|
|
repost_of_id UUID REFERENCES post (id) ON DELETE CASCADE,
|
2021-11-18 21:48:49 +00:00
|
|
|
visilibity SMALLINT NOT NULL,
|
2021-09-24 14:02:56 +00:00
|
|
|
reply_count INTEGER NOT NULL CHECK (reply_count >= 0) DEFAULT 0,
|
2021-10-17 16:55:33 +00:00
|
|
|
reaction_count INTEGER NOT NULL CHECK (reaction_count >= 0) DEFAULT 0,
|
2021-11-24 16:39:30 +00:00
|
|
|
repost_count INTEGER NOT NULL CHECK (repost_count >= 0) DEFAULT 0,
|
2021-10-08 22:39:40 +00:00
|
|
|
object_id VARCHAR(200) UNIQUE,
|
2021-04-09 00:22:17 +00:00
|
|
|
ipfs_cid VARCHAR(200),
|
|
|
|
token_id INTEGER,
|
|
|
|
token_tx_id VARCHAR(200),
|
2021-11-24 16:39:30 +00:00
|
|
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
|
2022-05-11 12:50:36 +00:00
|
|
|
updated_at TIMESTAMP WITH TIME ZONE,
|
2021-11-24 16:39:30 +00:00
|
|
|
UNIQUE (author_id, repost_of_id)
|
2021-04-09 00:22:17 +00:00
|
|
|
);
|
|
|
|
|
2021-10-17 16:55:33 +00:00
|
|
|
CREATE TABLE post_reaction (
|
|
|
|
id UUID PRIMARY KEY,
|
|
|
|
author_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE,
|
|
|
|
post_id UUID NOT NULL REFERENCES post (id) ON DELETE CASCADE,
|
2021-12-14 22:59:15 +00:00
|
|
|
activity_id VARCHAR(250) UNIQUE,
|
2021-10-17 16:55:33 +00:00
|
|
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
|
|
|
|
UNIQUE (author_id, post_id)
|
|
|
|
);
|
|
|
|
|
2021-04-09 00:22:17 +00:00
|
|
|
CREATE TABLE media_attachment (
|
|
|
|
id UUID PRIMARY KEY,
|
|
|
|
owner_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE,
|
|
|
|
file_name VARCHAR(200) NOT NULL,
|
2023-01-19 21:57:29 +00:00
|
|
|
file_size INTEGER,
|
|
|
|
media_type VARCHAR(50),
|
2021-09-28 21:44:31 +00:00
|
|
|
ipfs_cid VARCHAR(200),
|
2021-04-09 00:22:17 +00:00
|
|
|
post_id UUID REFERENCES post (id) ON DELETE CASCADE,
|
|
|
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()
|
2021-10-01 00:35:52 +00:00
|
|
|
);
|
|
|
|
|
2021-11-11 19:10:28 +00:00
|
|
|
CREATE TABLE mention (
|
|
|
|
post_id UUID NOT NULL REFERENCES post (id) ON DELETE CASCADE,
|
|
|
|
profile_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE,
|
|
|
|
PRIMARY KEY (post_id, profile_id)
|
|
|
|
);
|
|
|
|
|
2021-12-07 23:28:58 +00:00
|
|
|
CREATE TABLE tag (
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
tag_name VARCHAR(100) UNIQUE NOT NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE post_tag (
|
|
|
|
post_id UUID NOT NULL REFERENCES post (id) ON DELETE CASCADE,
|
|
|
|
tag_id INTEGER NOT NULL REFERENCES tag (id) ON DELETE CASCADE,
|
|
|
|
PRIMARY KEY (post_id, tag_id)
|
|
|
|
);
|
|
|
|
|
2022-08-21 21:15:30 +00:00
|
|
|
CREATE TABLE post_link (
|
|
|
|
source_id UUID NOT NULL REFERENCES post (id) ON DELETE CASCADE,
|
|
|
|
target_id UUID NOT NULL REFERENCES post (id) ON DELETE CASCADE,
|
|
|
|
PRIMARY KEY (source_id, target_id)
|
|
|
|
);
|
|
|
|
|
2023-01-07 19:28:26 +00:00
|
|
|
CREATE TABLE emoji (
|
|
|
|
id UUID PRIMARY KEY,
|
|
|
|
emoji_name VARCHAR(100) NOT NULL,
|
|
|
|
hostname VARCHAR(100) REFERENCES instance (hostname) ON DELETE RESTRICT,
|
|
|
|
image JSONB NOT NULL,
|
|
|
|
object_id VARCHAR(250) UNIQUE,
|
|
|
|
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
|
|
|
UNIQUE (emoji_name, hostname),
|
|
|
|
CHECK ((hostname IS NULL) = (object_id IS NULL))
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE post_emoji (
|
|
|
|
post_id UUID NOT NULL REFERENCES post (id) ON DELETE CASCADE,
|
|
|
|
emoji_id UUID NOT NULL REFERENCES emoji (id) ON DELETE CASCADE,
|
|
|
|
PRIMARY KEY (post_id, emoji_id)
|
|
|
|
);
|
|
|
|
|
2021-10-12 16:11:47 +00:00
|
|
|
CREATE TABLE notification (
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
sender_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE,
|
|
|
|
recipient_id UUID NOT NULL REFERENCES user_account (id) ON DELETE CASCADE,
|
|
|
|
post_id UUID REFERENCES post (id) ON DELETE CASCADE,
|
|
|
|
event_type SMALLINT NOT NULL,
|
|
|
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()
|
|
|
|
);
|
2021-11-03 12:03:56 +00:00
|
|
|
|
|
|
|
CREATE TABLE timeline_marker (
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
user_id UUID NOT NULL REFERENCES user_account (id) ON DELETE CASCADE,
|
|
|
|
timeline SMALLINT NOT NULL,
|
|
|
|
last_read_id VARCHAR(100) NOT NULL,
|
|
|
|
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
|
|
|
|
UNIQUE (user_id, timeline)
|
|
|
|
);
|
2022-02-04 21:43:18 +00:00
|
|
|
|
2022-08-24 19:36:57 +00:00
|
|
|
CREATE TABLE invoice (
|
|
|
|
id UUID PRIMARY KEY,
|
|
|
|
sender_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE,
|
|
|
|
recipient_id UUID NOT NULL REFERENCES user_account (id) ON DELETE CASCADE,
|
|
|
|
chain_id VARCHAR(50) NOT NULL,
|
|
|
|
payment_address VARCHAR(200) NOT NULL,
|
2022-09-18 00:23:20 +00:00
|
|
|
amount BIGINT NOT NULL CHECK (amount >= 0),
|
2022-08-24 19:36:57 +00:00
|
|
|
invoice_status SMALLINT NOT NULL DEFAULT 1,
|
|
|
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
UNIQUE (chain_id, payment_address)
|
|
|
|
);
|
|
|
|
|
2022-02-04 21:43:18 +00:00
|
|
|
CREATE TABLE subscription (
|
|
|
|
id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
|
|
sender_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE,
|
2022-08-30 23:56:10 +00:00
|
|
|
sender_address VARCHAR(100),
|
2022-02-04 21:43:18 +00:00
|
|
|
recipient_id UUID NOT NULL REFERENCES user_account (id) ON DELETE CASCADE,
|
2022-08-30 20:33:45 +00:00
|
|
|
chain_id VARCHAR(50) NOT NULL,
|
2022-02-04 21:43:18 +00:00
|
|
|
expires_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
|
|
|
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
|
|
|
UNIQUE (sender_id, recipient_id)
|
|
|
|
);
|