2023-07-19 16:35:47 +02:00
|
|
|
CREATE TYPE IF NOT EXISTS drive_file (
|
|
|
|
id ascii,
|
|
|
|
type ascii,
|
2023-07-24 04:29:38 +02:00
|
|
|
createdAt timestamp,
|
2023-07-19 16:35:47 +02:00
|
|
|
name text,
|
|
|
|
comment text,
|
|
|
|
blurhash text,
|
|
|
|
url text,
|
2023-07-24 04:29:38 +02:00
|
|
|
thumbnailUrl text,
|
|
|
|
isSensitive boolean,
|
|
|
|
isLink boolean,
|
2023-07-19 16:35:47 +02:00
|
|
|
md5 ascii,
|
|
|
|
size int,
|
|
|
|
width int,
|
|
|
|
height int,
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TYPE IF NOT EXISTS note_edit_history (
|
|
|
|
content text,
|
|
|
|
cw text,
|
|
|
|
files set<frozen<drive_file>>,
|
2023-07-24 04:29:38 +02:00
|
|
|
updatedAt timestamp,
|
2023-07-19 16:35:47 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TYPE IF NOT EXISTS emoji (
|
|
|
|
name text,
|
|
|
|
url text,
|
|
|
|
width int,
|
|
|
|
height int,
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS note ( -- Models timeline
|
2023-07-24 04:29:38 +02:00
|
|
|
createdAtDate date, -- For partitioning
|
|
|
|
createdAt timestamp,
|
2023-07-19 16:35:47 +02:00
|
|
|
id ascii, -- Post
|
|
|
|
visibility ascii,
|
|
|
|
content text,
|
|
|
|
name text,
|
|
|
|
cw text,
|
2023-07-24 04:29:38 +02:00
|
|
|
localOnly boolean,
|
|
|
|
renoteCount int,
|
|
|
|
repliesCount int,
|
2023-07-19 16:35:47 +02:00
|
|
|
uri text,
|
|
|
|
url text,
|
|
|
|
score int,
|
|
|
|
files set<frozen<drive_file>>,
|
2023-07-24 04:29:38 +02:00
|
|
|
visibleUsersId set<ascii>,
|
2023-07-19 16:35:47 +02:00
|
|
|
mentions set<ascii>,
|
|
|
|
emojis set<frozen<emoji>>,
|
|
|
|
tags set<text>,
|
2023-07-24 04:29:38 +02:00
|
|
|
hasPoll boolean,
|
|
|
|
threadId ascii,
|
|
|
|
channelId ascii, -- Channel
|
|
|
|
channelName text,
|
|
|
|
userId ascii, -- User
|
|
|
|
replyId ascii, -- Reply
|
|
|
|
renoteId ascii, -- Boost
|
2023-07-19 16:35:47 +02:00
|
|
|
reactions map<text, int>,
|
2023-07-24 04:29:38 +02:00
|
|
|
reactionEmojis map<text, frozen<emoji>>,
|
|
|
|
noteEdit set<frozen<note_edit_history>>, -- Edit History
|
|
|
|
updatedAt timestamp,
|
|
|
|
PRIMARY KEY (createdAtDate, createdAt)
|
2023-07-24 09:53:13 +02:00
|
|
|
) WITH CLUSTERING ORDER BY (createdAt DESC);
|
2023-07-19 16:35:47 +02:00
|
|
|
|
|
|
|
CREATE INDEX IF NOT EXISTS note_by_id ON note (id);
|
|
|
|
CREATE INDEX IF NOT EXISTS note_by_uri ON note (uri);
|
|
|
|
CREATE INDEX IF NOT EXISTS note_by_url ON note (url);
|
|
|
|
|
|
|
|
CREATE MATERIALIZED VIEW IF NOT EXISTS note_by_user_id AS
|
|
|
|
SELECT * FROM note
|
2023-07-24 04:29:38 +02:00
|
|
|
WHERE userId IS NOT NULL
|
|
|
|
AND createdAt IS NOT NULL
|
|
|
|
AND createdAtDate IS NOT NULL
|
|
|
|
PRIMARY KEY (userId, createdAt, createdAtDate)
|
|
|
|
WITH CLUSTERING ORDER BY (createdAt DESC);
|
2023-07-19 16:35:47 +02:00
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS reaction (
|
2023-07-24 04:29:38 +02:00
|
|
|
noteId ascii,
|
|
|
|
createdAt timestamp,
|
|
|
|
userId ascii,
|
2023-07-19 16:35:47 +02:00
|
|
|
reaction frozen<emoji>,
|
2023-07-24 04:29:38 +02:00
|
|
|
PRIMARY KEY (noteId, createdAt, userId)
|
2023-07-19 16:35:47 +02:00
|
|
|
);
|