2023-07-19 16:35:47 +02:00
|
|
|
CREATE TYPE IF NOT EXISTS drive_file (
|
2023-07-24 11:35:44 +02:00
|
|
|
"id" ascii,
|
|
|
|
"type" ascii,
|
|
|
|
"createdAt" timestamp,
|
|
|
|
"name" text,
|
|
|
|
"comment" text,
|
|
|
|
"blurhash" text,
|
|
|
|
"url" text,
|
|
|
|
"thumbnailUrl" text,
|
|
|
|
"isSensitive" boolean,
|
|
|
|
"isLink" boolean,
|
|
|
|
"md5" ascii,
|
2023-07-31 03:41:45 +02:00
|
|
|
"size" int,
|
|
|
|
"width" int,
|
|
|
|
"height" int,
|
2023-07-19 16:35:47 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TYPE IF NOT EXISTS note_edit_history (
|
2023-07-24 11:35:44 +02:00
|
|
|
"content" text,
|
|
|
|
"cw" text,
|
|
|
|
"files" set<frozen<drive_file>>,
|
|
|
|
"updatedAt" timestamp,
|
2023-07-19 16:35:47 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TYPE IF NOT EXISTS emoji (
|
2023-07-24 11:35:44 +02:00
|
|
|
"name" text,
|
|
|
|
"url" text,
|
|
|
|
"width" int,
|
|
|
|
"height" int,
|
2023-07-19 16:35:47 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS note ( -- Models timeline
|
2023-07-24 11:35:44 +02:00
|
|
|
"createdAtDate" date, -- For partitioning
|
|
|
|
"createdAt" timestamp,
|
|
|
|
"id" ascii, -- Post
|
|
|
|
"visibility" ascii,
|
|
|
|
"content" text,
|
|
|
|
"name" text,
|
|
|
|
"cw" text,
|
|
|
|
"localOnly" boolean,
|
|
|
|
"renoteCount" int,
|
|
|
|
"repliesCount" int,
|
|
|
|
"uri" text,
|
|
|
|
"url" text,
|
|
|
|
"score" int,
|
|
|
|
"files" set<frozen<drive_file>>,
|
2023-07-25 13:28:08 +02:00
|
|
|
"visibleUserIds" set<ascii>,
|
2023-07-24 11:35:44 +02:00
|
|
|
"mentions" set<ascii>,
|
2023-07-31 03:41:45 +02:00
|
|
|
"mentionedRemoteUsers" text,
|
2023-07-25 13:28:08 +02:00
|
|
|
"emojis" set<text>,
|
2023-07-24 11:35:44 +02:00
|
|
|
"tags" set<text>,
|
|
|
|
"hasPoll" boolean,
|
|
|
|
"threadId" ascii,
|
|
|
|
"channelId" ascii, -- Channel
|
|
|
|
"userId" ascii, -- User
|
2023-07-27 03:58:38 +02:00
|
|
|
"userHost" text,
|
2023-07-24 11:35:44 +02:00
|
|
|
"replyId" ascii, -- Reply
|
2023-07-27 03:58:38 +02:00
|
|
|
"replyUserId" ascii,
|
|
|
|
"replyUserHost" text,
|
2023-08-05 23:42:45 +02:00
|
|
|
"replyContent" text,
|
|
|
|
"replyCw" text,
|
|
|
|
"replyFiles" set<frozen<drive_file>>,
|
2023-07-24 11:35:44 +02:00
|
|
|
"renoteId" ascii, -- Boost
|
2023-07-27 03:58:38 +02:00
|
|
|
"renoteUserId" ascii,
|
|
|
|
"renoteUserHost" text,
|
2023-08-05 23:42:45 +02:00
|
|
|
"renoteContent" text,
|
|
|
|
"renoteCw" text,
|
|
|
|
"renoteFiles" set<frozen<drive_file>>,
|
2023-07-27 03:58:38 +02:00
|
|
|
"reactions" map<text, int>, -- Reactions
|
2023-07-24 11:35:44 +02:00
|
|
|
"noteEdit" set<frozen<note_edit_history>>, -- Edit History
|
|
|
|
"updatedAt" timestamp,
|
2023-07-24 13:52:35 +02:00
|
|
|
PRIMARY KEY ("createdAtDate", "createdAt", "id")
|
2023-07-24 11:35:44 +02:00
|
|
|
) WITH CLUSTERING ORDER BY ("createdAt" DESC);
|
2023-07-19 16:35:47 +02:00
|
|
|
|
2023-07-31 03:41:45 +02:00
|
|
|
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_id AS
|
|
|
|
SELECT * FROM note
|
|
|
|
WHERE "id" IS NOT NULL
|
|
|
|
AND "createdAt" IS NOT NULL
|
|
|
|
AND "createdAtDate" IS NOT NULL
|
|
|
|
PRIMARY KEY ("id", "createdAt", "createdAtDate")
|
|
|
|
WITH CLUSTERING ORDER BY ("createdAt" DESC);
|
2023-07-19 16:35:47 +02:00
|
|
|
|
2023-07-24 11:35:44 +02:00
|
|
|
CREATE MATERIALIZED VIEW IF NOT EXISTS note_by_userid AS
|
2023-07-19 16:35:47 +02:00
|
|
|
SELECT * FROM note
|
2023-07-24 11:35:44 +02:00
|
|
|
WHERE "userId" IS NOT NULL
|
|
|
|
AND "createdAt" IS NOT NULL
|
|
|
|
AND "createdAtDate" IS NOT NULL
|
2023-07-24 13:52:35 +02:00
|
|
|
AND "id" IS NOT NULL
|
|
|
|
PRIMARY KEY ("userId", "createdAt", "createdAtDate", "id")
|
2023-07-24 11:35:44 +02:00
|
|
|
WITH CLUSTERING ORDER BY ("createdAt" DESC);
|
2023-07-19 16:35:47 +02:00
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS reaction (
|
2023-07-24 13:52:35 +02:00
|
|
|
"id" text,
|
2023-07-24 11:35:44 +02:00
|
|
|
"noteId" ascii,
|
|
|
|
"userId" ascii,
|
2023-07-24 13:52:35 +02:00
|
|
|
"reaction" text,
|
|
|
|
"emoji" frozen<emoji>,
|
|
|
|
"createdAt" timestamp,
|
|
|
|
PRIMARY KEY ("noteId", "userId")
|
|
|
|
);
|
|
|
|
|
2023-07-31 03:41:45 +02:00
|
|
|
CREATE INDEX IF NOT EXISTS reaction_by_id ON reaction ("id");
|
2023-07-24 13:52:35 +02:00
|
|
|
|
|
|
|
CREATE MATERIALIZED VIEW IF NOT EXISTS reaction_by_userid AS
|
|
|
|
SELECT * FROM reaction
|
|
|
|
WHERE "userId" IS NOT NULL
|
|
|
|
AND "createdAt" IS NOT NULL
|
|
|
|
AND "noteId" IS NOT NULL
|
|
|
|
PRIMARY KEY ("userId", "createdAt", "noteId")
|
|
|
|
WITH CLUSTERING ORDER BY ("createdAt" DESC);
|