· 7 years ago · Nov 15, 2018, 05:24 AM
1CREATE KEYSPACE IF NOT EXISTS instagram WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor' : 3}
2
3CREATE TABLE IF NOT EXISTS instagram.user (
4 user_id uuid,
5 username text,
6 email text,
7 password text,
8 creation_date timestamp,
9 PRIMARY KEY (user_id)
10 );
11
12CREATE TABLE IF NOT EXISTS instagram.subscription (
13 user_id uuid,
14 tag text,
15 subscribe_date timestamp,
16 PRIMARY KEY (user_id, subscribe_date)
17) WITH CLUSTERING ORDER BY (subscribe_date DESC);
18
19CREATE TABLE IF NOT EXISTS instagram.follows (
20 user_id uuid,
21 follows uuid,
22 follow_date timestamp,
23 PRIMARY KEY (user_id, follow_date)
24) WITH CLUSTERING ORDER BY (follow_date DESC);
25
26CREATE TABLE IF NOT EXISTS instagram.followed_by (
27 user_id uuid,
28 followed_by uuid,
29 follow_date timestamp,
30 PRIMARY KEY (user_id, follow_date)
31) WITH CLUSTERING ORDER BY (follow_date DESC);
32
33 #tag joined with pipes "artsy|summer|test"
34 CREATE TABLE IF NOT EXISTS instagram.user_post (
35 user_id uuid,
36 post_id timeuuid,
37 tag text,
38 caption text,
39 PRIMARY KEY (user_id, post_id)
40 ) WITH CLUSTERING ORDER BY (post_id DESC);
41
42 # tag individual tag
43CREATE TABLE IF NOT EXISTS instagram.user_post_tag (
44 user_id uuid,
45 post_id timeuuid,
46 tag text,
47 caption text,
48 PRIMARY KEY(tag, post_id)
49 ) WITH CLUSTERING ORDER BY (post_id DESC);
50
51CREATE TABLE IF NOT EXISTS instagram.user_post_comment (
52 user_id uuid,
53 post_id timeuuid,
54 comment text,
55 PRIMARY KEY (user_id, post_id)
56) WITH CLUSTERING ORDER BY (post_id DESC);
57
58CREATE TABLE IF NOT EXISTS instagram.user_post_timeline (
59 user_id uuid,
60 post_id timeuuid,
61 month text,
62 PRIMARY KEY ((user_id, month) post_id)
63) WITH CLUSTERING ORDER BY (post_id DESC);