-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.cql
89 lines (74 loc) · 2.14 KB
/
schema.cql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
CREATE KEYSPACE IF NOT EXISTS "poc" WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 1};
USE poc;
-- Tables related to `users`
CREATE TABLE user (
user_id text,
username text,
password_hash text,
name text,
avatar_url text,
created_at timestamp,
updated_at timestamp,
PRIMARY KEY (user_id)
);
-- Tables related to `feeds`
CREATE TABLE feed (
feed_id text,
feedname text,
description text,
created_at timestamp,
updated_at timestamp,
PRIMARY KEY (feed_id)
);
CREATE INDEX ON feed (feedname);
-- Tables related to `posts`
CREATE TABLE post (
feed_id text,
post_id text,
user_id text,
text text,
created_at timestamp,
PRIMARY KEY (feed_id, post_id)
) WITH CLUSTERING ORDER BY (post_id DESC);
-- -- out-of-scope: list all posts of a user (any feed)
-- CREATE MATERIALIZED VIEW post_by_user_mview AS
-- SELECT *
-- FROM post
-- WHERE user_id IS NOT NULL
-- AND feed_id IS NOT NULL
-- AND post_id IS NOT NULL
-- PRIMARY KEY (user_id, post_id, feed_id);
-- out-of-scope: list all posts of a user for a particular feed
CREATE MATERIALIZED VIEW post_by_user_feed_mview AS
SELECT *
FROM post
WHERE user_id IS NOT NULL
AND feed_id IS NOT NULL
AND post_id IS NOT NULL
PRIMARY KEY ((user_id, feed_id), post_id);
CREATE TABLE post_stats (
feed_id text,
post_id text,
impressions counter,
bookmarked counter,
likes counter,
replies counter,
PRIMARY KEY (feed_id, post_id)
) WITH CLUSTERING ORDER BY (post_id DESC);
-- Tables related to relations between `users` and `posts`
CREATE TABLE user_x_post_rel (
user_id text,
rel_type text,
post_id text,
created_at timestamp,
PRIMARY KEY (user_id, rel_type, post_id)
) WITH CLUSTERING ORDER
BY (rel_type ASC, post_id DESC);
-- -- out-of-scope: e.g. query all user likes for a specific post
-- CREATE MATERIALIZED VIEW post_x_user_rel_mview AS
-- SELECT *
-- FROM user_x_post_rel
-- WHERE post_id IS NOT NULL
-- AND rel_type IS NOT NULL
-- AND user_id IS NOT NULL
-- PRIMARY KEY (post_id, rel_type, user_id);