hippofish/packages/backend/native-utils/scylla-migration/cql/1689400417034_timeline/up.cql

94 lines
2.2 KiB
Cassandra CQL
Raw Normal View History

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,
"size" 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-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
"channelName" text,
"userId" ascii, -- User
"replyId" ascii, -- Reply
"renoteId" ascii, -- Boost
"reactions" map<text, int>,
"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
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);
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")
);
CREATE INDEX IF NOT EXISTS reaction_by_id ON reaction (id);
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);