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