fedimovies/migrations/schema.sql

126 lines
4.4 KiB
MySQL
Raw Normal View History

2021-04-09 00:22:17 +00:00
CREATE TABLE actor_profile (
id UUID PRIMARY KEY,
username VARCHAR(100) NOT NULL,
display_name VARCHAR(200),
2021-04-09 00:22:17 +00:00
acct VARCHAR(200) UNIQUE NOT NULL,
bio TEXT,
bio_source TEXT,
avatar_file_name VARCHAR(100),
banner_file_name VARCHAR(100),
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,
post_count INTEGER NOT NULL CHECK (post_count >= 0) DEFAULT 0,
actor_json JSONB,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()
);
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,
wallet_address VARCHAR(100) UNIQUE,
2021-04-09 00:22:17 +00:00
password_hash VARCHAR(200) NOT NULL,
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()
);
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,
repost_of_id UUID REFERENCES post (id) ON DELETE CASCADE,
visilibity SMALLINT NOT NULL,
reply_count INTEGER NOT NULL CHECK (reply_count >= 0) DEFAULT 0,
reaction_count INTEGER NOT NULL CHECK (reaction_count >= 0) DEFAULT 0,
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),
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
UNIQUE (author_id, repost_of_id)
2021-04-09 00:22:17 +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,
activity_id VARCHAR(250) UNIQUE,
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 relationship (
2022-01-02 13:38:40 +00:00
id INTEGER GENERATED BY DEFAULT AS IDENTITY,
2021-04-09 00:22:17 +00:00
source_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE,
target_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE,
PRIMARY KEY (source_id, target_id)
);
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,
request_status SMALLINT NOT NULL,
UNIQUE (source_id, target_id)
);
CREATE TABLE media_attachment (
id UUID PRIMARY KEY,
owner_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE,
media_type VARCHAR(50),
file_name VARCHAR(200) NOT NULL,
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)
);
2021-10-01 00:35:52 +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
);
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()
);
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)
);