]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - db/laconica_pg.sql
315112b9350accd1a28da8d8db29001208eaaf5c
[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 /*    FULLTEXT(nickname, fullname, location, bio, homepage) */\r
15 );\r
16 create index profile_nickname_idx on profile using btree(nickname);\r
17 \r
18 \r
19 \r
20 create table avatar (\r
21     profile_id integer not null /* comment 'foreign key to profile table' */ references profile (id) ,\r
22     original integer default 0 /* comment 'uploaded by user or generated?' */,\r
23     width integer not null /* comment 'image width' */,\r
24     height integer not null /* comment 'image height' */,\r
25     mediatype varchar(32) not null /* comment 'file type' */,\r
26     filename varchar(255) null /* comment 'local filename, if local' */,\r
27     url varchar(255) unique /* comment 'avatar location' */,\r
28     created timestamp not null /* comment 'date this record was created' */,\r
29     modified timestamp /* comment 'date this record was modified' */,\r
30 \r
31     primary key(profile_id, width, height)\r
32 );\r
33 create index avatar_profile_id_idx on avatar using btree(profile_id);\r
34 \r
35 create table sms_carrier (\r
36     id serial primary key /* comment 'primary key for SMS carrier' */,\r
37     name varchar(64) unique /* comment 'name of the carrier' */,\r
38     email_pattern varchar(255) not null /* comment 'sprintf pattern for making an email address from a phone number' */,\r
39     created timestamp not null /* comment 'date this record was created' */,\r
40     modified timestamp /* comment 'date this record was modified ' */\r
41 );\r
42 \r
43 /* local users */\r
44 \r
45 create table "user" (\r
46     id integer primary key /* comment 'foreign key to profile table' */ references profile (id) ,\r
47     nickname varchar(64) unique /* comment 'nickname or username, duped in profile' */,\r
48     password varchar(255) /* comment 'salted password, can be null for OpenID users' */,\r
49     email varchar(255) unique /* comment 'email address for password recovery etc.' */,\r
50     incomingemail varchar(255) unique /* comment 'email address for post-by-email' */,\r
51     emailnotifysub integer default 1 /* comment 'Notify by email of subscriptions' */,\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     created timestamp not null /* comment 'date this record was created' */,\r
69     modified timestamp /* comment 'date this record was modified' */\r
70 \r
71 );\r
72 create index user_smsemail_idx on "user" using btree(smsemail);\r
73 \r
74 /* remote people */\r
75 \r
76 create table remote_profile (\r
77     id integer primary key /* comment 'foreign key to profile table' */ references profile (id) ,\r
78     uri varchar(255) unique /* comment 'universally unique identifier, usually a tag URI' */,\r
79     postnoticeurl varchar(255) /* comment 'URL we use for posting notices' */,\r
80     updateprofileurl varchar(255) /* comment 'URL we use for updates to this profile' */,\r
81     created timestamp not null /* comment 'date this record was created' */,\r
82     modified timestamp /* comment 'date this record was modified' */\r
83 );\r
84 \r
85 create table subscription (\r
86     subscriber integer not null /* comment 'profile listening' */,\r
87     subscribed integer not null /* comment 'profile being listened to' */,\r
88     token varchar(255) /* comment 'authorization token' */,\r
89     secret varchar(255) /* comment 'token secret' */,\r
90     created timestamp not null /* comment 'date this record was created' */,\r
91     modified timestamp /* comment 'date this record was modified' */,\r
92 \r
93     primary key (subscriber, subscribed)\r
94 );\r
95 create index subscription_subscriber_idx on subscription using btree(subscriber);\r
96 create index subscription_subscribed_idx on subscription using btree(subscribed);\r
97 \r
98 create table notice (\r
99 \r
100     id serial primary key /* comment 'unique identifier' */,\r
101     profile_id integer not null /* comment 'who made the update' */ references profile (id) ,\r
102     uri varchar(255) unique /* comment 'universally unique identifier, usually a tag URI' */,\r
103     content varchar(140) /* comment 'update content' */,\r
104     rendered text /* comment 'HTML version of the content' */,\r
105     url varchar(255) /* comment 'URL of any attachment (image, video, bookmark, whatever)' */,\r
106     created timestamp not null /* comment 'date this record was created' */,\r
107     modified timestamp /* comment 'date this record was modified' */,\r
108     reply_to integer /* comment 'notice replied to (usually a guess)' */ references notice (id) ,\r
109     is_local integer default 0 /* comment 'notice was generated by a user' */,\r
110     source varchar(32) /* comment 'source of comment, like "web", "im", or "clientname"' */\r
111 \r
112 /*    FULLTEXT(content) */\r
113 );\r
114 create index notice_profile_id_idx on notice using btree(profile_id);\r
115 create index notice_created_idx on notice using btree(created);\r
116 \r
117 create table notice_source (\r
118      code varchar(32) primary key not null /* comment 'source code' */,\r
119      name varchar(255) not null /* comment 'name of the source' */,\r
120      url varchar(255) not null /* comment 'url to link to' */,\r
121      created timestamp not null /* comment 'date this record was created' */,\r
122      modified timestamp /* comment 'date this record was modified' */\r
123 );\r
124 \r
125 create table reply (\r
126 \r
127     notice_id integer not null /* comment 'notice that is the reply' */ references notice (id) ,\r
128     profile_id integer not null /* comment 'profile replied to' */ references profile (id) ,\r
129     modified timestamp not null default 'now' /* comment 'date this record was modified' */,\r
130     replied_id integer /* comment 'notice replied to (not used, see notice.reply_to)' */,\r
131 \r
132     primary key (notice_id, profile_id)\r
133 \r
134 );\r
135 create index reply_notice_id_idx on reply using btree(notice_id);\r
136 create index reply_profile_id_idx on reply using btree(profile_id);\r
137 create index reply_replied_id_idx on reply using btree(replied_id);\r
138 \r
139 create table fave (\r
140 \r
141     notice_id integer not null /* comment 'notice that is the favorite' */ references notice (id),\r
142     user_id integer not null /* comment 'user who likes this notice' */ references "user" (id) ,\r
143     modified timestamp not null /* comment 'date this record was modified' */,\r
144 \r
145     primary key (notice_id, user_id)\r
146 \r
147 );\r
148 create index fave_notice_id_idx on fave using btree(notice_id);\r
149 create index fave_user_id_idx on fave using btree(user_id);\r
150 create index fave_modified_idx on fave using btree(modified);\r
151 \r
152 /* tables for OAuth */\r
153 \r
154 create table consumer (\r
155     consumer_key varchar(255) primary key /* comment 'unique identifier, root URL' */,\r
156     seed char(32) not null /* comment 'seed for new tokens by this consumer' */,\r
157 \r
158     created timestamp not null /* comment 'date this record was created' */,\r
159     modified timestamp /* comment 'date this record was modified' */\r
160 );\r
161 \r
162 create table token (\r
163     consumer_key varchar(255) not null /* comment 'unique identifier, root URL' */ references consumer (consumer_key),\r
164     tok char(32) not null /* comment 'identifying value' */,\r
165     secret char(32) not null /* comment 'secret value' */,\r
166     type integer not null default 0 /* comment 'request or access' */,\r
167     state integer default 0 /* comment 'for requests; 0 = initial, 1 = authorized, 2 = used' */,\r
168 \r
169     created timestamp not null /* comment 'date this record was created' */,\r
170     modified timestamp /* comment 'date this record was modified' */,\r
171 \r
172     primary key (consumer_key, tok)\r
173 );\r
174 \r
175 create table nonce (\r
176     consumer_key varchar(255) not null /* comment 'unique identifier, root URL' */,\r
177     tok char(32) not null /* comment 'identifying value' */,\r
178     nonce char(32) not null /* comment 'nonce' */,\r
179     ts timestamp not null /* comment 'timestamp sent' */,\r
180 \r
181     created timestamp not null /* comment 'date this record was created' */,\r
182     modified timestamp /* comment 'date this record was modified' */,\r
183 \r
184     primary key (consumer_key, tok, nonce),\r
185     foreign key (consumer_key, tok) references token (consumer_key, tok)\r
186 );\r
187 \r
188 /* One-to-many relationship of user to openid_url */\r
189 \r
190 create table user_openid (\r
191     canonical varchar(255) primary key /* comment 'Canonical true URL' */,\r
192     display varchar(255) not null unique /* comment 'URL for viewing, may be different from canonical' */,\r
193     user_id integer not null /* comment 'user owning this URL' */ references "user" (id) ,\r
194     created timestamp not null /* comment 'date this record was created' */,\r
195     modified timestamp /* comment 'date this record was modified' */\r
196 \r
197 );\r
198 create index user_openid_user_id_idx on user_openid using btree(user_id);\r
199 \r
200 /* These are used by JanRain OpenID library */\r
201 \r
202 create table oid_associations (\r
203     server_url varchar(2047),\r
204     handle varchar(255),\r
205     secret bytea,\r
206     issued integer,\r
207     lifetime integer,\r
208     assoc_type varchar(64),\r
209     primary key (server_url, handle)\r
210 );\r
211 \r
212 create table oid_nonces (\r
213     server_url varchar(2047),\r
214     "timestamp" integer,\r
215     salt character(40),\r
216     unique (server_url, "timestamp", salt)\r
217 );\r
218 \r
219 create table confirm_address (\r
220     code varchar(32) not null primary key /* comment 'good random code' */,\r
221     user_id integer not null /* comment 'user who requested confirmation' */ references "user" (id),\r
222     address varchar(255) not null /* comment 'address (email, Jabber, SMS, etc.)' */,\r
223     address_extra varchar(255) not null /* comment 'carrier ID, for SMS' */,\r
224     address_type varchar(8) not null /* comment 'address type ("email", "jabber", "sms")' */,\r
225     claimed timestamp /* comment 'date this was claimed for queueing' */,\r
226     sent timestamp /* comment 'date this was sent for queueing' */,\r
227     modified timestamp /* comment 'date this record was modified' */\r
228 );\r
229 \r
230 create table remember_me (\r
231     code varchar(32) not null primary key /* comment 'good random code' */,\r
232     user_id integer not null /* comment 'user who is logged in' */ references "user" (id),\r
233     modified timestamp /* comment 'date this record was modified' */\r
234 );\r
235 \r
236 create table queue_item (\r
237 \r
238     notice_id integer not null /* comment 'notice queued' */ references notice (id) ,\r
239     transport varchar(8) not null /* comment 'queue for what? "email", "jabber", "sms", "irc", ...' */,\r
240     created timestamp not null /* comment 'date this record was created' */,\r
241     claimed timestamp /* comment 'date this item was claimed' */,\r
242 \r
243     primary key (notice_id, transport)\r
244 \r
245 );\r
246 create index queue_item_created_idx on queue_item using btree(created);\r
247 \r
248 /* Hash tags */\r
249 create table notice_tag (\r
250     tag varchar( 64 ) not null /* comment 'hash tag associated with this notice' */,\r
251     notice_id integer not null /* comment 'notice tagged' */ references notice (id) ,\r
252     created timestamp not null /* comment 'date this record was created' */,\r
253 \r
254     primary key (tag, notice_id)\r
255 );\r
256 create index notice_tag_created_idx on notice_tag using btree(created);\r
257 \r
258 /* Synching with foreign services */\r
259 \r
260 create table foreign_service (\r
261      id int not null primary key /* comment 'numeric key for service' */,\r
262      name varchar(32) not null unique /* comment 'name of the service' */,\r
263      description varchar(255) /* comment 'description' */,\r
264      created timestamp not null /* comment 'date this record was created' */,\r
265      modified timestamp /* comment 'date this record was modified' */\r
266 );\r
267 \r
268 create table foreign_user (\r
269      id int not null /* comment 'unique numeric key on foreign service' */,\r
270      service int not null /* comment 'foreign key to service' */ references foreign_service(id) ,\r
271      uri varchar(255) not null unique /* comment 'identifying URI' */,\r
272      nickname varchar(255) /* comment 'nickname on foreign service' */,\r
273      user_id int /* comment 'link to user on this system, if exists' */ references "user" (id),  \r
274      credentials varchar(255) /* comment 'authc credentials, typically a password' */,\r
275      created timestamp not null /* comment 'date this record was created' */,\r
276      modified timestamp /* comment 'date this record was modified' */,\r
277      \r
278      primary key (id, service)\r
279 );\r
280 create index foreign_user_user_id_idx on foreign_user using btree(user_id);\r
281 \r
282 create table foreign_subscription (\r
283      service int not null /* comment 'service where relationship happens' */ references foreign_service(id) ,\r
284      subscriber int not null /* comment 'subscriber on foreign service' */ ,\r
285      subscribed int not null /* comment 'subscribed user' */ ,\r
286      created timestamp not null /* comment 'date this record was created' */,\r
287      \r
288      primary key (service, subscriber, subscribed)\r
289 );\r
290 create index foreign_subscription_subscriber_idx on foreign_subscription using btree(subscriber);\r
291 create index foreign_subscription_subscribed_idx on foreign_subscription using btree(subscribed);\r