]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - db/laconica.sql
Twitter integration - SQL ref data for Twitter
[quix0rs-gnu-social.git] / db / laconica.sql
1 /* local and remote users have profiles */
2
3 create table profile (
4     id integer auto_increment primary key comment 'unique identifier',
5     nickname varchar(64) not null comment 'nickname or username',
6     fullname varchar(255) comment 'display name',
7     profileurl varchar(255) comment 'URL, cached so we dont regenerate',
8     homepage varchar(255) comment 'identifying URL',
9     bio varchar(140) comment 'descriptive biography',
10     location varchar(255) comment 'physical location',
11     created datetime not null comment 'date this record was created',
12     modified timestamp comment 'date this record was modified',
13
14     index profile_nickname_idx (nickname),
15     FULLTEXT(nickname, fullname, location, bio, homepage)
16 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin;
17
18 create table avatar (
19     profile_id integer not null comment 'foreign key to profile table' references profile (id),
20     original boolean default false comment 'uploaded by user or generated?',
21     width integer not null comment 'image width',
22     height integer not null comment 'image height',
23     mediatype varchar(32) not null comment 'file type',
24     filename varchar(255) null comment 'local filename, if local',
25     url varchar(255) unique key comment 'avatar location',
26     created datetime not null comment 'date this record was created',
27     modified timestamp comment 'date this record was modified',
28
29     constraint primary key (profile_id, width, height),
30     index avatar_profile_id_idx (profile_id)
31 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
32
33 create table sms_carrier (
34     id integer auto_increment primary key comment 'primary key for SMS carrier',
35     name varchar(64) unique key comment 'name of the carrier',
36     email_pattern varchar(255) not null comment 'sprintf pattern for making an email address from a phone number',
37     created datetime not null comment 'date this record was created',
38     modified timestamp comment 'date this record was modified'
39 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
40
41 /* local users */
42
43 create table user (
44     id integer primary key comment 'foreign key to profile table' references profile (id),
45     nickname varchar(64) unique key comment 'nickname or username, duped in profile',
46     password varchar(255) comment 'salted password, can be null for OpenID users',
47     email varchar(255) unique key comment 'email address for password recovery etc.',
48     incomingemail varchar(255) unique key comment 'email address for post-by-email',
49     emailnotifysub tinyint default 1 comment 'Notify by email of subscriptions',
50     emailnotifyfav tinyint default 1 comment 'Notify by email of favorites',
51     emailmicroid tinyint default 1 comment 'whether to publish email microid',
52     language varchar(50) comment 'preferred language',
53     timezone varchar(50) comment 'timezone',
54     emailpost tinyint default 1 comment 'Post by email',
55     jabber varchar(255) unique key comment 'jabber ID for notices',
56     jabbernotify tinyint default 0 comment 'whether to send notices to jabber',
57     jabberreplies tinyint default 0 comment 'whether to send notices to jabber on replies',
58     jabbermicroid tinyint default 1 comment 'whether to publish xmpp microid',
59     updatefrompresence tinyint default 0 comment 'whether to record updates from Jabber presence notices',
60     sms varchar(64) unique key comment 'sms phone number',
61     carrier integer comment 'foreign key to sms_carrier' references sms_carrier (id),
62     smsnotify tinyint default 0 comment 'whether to send notices to SMS',
63     smsreplies tinyint default 0 comment 'whether to send notices to SMS on replies',
64     smsemail varchar(255) comment 'built from sms and carrier',
65     uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI',
66     autosubscribe tinyint default 0 comment 'automatically subscribe to users who subscribe to us',
67     created datetime not null comment 'date this record was created',
68     modified timestamp comment 'date this record was modified',
69
70     index user_smsemail_idx (smsemail)
71 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
72
73 /* remote people */
74
75 create table remote_profile (
76     id integer primary key comment 'foreign key to profile table' references profile (id),
77     uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI',
78     postnoticeurl varchar(255) comment 'URL we use for posting notices',
79     updateprofileurl varchar(255) comment 'URL we use for updates to this profile',
80     created datetime not null comment 'date this record was created',
81     modified timestamp comment 'date this record was modified'
82 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
83
84 create table subscription (
85     subscriber integer not null comment 'profile listening',
86     subscribed integer not null comment 'profile being listened to',
87     token varchar(255) comment 'authorization token',
88     secret varchar(255) comment 'token secret',
89     created datetime not null comment 'date this record was created',
90     modified timestamp comment 'date this record was modified',
91
92     constraint primary key (subscriber, subscribed),
93     index subscription_subscriber_idx (subscriber),
94     index subscription_subscribed_idx (subscribed)
95 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
96
97 create table notice (
98
99     id integer auto_increment primary key comment 'unique identifier',
100     profile_id integer not null comment 'who made the update' references profile (id),
101     uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI',
102     content varchar(140) comment 'update content',
103     rendered text comment 'HTML version of the content',
104     url varchar(255) comment 'URL of any attachment (image, video, bookmark, whatever)',
105     created datetime not null comment 'date this record was created',
106     modified timestamp comment 'date this record was modified',
107     reply_to integer comment 'notice replied to (usually a guess)' references notice (id),
108     is_local tinyint default 0 comment 'notice was generated by a user',
109     source varchar(32) comment 'source of comment, like "web", "im", or "clientname"',
110
111     index notice_profile_id_idx (profile_id),
112     index notice_created_idx (created),
113     FULLTEXT(content)
114 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin;
115
116 create table notice_source (
117      code varchar(32) primary key not null comment 'source code',
118      name varchar(255) not null comment 'name of the source',
119      url varchar(255) not null comment 'url to link to',
120      created datetime not null comment 'date this record was created',
121      modified timestamp comment 'date this record was modified'
122 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
123
124 create table reply (
125
126     notice_id integer not null comment 'notice that is the reply' references notice (id),
127     profile_id integer not null comment 'profile replied to' references profile (id),
128     modified timestamp not null comment 'date this record was modified',
129     replied_id integer comment 'notice replied to (not used, see notice.reply_to)',
130
131     constraint primary key (notice_id, profile_id),
132     index reply_notice_id_idx (notice_id),
133     index reply_profile_id_idx (profile_id),
134     index reply_replied_id_idx (replied_id)
135
136 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
137
138 create table fave (
139
140     notice_id integer not null comment 'notice that is the favorite' references notice (id),
141     user_id integer not null comment 'user who likes this notice' references user (id),
142     modified timestamp not null comment 'date this record was modified',
143
144     constraint primary key (notice_id, user_id),
145     index fave_notice_id_idx (notice_id),
146     index fave_user_id_idx (user_id),
147     index fave_modified_idx (modified)
148
149 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
150
151 /* tables for OAuth */
152
153 create table consumer (
154     consumer_key varchar(255) primary key comment 'unique identifier, root URL',
155     seed char(32) not null comment 'seed for new tokens by this consumer',
156
157     created datetime not null comment 'date this record was created',
158     modified timestamp comment 'date this record was modified'
159 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
160
161 create table token (
162     consumer_key varchar(255) not null comment 'unique identifier, root URL' references consumer (consumer_key),
163     tok char(32) not null comment 'identifying value',
164     secret char(32) not null comment 'secret value',
165     type tinyint not null default 0 comment 'request or access',
166     state tinyint default 0 comment 'for requests; 0 = initial, 1 = authorized, 2 = used',
167
168     created datetime not null comment 'date this record was created',
169     modified timestamp comment 'date this record was modified',
170
171     constraint primary key (consumer_key, tok)
172 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
173
174 create table nonce (
175     consumer_key varchar(255) not null comment 'unique identifier, root URL',
176     tok char(32) not null comment 'identifying value',
177     nonce char(32) not null comment 'nonce',
178     ts datetime not null comment 'timestamp sent',
179
180     created datetime not null comment 'date this record was created',
181     modified timestamp comment 'date this record was modified',
182
183     constraint primary key (consumer_key, tok, nonce),
184     constraint foreign key (consumer_key, tok) references token (consumer_key, tok)
185 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
186
187 /* One-to-many relationship of user to openid_url */
188
189 create table user_openid (
190     canonical varchar(255) primary key comment 'Canonical true URL',
191     display varchar(255) not null unique key comment 'URL for viewing, may be different from canonical',
192     user_id integer not null comment 'user owning this URL' references user (id),
193     created datetime not null comment 'date this record was created',
194     modified timestamp comment 'date this record was modified',
195
196     index user_openid_user_id_idx (user_id)
197 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
198
199 /* These are used by JanRain OpenID library */
200
201 create table oid_associations (
202     server_url BLOB,
203     handle VARCHAR(255) character set latin1,
204     secret BLOB,
205     issued INTEGER,
206     lifetime INTEGER,
207     assoc_type VARCHAR(64),
208     PRIMARY KEY (server_url(255), handle)
209 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
210
211 create table oid_nonces (
212     server_url VARCHAR(2047),
213     timestamp INTEGER,
214     salt CHAR(40),
215     UNIQUE (server_url(255), timestamp, salt)
216 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
217
218 create table confirm_address (
219     code varchar(32) not null primary key comment 'good random code',
220     user_id integer not null comment 'user who requested confirmation' references user (id),
221     address varchar(255) not null comment 'address (email, Jabber, SMS, etc.)',
222     address_extra varchar(255) not null comment 'carrier ID, for SMS',
223     address_type varchar(8) not null comment 'address type ("email", "jabber", "sms")',
224     claimed datetime comment 'date this was claimed for queueing',
225     sent datetime comment 'date this was sent for queueing',
226     modified timestamp comment 'date this record was modified'
227 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
228
229 create table remember_me (
230     code varchar(32) not null primary key comment 'good random code',
231     user_id integer not null comment 'user who is logged in' references user (id),
232     modified timestamp comment 'date this record was modified'
233 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
234
235 create table queue_item (
236
237     notice_id integer not null comment 'notice queued' references notice (id),
238     transport varchar(8) not null comment 'queue for what? "email", "jabber", "sms", "irc", ...',
239     created datetime not null comment 'date this record was created',
240     claimed datetime comment 'date this item was claimed',
241
242     constraint primary key (notice_id, transport),
243     index queue_item_created_idx (created)
244
245 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
246
247 /* Hash tags */
248 create table notice_tag (
249     tag varchar( 64 ) not null comment 'hash tag associated with this notice',
250     notice_id integer not null comment 'notice tagged' references notice (id),
251     created datetime not null comment 'date this record was created',
252
253     constraint primary key (tag, notice_id),
254     index notice_tag_created_idx (created)
255 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
256
257 /* Synching with foreign services */
258
259 create table foreign_service (
260      id int not null primary key comment 'numeric key for service',
261      name varchar(32) not null unique key comment 'name of the service',
262      description varchar(255) comment 'description',
263      created datetime not null comment 'date this record was created',
264      modified timestamp comment 'date this record was modified'
265 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
266
267 create table foreign_user (
268      id int not null comment 'unique numeric key on foreign service',
269      service int not null comment 'foreign key to service' references foreign_service(id),
270      uri varchar(255) not null unique key comment 'identifying URI',
271      nickname varchar(255) comment 'nickname on foreign service',
272      created datetime not null comment 'date this record was created',
273      modified timestamp comment 'date this record was modified',
274
275      constraint primary key (id, service)
276 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
277
278 create table foreign_link (
279      user_id int comment 'link to user on this system, if exists' references user (id),
280      foreign_id int comment 'link ' references foreign_user(id),
281      service int not null comment 'foreign key to service' references foreign_service(id),
282      credentials varchar(255) comment 'authc credentials, typically a password',
283      noticesync tinyint not null default 1 comment 'notice synchronization, bit 1 = sync outgoing, bit 2 = sync incoming',
284      friendsync tinyint not null default 2 comment 'friend synchronization, bit 1 = sync outgoing, bit 2 = sync incoming',
285      profilesync tinyint not null default 1 comment 'profile synchronization, bit 1 = sync outgoing, bit 2 = sync incoming',
286      created datetime not null comment 'date this record was created',
287      modified timestamp comment 'date this record was modified',
288
289      constraint primary key (user_id, foreign_id, service),
290      index foreign_user_user_id_idx (user_id)
291 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
292
293 create table foreign_subscription (
294      service int not null comment 'service where relationship happens' references foreign_service(id),
295      subscriber int not null comment 'subscriber on foreign service' references foreign_user (id),
296      subscribed int not null comment 'subscribed user' references foreign_user (id),
297      created datetime not null comment 'date this record was created',
298
299      constraint primary key (service, subscriber, subscribed),
300      index foreign_subscription_subscriber_idx (subscriber),
301      index foreign_subscription_subscribed_idx (subscribed)
302 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
303
304 create table invitation (
305      code varchar(32) not null primary key comment 'random code for an invitation',
306      user_id int not null comment 'who sent the invitation' references user (id),
307      address varchar(255) not null comment 'invitation sent to',
308      address_type varchar(8) not null comment 'address type ("email", "jabber", "sms")',
309      created datetime not null comment 'date this record was created',
310
311      index invitation_address_idx (address, address_type),
312      index invitation_user_id_idx (user_id)
313 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
314
315 create table message (
316
317     id integer auto_increment primary key comment 'unique identifier',
318     uri varchar(255) unique key comment 'universally unique identifier',
319     from_profile integer not null comment 'who the message is from' references profile (id),
320     to_profile integer not null comment 'who the message is to' references profile (id),
321     content varchar(140) comment 'message content',
322     rendered text comment 'HTML version of the content',
323     url varchar(255) comment 'URL of any attachment (image, video, bookmark, whatever)',
324     created datetime not null comment 'date this record was created',
325     modified timestamp comment 'date this record was modified',
326     source varchar(32) comment 'source of comment, like "web", "im", or "clientname"',
327     
328     index message_from_idx (from_profile),
329     index message_to_idx (to_profile),
330     index message_created_idx (created)
331 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;