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