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