forked from danielkarszt/DSNP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchoice.sql
215 lines (158 loc) · 3.57 KB
/
choice.sql
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
DROP TABLE IF EXISTS user;
CREATE TABLE user
(
id BIGINT NOT NULL AUTO_INCREMENT,
user VARCHAR(20),
pass_salt CHAR(24) BINARY,
pass VARCHAR(40) BINARY,
user_keys_id BIGINT,
identity_id BIGINT,
relationship_id BIGINT,
network_id BIGINT,
PRIMARY KEY( id ),
UNIQUE KEY ( user )
);
DROP TABLE IF EXISTS identity;
CREATE TABLE identity
(
id BIGINT NOT NULL AUTO_INCREMENT,
iduri VARCHAR(128),
hash VARCHAR(48) BINARY,
PRIMARY KEY( id ),
UNIQUE KEY ( iduri )
);
DROP TABLE IF EXISTS relationship;
CREATE TABLE relationship
(
id BIGINT NOT NULL AUTO_INCREMENT,
user_id BIGINT,
-- 1: self.
-- 8: friend.
type SMALLINT,
identity_id BIGINT,
-- User's view of the remote identity. This is used for one's own data
-- as well.
name TEXT,
email VARCHAR(50),
PRIMARY KEY( id ),
UNIQUE( user_id, identity_id )
);
DROP TABLE IF EXISTS friend_request;
CREATE TABLE friend_request
(
id BIGINT NOT NULL AUTO_INCREMENT,
user_id BIGINT,
identity_id BIGINT,
relationship_id BIGINT,
accept_reqid VARCHAR(48) BINARY,
PRIMARY KEY( id )
);
DROP TABLE IF EXISTS sent_friend_request;
CREATE TABLE sent_friend_request
(
id BIGINT NOT NULL AUTO_INCREMENT,
user_id BIGINT,
identity_id BIGINT,
relationship_id BIGINT,
user_notify_reqid VARCHAR(48) BINARY,
PRIMARY KEY( id )
);
DROP TABLE IF EXISTS friend_claim;
CREATE TABLE friend_claim
(
id BIGINT NOT NULL AUTO_INCREMENT,
user_id BIGINT,
identity_id BIGINT,
relationship_id BIGINT,
PRIMARY KEY( id ),
UNIQUE KEY ( user_id, identity_id )
);
DROP TABLE IF EXISTS network;
CREATE TABLE network
(
id BIGINT NOT NULL AUTO_INCREMENT,
user_id BIGINT,
-- 1: primary.
-- 2: friend group.
type SMALLINT,
-- Name visible to the user.
private_name VARCHAR(20),
-- Name distributed to others.
dist_name VARCHAR(48) BINARY,
key_gen BIGINT,
PRIMARY KEY ( id )
);
--
-- Should have three tables:
-- published_owner: owner's view of what's published
-- published_friend: friend's view of what's published
-- activity_stream: what's going on with the user's friends.
--
DROP TABLE IF EXISTS activity;
CREATE TABLE activity
(
id BIGINT NOT NULL AUTO_INCREMENT,
-- What is it?
pub_type INT,
-- The actors.
user_id BIGINT,
publisher_id BIGINT,
author_id BIGINT,
subject_id BIGINT,
-- Supplied by the publisher.
message_id VARCHAR(48),
time_published TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
time_received TIMESTAMP DEFAULT 0,
-- Pointers to material.
remote_resource TEXT,
remote_presentation TEXT,
local_resource TEXT,
local_presentation TEXT,
local_thumbnail TEXT,
message BLOB,
PRIMARY KEY ( id ),
-- The publishers are relationship_ids, which are all unique to each
-- user, so we don't need to include user_id.
UNIQUE KEY ( publisher_id, message_id )
);
DROP TABLE IF EXISTS image;
CREATE TABLE image
(
user_id BIGINT,
seq_num BIGINT NOT NULL AUTO_INCREMENT,
rows INT,
cols INT,
mime_type VARCHAR(32),
PRIMARY KEY ( user_id, seq_num )
);
DROP TABLE IF EXISTS remote_image;
CREATE TABLE remote_image
(
user_id BIGINT,
seq_num BIGINT NOT NULL AUTO_INCREMENT,
PRIMARY KEY ( user_id, seq_num )
);
DROP TABLE IF EXISTS publication;
CREATE TABLE publication
(
id BIGINT NOT NULL AUTO_INCREMENT,
message_id VARCHAR(64),
user_id BIGINT,
author_id BIGINT,
subject_id BIGINT,
publication_type INT,
local_resource TEXT,
local_presentation TEXT,
time_published TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
message BLOB,
PRIMARY KEY ( id )
);
--
-- Database schema verison. Initialize it.
--
DROP TABLE IF EXISTS version;
CREATE TABLE version
(
version INT
);
INSERT INTO version ( version ) VALUES ( 3 );