]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - db/laconica_pg.sql
PostgreSQL - added new emailnotifyattn field to user table, to match MySQL version
[quix0rs-gnu-social.git] / db / laconica_pg.sql
1 /* local and remote users have profiles */\r
2 \r
3 create table profile (\r
4     id serial primary key /* comment 'unique identifier' */,\r
5     nickname varchar(64) not null /* comment 'nickname or username' */,\r
6     fullname varchar(255) /* comment 'display name' */,\r
7     profileurl varchar(255) /* comment 'URL, cached so we dont regenerate' */,\r
8     homepage varchar(255) /* comment 'identifying URL' */,\r
9     bio varchar(140) /* comment 'descriptive biography' */,\r
10     location varchar(255) /* comment 'physical location' */,\r
11     created timestamp not null /* comment 'date this record was created' */,\r
12     modified timestamp /* comment 'date this record was modified' */,\r
13 \r
14     textsearch tsvector\r
15 );\r
16 create index profile_nickname_idx on profile using btree(nickname);\r
17 \r
18 create table avatar (\r
19     profile_id integer not null /* comment 'foreign key to profile table' */ references profile (id) ,\r
20     original integer default 0 /* comment 'uploaded by user or generated?' */,\r
21     width integer not null /* comment 'image width' */,\r
22     height integer not null /* comment 'image height' */,\r
23     mediatype varchar(32) not null /* comment 'file type' */,\r
24     filename varchar(255) null /* comment 'local filename, if local' */,\r
25     url varchar(255) unique /* comment 'avatar location' */,\r
26     created timestamp not null /* comment 'date this record was created' */,\r
27     modified timestamp /* comment 'date this record was modified' */,\r
28 \r
29     primary key(profile_id, width, height)\r
30 );\r
31 create index avatar_profile_id_idx on avatar using btree(profile_id);\r
32 \r
33 create table sms_carrier (\r
34     id serial primary key /* comment 'primary key for SMS carrier' */,\r
35     name varchar(64) unique /* comment 'name of the carrier' */,\r
36     email_pattern varchar(255) not null /* comment 'sprintf pattern for making an email address from a phone number' */,\r
37     created timestamp not null /* comment 'date this record was created' */,\r
38     modified timestamp /* comment 'date this record was modified ' */\r
39 );\r
40 \r
41 /* local users */\r
42 \r
43 create table "user" (\r
44     id integer primary key /* comment 'foreign key to profile table' */ references profile (id) ,\r
45     nickname varchar(64) unique /* comment 'nickname or username, duped in profile' */,\r
46     password varchar(255) /* comment 'salted password, can be null for OpenID users' */,\r
47     email varchar(255) unique /* comment 'email address for password recovery etc.' */,\r
48     incomingemail varchar(255) unique /* comment 'email address for post-by-email' */,\r
49     emailnotifysub integer default 1 /* comment 'Notify by email of subscriptions' */,\r
50     emailnotifyfav integer default 1 /* comment 'Notify by email of favorites' */,\r
51     emailnotifynudge integer default 1 /* comment 'Notify by email of nudges' */,\r
52     emailnotifymsg integer default 1 /* comment 'Notify by email of direct messages' */,\r
53     emailnotifyattn integer default 1 /* command 'Notify by email of @-replies' */, \r
54     emailmicroid integer default 1 /* comment 'whether to publish email microid' */,\r
55     language varchar(50) /* comment 'preferred language' */,\r
56     timezone varchar(50) /* comment 'timezone' */,\r
57     emailpost integer default 1 /* comment 'Post by email' */,\r
58     jabber varchar(255) unique /* comment 'jabber ID for notices' */,\r
59     jabbernotify integer default 0 /* comment 'whether to send notices to jabber' */,\r
60     jabberreplies integer default 0 /* comment 'whether to send notices to jabber on replies' */,\r
61     jabbermicroid integer default 1 /* comment 'whether to publish xmpp microid' */,\r
62     updatefrompresence integer default 0 /* comment 'whether to record updates from Jabber presence notices' */,\r
63     sms varchar(64) unique /* comment 'sms phone number' */,\r
64     carrier integer /* comment 'foreign key to sms_carrier' */ references sms_carrier (id) ,\r
65     smsnotify integer default 0 /* comment 'whether to send notices to SMS' */,\r
66     smsreplies integer default 0 /* comment 'whether to send notices to SMS on replies' */,\r
67     smsemail varchar(255) /* comment 'built from sms and carrier' */,\r
68     uri varchar(255) unique /* comment 'universally unique identifier, usually a tag URI' */,\r
69     autosubscribe integer default 0 /* comment 'automatically subscribe to users who subscribe to us' */,\r
70     urlshorteningservice varchar(50) default 'ur1.ca' /* comment 'service to use for auto-shortening URLs' */,\r
71     inboxed integer default 0 /* comment 'has an inbox been created for this user?' */, \r
72     created timestamp not null /* comment 'date this record was created' */,\r
73     modified timestamp /* comment 'date this record was modified' */\r
74 \r
75 );\r
76 create index user_smsemail_idx on "user" using btree(smsemail);\r
77 \r
78 /* remote people */\r
79 \r
80 create table remote_profile (\r
81     id integer primary key /* comment 'foreign key to profile table' */ references profile (id) ,\r
82     uri varchar(255) unique /* comment 'universally unique identifier, usually a tag URI' */,\r
83     postnoticeurl varchar(255) /* comment 'URL we use for posting notices' */,\r
84     updateprofileurl varchar(255) /* comment 'URL we use for updates to this profile' */,\r
85     created timestamp not null /* comment 'date this record was created' */,\r
86     modified timestamp /* comment 'date this record was modified' */\r
87 );\r
88 \r
89 create table subscription (\r
90     subscriber integer not null /* comment 'profile listening' */,\r
91     subscribed integer not null /* comment 'profile being listened to' */,\r
92     jabber integer default 1 /* comment 'deliver jabber messages' */,\r
93     sms integer default 1 /* comment 'deliver sms messages' */,\r
94     token varchar(255) /* comment 'authorization token' */,\r
95     secret varchar(255) /* comment 'token secret' */,\r
96     created timestamp not null /* comment 'date this record was created' */,\r
97     modified timestamp /* comment 'date this record was modified' */,\r
98 \r
99     primary key (subscriber, subscribed)\r
100 );\r
101 create index subscription_subscriber_idx on subscription using btree(subscriber);\r
102 create index subscription_subscribed_idx on subscription using btree(subscribed);\r
103 \r
104 create table notice (\r
105 \r
106     id serial primary key /* comment 'unique identifier' */,\r
107     profile_id integer not null /* comment 'who made the update' */ references profile (id) ,\r
108     uri varchar(255) unique /* comment 'universally unique identifier, usually a tag URI' */,\r
109     content varchar(140) /* comment 'update content' */,\r
110     rendered text /* comment 'HTML version of the content' */,\r
111     url varchar(255) /* comment 'URL of any attachment (image, video, bookmark, whatever)' */,\r
112     created timestamp not null /* comment 'date this record was created' */,\r
113     modified timestamp /* comment 'date this record was modified' */,\r
114     reply_to integer /* comment 'notice replied to (usually a guess)' */ references notice (id) ,\r
115     is_local integer default 0 /* comment 'notice was generated by a user' */,\r
116     source varchar(32) /* comment 'source of comment, like "web", "im", or "clientname"' */\r
117 \r
118 /*    FULLTEXT(content) */\r
119 );\r
120 create index notice_profile_id_idx on notice using btree(profile_id);\r
121 create index notice_created_idx on notice using btree(created);\r
122 \r
123 create table notice_source (\r
124      code varchar(32) primary key not null /* comment 'source code' */,\r
125      name varchar(255) not null /* comment 'name of the source' */,\r
126      url varchar(255) not null /* comment 'url to link to' */,\r
127      created timestamp not null /* comment 'date this record was created' */,\r
128      modified timestamp /* comment 'date this record was modified' */\r
129 );\r
130 \r
131 create table reply (\r
132 \r
133     notice_id integer not null /* comment 'notice that is the reply' */ references notice (id) ,\r
134     profile_id integer not null /* comment 'profile replied to' */ references profile (id) ,\r
135     modified timestamp not null default 'now' /* comment 'date this record was modified' */,\r
136     replied_id integer /* comment 'notice replied to (not used, see notice.reply_to)' */,\r
137 \r
138     primary key (notice_id, profile_id)\r
139 \r
140 );\r
141 create index reply_notice_id_idx on reply using btree(notice_id);\r
142 create index reply_profile_id_idx on reply using btree(profile_id);\r
143 create index reply_replied_id_idx on reply using btree(replied_id);\r
144 \r
145 create table fave (\r
146 \r
147     notice_id integer not null /* comment 'notice that is the favorite' */ references notice (id),\r
148     user_id integer not null /* comment 'user who likes this notice' */ references "user" (id) ,\r
149     modified timestamp not null /* comment 'date this record was modified' */,\r
150     primary key (notice_id, user_id)\r
151 \r
152 );\r
153 create index fave_notice_id_idx on fave using btree(notice_id);\r
154 create index fave_user_id_idx on fave using btree(user_id);\r
155 create index fave_modified_idx on fave using btree(modified);\r
156 \r
157 /* tables for OAuth */\r
158 \r
159 create table consumer (\r
160     consumer_key varchar(255) primary key /* comment 'unique identifier, root URL' */,\r
161     seed char(32) not null /* comment 'seed for new tokens by this consumer' */,\r
162 \r
163     created timestamp not null /* comment 'date this record was created' */,\r
164     modified timestamp /* comment 'date this record was modified' */\r
165 );\r
166 \r
167 create table token (\r
168     consumer_key varchar(255) not null /* comment 'unique identifier, root URL' */ references consumer (consumer_key),\r
169     tok char(32) not null /* comment 'identifying value' */,\r
170     secret char(32) not null /* comment 'secret value' */,\r
171     type integer not null default 0 /* comment 'request or access' */,\r
172     state integer default 0 /* comment 'for requests; 0 = initial, 1 = authorized, 2 = used' */,\r
173 \r
174     created timestamp not null /* comment 'date this record was created' */,\r
175     modified timestamp /* comment 'date this record was modified' */,\r
176 \r
177     primary key (consumer_key, tok)\r
178 );\r
179 \r
180 create table nonce (\r
181     consumer_key varchar(255) not null /* comment 'unique identifier, root URL' */,\r
182     tok char(32) not null /* comment 'identifying value' */,\r
183     nonce char(32) not null /* comment 'nonce' */,\r
184     ts timestamp not null /* comment 'timestamp sent' */,\r
185 \r
186     created timestamp not null /* comment 'date this record was created' */,\r
187     modified timestamp /* comment 'date this record was modified' */,\r
188 \r
189     primary key (consumer_key, tok, nonce),\r
190     foreign key (consumer_key, tok) references token (consumer_key, tok)\r
191 );\r
192 \r
193 /* One-to-many relationship of user to openid_url */\r
194 \r
195 create table user_openid (\r
196     canonical varchar(255) primary key /* comment 'Canonical true URL' */,\r
197     display varchar(255) not null unique /* comment 'URL for viewing, may be different from canonical' */,\r
198     user_id integer not null /* comment 'user owning this URL' */ references "user" (id) ,\r
199     created timestamp not null /* comment 'date this record was created' */,\r
200     modified timestamp /* comment 'date this record was modified' */\r
201 \r
202 );\r
203 create index user_openid_user_id_idx on user_openid using btree(user_id);\r
204 \r
205 /* These are used by JanRain OpenID library */\r
206 \r
207 create table oid_associations (\r
208     server_url varchar(2047),\r
209     handle varchar(255),\r
210     secret bytea,\r
211     issued integer,\r
212     lifetime integer,\r
213     assoc_type varchar(64),\r
214     primary key (server_url, handle)\r
215 );\r
216 \r
217 create table oid_nonces (\r
218     server_url varchar(2047),\r
219     "timestamp" integer,\r
220     salt character(40),\r
221     unique (server_url, "timestamp", salt)\r
222 );\r
223 \r
224 create table confirm_address (\r
225     code varchar(32) not null primary key /* comment 'good random code' */,\r
226     user_id integer not null /* comment 'user who requested confirmation' */ references "user" (id),\r
227     address varchar(255) not null /* comment 'address (email, Jabber, SMS, etc.)' */,\r
228     address_extra varchar(255) not null default '' /* comment 'carrier ID, for SMS' */,\r
229     address_type varchar(8) not null /* comment 'address type ("email", "jabber", "sms")' */,\r
230     claimed timestamp /* comment 'date this was claimed for queueing' */,\r
231     sent timestamp /* comment 'date this was sent for queueing' */,\r
232     modified timestamp /* comment 'date this record was modified' */\r
233 );\r
234 \r
235 create table remember_me (\r
236     code varchar(32) not null primary key /* comment 'good random code' */,\r
237     user_id integer not null /* comment 'user who is logged in' */ references "user" (id),\r
238     modified timestamp /* comment 'date this record was modified' */\r
239 );\r
240 \r
241 create table queue_item (\r
242 \r
243     notice_id integer not null /* comment 'notice queued' */ references notice (id) ,\r
244     transport varchar(8) not null /* comment 'queue for what? "email", "jabber", "sms", "irc", ...' */,\r
245     created timestamp not null /* comment 'date this record was created' */,\r
246     claimed timestamp /* comment 'date this item was claimed' */,\r
247 \r
248     primary key (notice_id, transport)\r
249 \r
250 );\r
251 create index queue_item_created_idx on queue_item using btree(created);\r
252 \r
253 /* Hash tags */\r
254 create table notice_tag (\r
255     tag varchar( 64 ) not null /* comment 'hash tag associated with this notice' */,\r
256     notice_id integer not null /* comment 'notice tagged' */ references notice (id) ,\r
257     created timestamp not null /* comment 'date this record was created' */,\r
258 \r
259     primary key (tag, notice_id)\r
260 );\r
261 create index notice_tag_created_idx on notice_tag using btree(created);\r
262 \r
263 /* Synching with foreign services */\r
264 \r
265 create table foreign_service (\r
266      id int not null primary key /* comment 'numeric key for service' */,\r
267      name varchar(32) not null unique /* comment 'name of the service' */,\r
268      description varchar(255) /* comment 'description' */,\r
269      created timestamp not null /* comment 'date this record was created' */,\r
270      modified timestamp /* comment 'date this record was modified' */\r
271 );\r
272 \r
273 create table foreign_user (\r
274      id int not null unique /* comment 'unique numeric key on foreign service' */,\r
275      service int not null /* comment 'foreign key to service' */ references foreign_service(id) ,\r
276      uri varchar(255) not null unique /* comment 'identifying URI' */,\r
277      nickname varchar(255) /* comment 'nickname on foreign service' */,\r
278      created timestamp not null /* comment 'date this record was created' */,\r
279      modified timestamp /* comment 'date this record was modified' */,\r
280      \r
281      primary key (id, service)\r
282 );\r
283 \r
284 create table foreign_link (\r
285      user_id int /* comment 'link to user on this system, if exists' */ references "user" (id),\r
286      foreign_id int /* comment 'link' */ references foreign_user (id),\r
287      service int not null /* comment 'foreign key to service' */ references foreign_service (id),\r
288      credentials varchar(255) /* comment 'authc credentials, typically a password' */,\r
289      noticesync int not null default 1 /* comment 'notice synchronisation, bit 1 = sync outgoing, bit 2 = sync incoming, bit 3 = filter local replies' */,\r
290      friendsync int not null default 2 /* comment 'friend synchronisation, bit 1 = sync outgoing, bit 2 = sync incoming */, \r
291      profilesync int not null default 1 /* comment 'profile synchronization, bit 1 = sync outgoing, bit 2 = sync incoming' */,\r
292      created timestamp not null /* comment 'date this record was created' */,\r
293      modified timestamp not null /* comment 'date this record was modified' */,\r
294 \r
295      primary key (user_id,foreign_id,service)\r
296 );\r
297 create index foreign_user_user_id_idx on foreign_link using btree(user_id);\r
298 \r
299 create table foreign_subscription (\r
300      service int not null /* comment 'service where relationship happens' */ references foreign_service(id) ,\r
301      subscriber int not null /* comment 'subscriber on foreign service' */ ,\r
302      subscribed int not null /* comment 'subscribed user' */ ,\r
303      created timestamp not null /* comment 'date this record was created' */,\r
304      \r
305      primary key (service, subscriber, subscribed)\r
306 );\r
307 create index foreign_subscription_subscriber_idx on foreign_subscription using btree(subscriber);\r
308 create index foreign_subscription_subscribed_idx on foreign_subscription using btree(subscribed);\r
309 \r
310 create table invitation (\r
311      code varchar(32) not null primary key /* comment 'random code for an invitation' */,\r
312      user_id int not null /* comment 'who sent the invitation' */ references "user" (id),\r
313      address varchar(255) not null /* comment 'invitation sent to' */,\r
314      address_type varchar(8) not null /* comment 'address type ("email", "jabber", "sms") '*/,\r
315      created timestamp not null /* comment 'date this record was created' */\r
316 \r
317 );\r
318 create index invitation_address_idx on invitation using btree(address,address_type);\r
319 create index invitation_user_id_idx on invitation using btree(user_id);\r
320 \r
321 create table message (\r
322 \r
323     id serial primary key /* comment 'unique identifier' */,\r
324     uri varchar(255) unique /* comment 'universally unique identifier' */,\r
325     from_profile integer not null /* comment 'who the message is from' */ references profile (id),\r
326     to_profile integer not null /* comment 'who the message is to' */ references profile (id),\r
327     content varchar(140) /* comment 'message content' */,\r
328     rendered text /* comment 'HTML version of the content' */,\r
329     url varchar(255) /* comment 'URL of any attachment (image, video, bookmark, whatever)' */,\r
330     created timestamp not null /* comment 'date this record was created' */,\r
331     modified timestamp /* comment 'date this record was modified' */,\r
332     source varchar(32) /* comment 'source of comment, like "web", "im", or "clientname"' */\r
333     \r
334 );\r
335 create index message_from_idx on message using btree(from_profile);\r
336 create index message_to_idx on message using btree(to_profile);\r
337 create index message_created_idx on message using btree(created);\r
338 \r
339 create table notice_inbox (\r
340 \r
341     user_id integer not null /* comment 'user receiving the message' */ references "user" (id),\r
342     notice_id integer not null /* comment 'notice received' */ references notice (id),\r
343     created timestamp not null /* comment 'date the notice was created' */,\r
344     source integer default 1 /* comment 'reason it is in the inbox; 1=subscription' */,\r
345 \r
346     primary key (user_id, notice_id)\r
347 );\r
348 create index notice_inbox_notice_id_idx on notice_inbox using btree(notice_id);\r
349 \r
350 create table profile_tag (\r
351    tagger integer not null /* comment 'user making the tag' */ references "user" (id),\r
352    tagged integer not null /* comment 'profile tagged' */ references profile (id),\r
353    tag varchar(64) not null /* comment 'hash tag associated with this notice' */,\r
354    modified timestamp /* comment 'date the tag was added' */,\r
355 \r
356    primary key (tagger, tagged, tag)\r
357 );\r
358 create index profile_tag_modified_idx on profile_tag using btree(modified);\r
359 create index profile_tag_tagger_tag_idx on profile_tag using btree(tagger,tag);\r
360 \r
361 create table profile_block (\r
362 \r
363    blocker integer not null /* comment 'user making the block' */ references "user" (id),\r
364    blocked integer not null /* comment 'profile that is blocked' */ references profile (id),\r
365    modified timestamp /* comment 'date of blocking' */,\r
366 \r
367    primary key (blocker, blocked)\r
368 \r
369 );\r
370 \r
371 create table user_group (\r
372 \r
373     id serial primary key /* comment 'unique identifier' */,\r
374 \r
375     nickname varchar(64) unique /* comment 'nickname for addressing' */,\r
376     fullname varchar(255) /* comment 'display name' */,\r
377     homepage varchar(255) /* comment 'URL, cached so we dont regenerate' */,\r
378     description varchar(140) /* comment 'descriptive biography' */,\r
379     location varchar(255) /* comment 'related physical location, if any' */,\r
380 \r
381     original_logo varchar(255) /* comment 'original size logo' */,\r
382     homepage_logo varchar(255) /* comment 'homepage (profile) size logo' */,\r
383     stream_logo varchar(255) /* comment 'stream-sized logo' */,\r
384     mini_logo varchar(255) /* comment 'mini logo' */,\r
385 \r
386     created timestamp not null /* comment 'date this record was created' */,\r
387     modified timestamp /* comment 'date this record was modified' */\r
388 \r
389 );\r
390 create index user_group_nickname_idx on user_group using btree(nickname);\r
391 \r
392 create table group_member (\r
393 \r
394     group_id integer not null /* comment 'foreign key to user_group' */ references user_group (id),\r
395     profile_id integer not null /* comment 'foreign key to profile table' */ references profile (id),\r
396     is_admin integer default 0 /* comment 'is this user an admin?' */,\r
397 \r
398     created timestamp not null /* comment 'date this record was created' */,\r
399     modified timestamp /* comment 'date this record was modified' */,\r
400 \r
401     primary key (group_id, profile_id)\r
402 );\r
403 \r
404 create table related_group (\r
405 \r
406     group_id integer not null /* comment 'foreign key to user_group' */ references user_group (id) ,\r
407     related_group_id integer not null /* comment 'foreign key to user_group' */ references user_group (id),\r
408 \r
409     created timestamp not null /* comment 'date this record was created' */,\r
410 \r
411     primary key (group_id, related_group_id)\r
412 \r
413 );\r
414 \r
415 create table group_inbox (\r
416     group_id integer not null /* comment 'group receiving the message' references user_group (id) */,\r
417     notice_id integer not null /* comment 'notice received' references notice (id) */,\r
418     created timestamp not null /* comment 'date the notice was created' */,\r
419 \r
420     primary key (group_id, notice_id)\r
421 );\r
422 create index group_inbox_created_idx on group_inbox using btree(created);\r
423 \r
424 /* Textsearch stuff */\r
425 \r
426 create index textsearch_idx on profile using gist(textsearch);\r
427 create index noticecontent_idx on notice using gist(to_tsvector('english',content));\r
428 create trigger textsearchupdate before insert or update on profile for each row\r
429 execute procedure tsvector_update_trigger(textsearch, 'pg_catalog.english', nickname, fullname, location, bio, homepage);\r
430 \r