Mercurial Hosting > nabble
comparison src/nabble/model/DbSiteUpdater.java @ 0:7ecd1a4ef557
add content
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 21 Mar 2019 19:15:52 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:7ecd1a4ef557 |
---|---|
1 | |
2 package nabble.model; | |
3 | |
4 import fschmidt.db.DbDatabase; | |
5 import org.slf4j.Logger; | |
6 import org.slf4j.LoggerFactory; | |
7 | |
8 import java.sql.SQLException; | |
9 import java.util.HashMap; | |
10 import java.util.Map; | |
11 | |
12 | |
13 final class DbSiteUpdater { | |
14 private static final Logger logger = LoggerFactory.getLogger(DbSiteUpdater.class); | |
15 | |
16 // don't forget to update site.schema | |
17 static final int version = 167; | |
18 | |
19 private static class Result { | |
20 private static final long wait = 2000L; // 2 seconds | |
21 private final long waitUntil = System.currentTimeMillis() + wait; | |
22 private DbSiteUpdater updater; | |
23 private SQLException sqlException = null; | |
24 private RuntimeException runtimeException = null; | |
25 private Error error = null; | |
26 private final String user; | |
27 | |
28 private Result(DbDatabase db,String user) { | |
29 updater = new DbSiteUpdater(db,this,user); | |
30 this.user = user; | |
31 updater.start(); | |
32 } | |
33 | |
34 private synchronized void check() throws SQLException { | |
35 if( !isDone() ) { | |
36 long now = System.currentTimeMillis(); | |
37 if( now < waitUntil ) { | |
38 try { | |
39 wait( waitUntil - now ); | |
40 } catch(InterruptedException e) { | |
41 throw new RuntimeException(e); | |
42 } | |
43 } | |
44 if( !isDone() ) | |
45 throw new UpdatingException(user); | |
46 } | |
47 if( sqlException != null ) | |
48 throw sqlException; | |
49 if( runtimeException != null ) | |
50 throw runtimeException; | |
51 if( error != null ) | |
52 throw error; | |
53 } | |
54 | |
55 synchronized boolean isDone() { | |
56 return updater==null; | |
57 } | |
58 | |
59 synchronized void done(Throwable e) { | |
60 updater = null; | |
61 if( e != null ) { | |
62 if( e instanceof SQLException ) { | |
63 sqlException = (SQLException)e; | |
64 } else if( e instanceof RuntimeException ) { | |
65 runtimeException = (RuntimeException)e; | |
66 } else if( e instanceof Error ) { | |
67 error = (Error)e; | |
68 } else { | |
69 runtimeException = new RuntimeException("invalid exception type",e); | |
70 } | |
71 } | |
72 notifyAll(); | |
73 } | |
74 } | |
75 | |
76 private static final Map<String,Result> userResults = new HashMap<String,Result>(); | |
77 private static final Object lock = new Object(); | |
78 | |
79 static void update(String user,DbDatabase db) throws SQLException { | |
80 if( user.equals("global") ) | |
81 return; // done from command line | |
82 getResult(user,db).check(); | |
83 } | |
84 | |
85 private static Result getResult(String user,DbDatabase db) throws SQLException { | |
86 synchronized(lock) { | |
87 Result result = userResults.get(user); | |
88 if( result == null ) { | |
89 result = new Result(db,user); | |
90 userResults.put(user,result); | |
91 } | |
92 return result; | |
93 } | |
94 } | |
95 | |
96 // for shell | |
97 public static void clearResult(long siteId) { | |
98 String user = SiteKey.getInstance(siteId).schema(); | |
99 synchronized(lock) { | |
100 userResults.remove(user); | |
101 } | |
102 } | |
103 | |
104 | |
105 | |
106 | |
107 private final Result result; | |
108 private final DbUpdater up; | |
109 | |
110 private DbSiteUpdater(DbDatabase db,Result result,String schema) { | |
111 this.up = new DbUpdater(db,schema); | |
112 this.result = result; | |
113 } | |
114 | |
115 private void start() { | |
116 try { // needed for site creation because version is only up to date in current transaction | |
117 if( up.dbVersion() == version ) { | |
118 result.done(null); | |
119 return; | |
120 } | |
121 } catch(RuntimeException e) { | |
122 result.done(e); | |
123 return; | |
124 } catch(Error e) { | |
125 result.done(e); | |
126 return; | |
127 } | |
128 Executors.executeNow(new Runnable(){public void run(){ | |
129 try { | |
130 go(); | |
131 result.done(null); | |
132 } catch(SQLException e) { | |
133 result.done(e); | |
134 } catch(RuntimeException e) { | |
135 result.done(e); | |
136 } catch(Error e) { | |
137 result.done(e); | |
138 } finally { | |
139 if( !result.isDone() ) | |
140 logger.error("result isn't done"); | |
141 } | |
142 }}); | |
143 } | |
144 | |
145 void go() throws SQLException { | |
146 try { | |
147 update(); | |
148 if( up.databaseVersion() != version ) | |
149 throw new RuntimeException(); | |
150 } finally { | |
151 up.close(); | |
152 } | |
153 } | |
154 | |
155 @Override public String toString() { | |
156 return "DbSiteUpdater-" + up.schema; | |
157 } | |
158 | |
159 private void execCatching(String sql,String exStr) throws SQLException { | |
160 up.begin(); | |
161 try { | |
162 up.exec(sql); | |
163 } catch(SQLException e) { | |
164 if( !e.getMessage().contains(exStr) ) | |
165 throw e; | |
166 logger.info(e.toString()); | |
167 up.exec("rollback"); | |
168 } | |
169 up.commit(); | |
170 } | |
171 | |
172 void update() throws SQLException { | |
173 switch( up.dbVersion() ) { | |
174 case 0: | |
175 up.execStep( | |
176 "\r\n create index embed_key_site_idx on embed_key(site_id)\r\n " | |
177 ); | |
178 case 1: | |
179 up.execStep( | |
180 "\r\n create index file_avatar_site_idx on file_avatar(site_id)\r\n " | |
181 ); | |
182 case 2: | |
183 up.execStep( | |
184 "\r\n create index file_node_site_idx on file_node(site_id)\r\n " | |
185 ); | |
186 case 3: | |
187 up.execStep( | |
188 "\r\n create index file_temp_site_idx on file_temp(site_id)\r\n " | |
189 ); | |
190 case 4: | |
191 up.execStep( | |
192 "\r\n create index mailing_list_site_idx on mailing_list(site_id)\r\n " | |
193 ); | |
194 case 5: | |
195 up.execStep( | |
196 "\r\n create index node_msg_site_idx on node_msg(site_id)\r\n " | |
197 ); | |
198 case 6: | |
199 up.execStep( | |
200 "\r\n create index node_property_site_idx on node_property(site_id)\r\n " | |
201 ); | |
202 case 7: | |
203 up.execStep( | |
204 "\r\n create index paid_site_idx on paid(site_id)\r\n " | |
205 ); | |
206 case 8: | |
207 up.execStep( | |
208 "\r\n create index registration_site_idx on registration(site_id)\r\n " | |
209 ); | |
210 case 9: | |
211 up.execStep( | |
212 "\r\n create index subscription_site_idx on subscription(site_id)\r\n " | |
213 ); | |
214 case 10: | |
215 up.execStep( | |
216 "\r\n create index user_property_site_idx on user_property(site_id)\r\n " | |
217 ); | |
218 case 11: | |
219 up.execStep( | |
220 "\r\n create index view_count_site_idx on view_count(site_id)\r\n " | |
221 ); | |
222 case 12: | |
223 up.execStep( | |
224 "\r\n create index visited_site_idx on visited(site_id)\r\n " | |
225 ); | |
226 | |
227 case 13: | |
228 up.execStep( | |
229 "\r\n create index tag_node_idx on tag(node_id)\r\n " | |
230 ); | |
231 case 14: | |
232 up.execStep( | |
233 "\r\n create index tag_user_idx on tag(user_id)\r\n " | |
234 ); | |
235 case 15: | |
236 up.execStep( | |
237 "\r\n create index embed_key_node_idx on embed_key(node_id)\r\n " | |
238 ); | |
239 case 16: | |
240 up.execStep( | |
241 "\r\n create index visited_node_idx on visited(node_id)\r\n " | |
242 ); | |
243 case 17: | |
244 up.execStep( | |
245 "\r\n create index visited_last_node_idx on visited(last_node_id)\r\n " | |
246 ); | |
247 case 18: | |
248 up.execStep( | |
249 "\r\n alter table node add column poll_option_count integer default null\r\n " | |
250 ); | |
251 case 19: | |
252 up.execStep( | |
253 "\r\n alter table configuration drop column site_id\r\n " | |
254 ); | |
255 case 20: | |
256 up.execStep( | |
257 "\r\n alter table configuration ADD PRIMARY KEY (name)\r\n " | |
258 ); | |
259 case 21: | |
260 up.execStep( | |
261 "\r\n alter table embed_key drop column site_id\r\n " | |
262 ); | |
263 case 22: | |
264 up.execStep( | |
265 "\r\n alter table file_avatar drop column site_id\r\n " | |
266 ); | |
267 case 23: | |
268 up.execStep( | |
269 "\r\n alter table file_node drop column site_id\r\n " | |
270 ); | |
271 case 24: | |
272 up.execStep( | |
273 "\r\n alter table file_temp drop column site_id\r\n " | |
274 ); | |
275 case 25: | |
276 up.execStep( | |
277 "\r\n alter table mailing_list drop column site_id\r\n " | |
278 ); | |
279 case 26: | |
280 up.execStep( | |
281 "\r\n alter table node_msg drop column site_id\r\n " | |
282 ); | |
283 case 27: | |
284 up.execStep( | |
285 "\r\n alter table node_property drop column site_id\r\n " | |
286 ); | |
287 case 28: | |
288 up.execStep( | |
289 "\r\n alter table paid drop column site_id\r\n " | |
290 ); | |
291 case 29: | |
292 up.execStep( | |
293 "\r\n alter table registration drop column site_id\r\n " | |
294 ); | |
295 case 30: | |
296 up.execStep( | |
297 "\r\n alter table subscription drop column site_id\r\n " | |
298 ); | |
299 case 31: | |
300 up.execStep( | |
301 "\r\n alter table user_property drop column site_id\r\n " | |
302 ); | |
303 case 32: | |
304 up.execStep( | |
305 "\r\n alter table view_count drop column site_id\r\n " | |
306 ); | |
307 case 33: | |
308 up.execStep( | |
309 "\r\n alter table visited drop column site_id\r\n " | |
310 ); | |
311 case 34: | |
312 up.execStep( | |
313 "\r\n alter table file_site drop column site_id\r\n " | |
314 ); | |
315 case 35: | |
316 up.execStep( | |
317 "\r\n alter table file_site ADD PRIMARY KEY (name)\r\n " | |
318 ); | |
319 case 36: | |
320 up.execStep( | |
321 "\r\n alter table module drop column site_id\r\n " | |
322 ); | |
323 case 37: | |
324 up.execStep( | |
325 "\r\n alter table module ADD PRIMARY KEY (module_name)\r\n " | |
326 ); | |
327 case 38: | |
328 up.execStep( | |
329 "\r\n alter table site_property drop column site_id\r\n " | |
330 ); | |
331 case 39: | |
332 up.execStep( | |
333 "\r\n alter table site_property ADD PRIMARY KEY (key)\r\n " | |
334 ); | |
335 case 40: | |
336 up.execStep( | |
337 "\r\n alter table tweak drop column site_id\r\n " | |
338 ); | |
339 case 41: | |
340 up.execStep( | |
341 "\r\n alter table tweak ADD PRIMARY KEY (tweak_name)\r\n " | |
342 ); | |
343 case 42: | |
344 up.execStep( | |
345 "\r\n alter table tag drop column site_id\r\n " | |
346 ); | |
347 case 43: | |
348 up.execStep( | |
349 "\r\n CREATE UNIQUE INDEX tag_idx\r\n ON tag (node_id, user_id, label);\r\n " | |
350 ); | |
351 case 44: | |
352 up.execStep( | |
353 "\r\n drop index tag_node_idx\r\n " | |
354 ); | |
355 case 45: | |
356 up.execStep( | |
357 "\r\n alter table user_ drop column site_id\r\n " | |
358 ); | |
359 case 46: | |
360 up.execStep( | |
361 "\r\n CREATE UNIQUE INDEX user_email_idx\r\n ON user_ (lower(email));\r\n " | |
362 ); | |
363 case 47: | |
364 up.execStep( | |
365 "\r\n CREATE UNIQUE INDEX user_name_idx\r\n ON user_ (lower(name));\r\n " | |
366 ); | |
367 case 48: | |
368 up.execStep( | |
369 "\r\n alter table node drop column site_id\r\n " | |
370 ); | |
371 case 49: | |
372 up.execStep( | |
373 "\r\n CREATE INDEX node_cookie_idx\r\n ON node (cookie)\r\n WHERE cookie IS NOT NULL;\r\n " | |
374 ); | |
375 case 50: | |
376 up.execStep( | |
377 "\r\n CREATE INDEX node_message_id_idx\r\n ON node (lower(message_id))\r\n WHERE message_id IS NOT NULL;\r\n " | |
378 ); | |
379 case 51: | |
380 up.execStep( | |
381 "\r\n drop table embed_key\r\n " | |
382 ); | |
383 case 52: | |
384 up.execStep( | |
385 "\r\n delete from site_property where key = '__embedding_warning'\r\n " | |
386 ); | |
387 case 53: | |
388 up.execStep( | |
389 "\r\n alter table site drop column site_id\r\n " | |
390 ); | |
391 case 54: | |
392 up.execStep( | |
393 "\r\n alter table site add column one integer default 1 not null\r\n " | |
394 ); | |
395 case 55: | |
396 up.execStep( | |
397 "\r\n alter table site ADD PRIMARY KEY (one)\r\n " | |
398 ); | |
399 case 56: | |
400 up.execStep( | |
401 "\r\n alter table site add column content_type character varying;\r\n " | |
402 ); | |
403 case 57: | |
404 up.execStep( | |
405 "\r\n update configuration set naml=E'<override_macro name=\"site_style\">\\n\\t<n.overridden/>\\n\\t#search-box { text-align:left; }\\n</override_macro>' where name='searchBoxAlignment';\r\n " | |
406 ); | |
407 case 58: | |
408 up.execStep( | |
409 "\r\n update site set ad_type=null where ad_type='ADBRITE' or ad_type='ADSENSE'\r\n " | |
410 ); | |
411 | |
412 case 59: | |
413 up.execStep( | |
414 "\r\n alter table node\r\n add column unsafe character varying default 'new',\r\n add column safe_version integer\r\n " | |
415 ); | |
416 case 60: | |
417 up.execStep( | |
418 "\r\n alter table user_\r\n add column unsafe character varying default 'new',\r\n add column safe_version integer\r\n " | |
419 ); | |
420 | |
421 case 61: | |
422 up.execStep( | |
423 "\r\n update site set ad_type='HOPELESS' where ad_type='COPYRIGHTED'\r\n " | |
424 ); | |
425 case 62: | |
426 up.execStep( | |
427 "\r\n update site set ad_type='HOPELESS' where ad_type='OURS'\r\n " | |
428 ); | |
429 case 63: | |
430 up.execStep( | |
431 "\r\n update site set ad_type=null, ad_free=" | |
432 +(Integer.MAX_VALUE) | |
433 +" where ad_type='NONE'\r\n " | |
434 ); | |
435 | |
436 case 64: | |
437 up.execStep( | |
438 "\r\n alter table node\r\n add column is_safe boolean\r\n " | |
439 ); | |
440 case 65: | |
441 up.execStep( | |
442 "\r\n alter table user_\r\n add column is_safe boolean\r\n " | |
443 ); | |
444 case 66: | |
445 up.execStep( null ); | |
446 case 67: | |
447 up.execStep( null ); | |
448 case 68: | |
449 up.execStep( | |
450 "\r\n delete from tag where label='hide_ads'\r\n " | |
451 ); | |
452 case 69: | |
453 up.execStep( | |
454 "\r\n update site set ad_type=null where ad_type='SOME_ADSENSE'\r\n " | |
455 ); | |
456 case 70: | |
457 up.execStep( | |
458 "\r\n update site set ad_type='ADULT' where ad_type='HACK'\r\n " | |
459 ); | |
460 case 71: | |
461 up.execStep( | |
462 "\r\n update site set content_type=null where content_type='FAMILY'\r\n " | |
463 ); | |
464 case 72: | |
465 up.execStep( | |
466 "\r\n drop index if exists node_is_safe_idx\r\n " | |
467 ); | |
468 case 73: | |
469 up.execStep( | |
470 "\r\n drop index if exists user_is_safe_idx\r\n " | |
471 ); | |
472 case 74: | |
473 up.execStep( | |
474 "\r\n create index node_unsafe_idx on node(unsafe) where unsafe is not null and unsafe!='new'\r\n " | |
475 ); | |
476 case 75: | |
477 up.execStep( | |
478 "\r\n create index user_unsafe_idx on user_(unsafe) where unsafe is not null and unsafe!='new'\r\n " | |
479 ); | |
480 case 76: | |
481 up.execStep( | |
482 "\r\n update site set content_type=ad_type where content_type is null and ad_type is not null and ad_type!='HOPELESS'\r\n " | |
483 ); | |
484 case 77: | |
485 up.execStep( | |
486 "\r\n update site set ad_type=content_type where content_type is not null and ad_type is null\r\n " | |
487 ); | |
488 case 78: | |
489 up.execStep( | |
490 "\r\n update site set ad_type='ADULT' where content_type='ADULT' and ad_type='PORN'\r\n " | |
491 ); | |
492 | |
493 case 79: | |
494 up.execStep( | |
495 "\r\n alter table user_\r\n drop column unsafe,\r\n drop column safe_version,\r\n drop column is_safe\r\n " | |
496 ); | |
497 case 80: | |
498 up.execStep( null ); | |
499 case 81: | |
500 up.execStep( null ); | |
501 case 82: | |
502 up.begin(); | |
503 up.exec( | |
504 "\r\n alter table node\r\n drop column unsafe,\r\n drop column safe_version,\r\n drop column is_safe\r\n " | |
505 ); | |
506 up.exec( | |
507 "\r\n alter table node\r\n add column unsafe character varying,\r\n add column safe_version integer,\r\n add column is_safe boolean\r\n " | |
508 ); | |
509 up.commit(); | |
510 case 83: | |
511 up.execStep( | |
512 "\r\n create index node_unsafe_idx on node(unsafe) where safe_version is not null\r\n " | |
513 ); | |
514 case 84: | |
515 up.execStep( | |
516 "\r\n delete from module where module_name = 'topic_ads';\r\n " | |
517 ); | |
518 case 85: | |
519 up.execStep( | |
520 "\r\n alter table node\r\n drop column unsafe,\r\n drop column safe_version,\r\n drop column is_safe\r\n " | |
521 ); | |
522 case 86: | |
523 up.execStep( | |
524 "\r\n alter table site\r\n add column when_created timestamp with time zone NOT NULL DEFAULT now()\r\n " | |
525 ); | |
526 case 87: | |
527 up.execStep( | |
528 "\r\n update site\r\n set when_created = node.when_created\r\n from node\r\n where node.node_id = site.root_node_id\r\n " | |
529 ); | |
530 | |
531 case 88: | |
532 up.execStep( | |
533 "\r\n alter table site\r\n add column is_safe boolean NOT NULL DEFAULT true\r\n " | |
534 ); | |
535 case 89: | |
536 up.execStep( | |
537 "\r\n update site set is_safe = false where ad_type is not null\r\n " | |
538 ); | |
539 case 90: | |
540 up.execStep( | |
541 "\r\n update site set when_created = now() where not is_safe\r\n " | |
542 ); | |
543 case 91: | |
544 up.execStep( | |
545 "\r\n alter table site rename column ad_type to old_ad_type\r\n " | |
546 ); | |
547 case 92: | |
548 up.execStep( | |
549 "\r\n alter table site rename column content_type to old_content_type\r\n " | |
550 ); | |
551 case 93: | |
552 up.execStep( | |
553 "\r\n alter table site\r\n add column ad_credits_for_users boolean NOT NULL DEFAULT false\r\n " | |
554 ); | |
555 case 94: | |
556 up.execStep( | |
557 "\r\n alter table site\r\n add column monthly_views integer NOT NULL DEFAULT 0\r\n " | |
558 ); | |
559 case 95: | |
560 up.execStep( | |
561 "\r\n delete from tag where label='group:Administrators' and node_id is null and user_id = (select user_id from user_ where email = 'pedro@nabble.com')\r\n " | |
562 ); | |
563 | |
564 case 96: | |
565 execCatching( | |
566 "\r\n alter table tweak ADD PRIMARY KEY (tweak_name)\r\n " | |
567 , "multiple primary keys for table" ); | |
568 case 97: | |
569 execCatching( | |
570 "\r\n alter table mailing_list ADD PRIMARY KEY (node_id)\r\n " | |
571 , "multiple primary keys for table" ); | |
572 case 98: | |
573 /* | |
574 execCatching( | |
575 "\r\n alter table mailing_list ADD CONSTRAINT mailing_list_node_id_fkey FOREIGN KEY (node_id) REFERENCES node (node_id) ON DELETE CASCADE\r\n " | |
576 , "already exists" ); | |
577 */ | |
578 up.execStep( null ); | |
579 case 99: | |
580 execCatching( | |
581 "\r\n CREATE INDEX forum_ml_idx ON mailing_list (lower(list_address))\r\n " | |
582 , "already exists" ); | |
583 case 100: | |
584 execCatching( | |
585 "\r\n alter table node ADD PRIMARY KEY (node_id)\r\n " | |
586 , "multiple primary keys for table" ); | |
587 case 101: | |
588 execCatching( | |
589 "\r\n alter table configuration ADD PRIMARY KEY (name)\r\n " | |
590 , "multiple primary keys for table" ); | |
591 case 102: | |
592 execCatching( | |
593 "\r\n alter table file_avatar ADD PRIMARY KEY (user_id, name)\r\n " | |
594 , "multiple primary keys for table" ); | |
595 case 103: | |
596 execCatching( | |
597 "\r\n alter table file_node ADD PRIMARY KEY (node_id, name)\r\n " | |
598 , "multiple primary keys for table" ); | |
599 case 104: | |
600 execCatching( | |
601 "\r\n alter table file_site ADD PRIMARY KEY (name)\r\n " | |
602 , "multiple primary keys for table" ); | |
603 case 105: | |
604 execCatching( | |
605 "\r\n alter table file_temp ADD PRIMARY KEY (user_id, name)\r\n " | |
606 , "multiple primary keys for table" ); | |
607 case 106: | |
608 execCatching( | |
609 "\r\n CREATE INDEX file_temp_date_idx ON file_temp (date_)\r\n " | |
610 , "already exists" ); | |
611 case 107: | |
612 execCatching( | |
613 "\r\n alter table module ADD PRIMARY KEY (module_name)\r\n " | |
614 , "multiple primary keys for table" ); | |
615 case 108: | |
616 execCatching( | |
617 "\r\n CREATE INDEX node_cookie_idx ON node (cookie) WHERE cookie IS NOT NULL\r\n " | |
618 , "already exists" ); | |
619 case 109: | |
620 execCatching( | |
621 "\r\n CREATE INDEX node_export ON node (export_permalink) WHERE export_permalink IS NOT NULL\r\n " | |
622 , "already exists" ); | |
623 case 110: | |
624 execCatching( | |
625 "\r\n CREATE INDEX node_message_id_idx ON node (lower(message_id)) WHERE message_id IS NOT NULL\r\n " | |
626 , "already exists" ); | |
627 case 111: | |
628 execCatching( | |
629 "\r\n CREATE INDEX node_ml2_idx ON node (lower(parent_message_id)) WHERE lower(parent_message_id) IS NOT NULL\r\n " | |
630 , "already exists" ); | |
631 case 112: | |
632 execCatching( | |
633 "\r\n CREATE INDEX node_owner_idx ON node (owner_id, when_created)\r\n " | |
634 , "already exists" ); | |
635 case 113: | |
636 execCatching( | |
637 "\r\n CREATE UNIQUE INDEX node_parent2_idx ON node (parent_id, when_created, node_id)\r\n " | |
638 , "already exists" ); | |
639 case 114: | |
640 execCatching( | |
641 "\r\n CREATE UNIQUE INDEX node_parent_idx ON node (parent_id, last_node_date, node_id)\r\n " | |
642 , "already exists" ); | |
643 case 115: | |
644 execCatching( | |
645 "\r\n CREATE INDEX node_sent_idx ON node (when_sent) WHERE when_sent IS NOT NULL\r\n " | |
646 , "already exists" ); | |
647 case 116: | |
648 execCatching( | |
649 "\r\n CREATE UNIQUE INDEX pinned_node_idx ON node (parent_id, pin) WHERE pin IS NOT NULL\r\n " | |
650 , "already exists" ); | |
651 case 117: | |
652 execCatching( | |
653 "\r\n CREATE INDEX post_date ON node (when_created)\r\n " | |
654 , "already exists" ); | |
655 case 118: | |
656 execCatching( | |
657 "\r\n alter table node_msg ADD PRIMARY KEY (node_id)\r\n " | |
658 , "multiple primary keys for table" ); | |
659 case 119: | |
660 execCatching( | |
661 "\r\n alter table node_property ADD PRIMARY KEY (node_id, key)\r\n " | |
662 , "multiple primary keys for table" ); | |
663 case 120: | |
664 execCatching( | |
665 "\r\n alter table paid ADD PRIMARY KEY (user_id)\r\n " | |
666 , "multiple primary keys for table" ); | |
667 case 121: | |
668 execCatching( | |
669 "\r\n alter table registration ADD PRIMARY KEY (key_)\r\n " | |
670 , "multiple primary keys for table" ); | |
671 case 122: | |
672 execCatching( | |
673 "\r\n CREATE INDEX registration_date_idx ON registration (date_)\r\n " | |
674 , "already exists" ); | |
675 case 123: | |
676 execCatching( | |
677 "\r\n alter table site ADD PRIMARY KEY (one)\r\n " | |
678 , "multiple primary keys for table" ); | |
679 case 124: | |
680 execCatching( | |
681 "\r\n alter table site_property ADD PRIMARY KEY (key)\r\n " | |
682 , "multiple primary keys for table" ); | |
683 case 125: | |
684 execCatching( | |
685 "\r\n alter table subscription ADD PRIMARY KEY (user_id, node_id)\r\n " | |
686 , "multiple primary keys for table" ); | |
687 case 126: | |
688 execCatching( | |
689 "\r\n CREATE INDEX subscription_node_idx ON subscription (node_id)\r\n " | |
690 , "already exists" ); | |
691 case 127: | |
692 execCatching( | |
693 "\r\n CREATE UNIQUE INDEX tag_idx ON tag (node_id, user_id, label)\r\n " | |
694 , "already exists" ); | |
695 case 128: | |
696 execCatching( | |
697 "\r\n CREATE INDEX tag_user_idx ON tag (user_id)\r\n " | |
698 , "already exists" ); | |
699 case 129: | |
700 execCatching( | |
701 "\r\n alter table user_ ADD PRIMARY KEY (user_id)\r\n " | |
702 , "multiple primary keys for table" ); | |
703 case 130: | |
704 execCatching( | |
705 "\r\n CREATE UNIQUE INDEX user_email_idx ON user_ (lower(email))\r\n " | |
706 , "already exists" ); | |
707 case 131: | |
708 execCatching( | |
709 "\r\n CREATE UNIQUE INDEX user_name_idx ON user_ (lower(name))\r\n " | |
710 , "already exists" ); | |
711 case 132: | |
712 execCatching( | |
713 "\r\n alter table user_property ADD PRIMARY KEY (user_id, key)\r\n " | |
714 , "multiple primary keys for table" ); | |
715 case 133: | |
716 execCatching( | |
717 "\r\n alter table view_count ADD PRIMARY KEY (node_id)\r\n " | |
718 , "multiple primary keys for table" ); | |
719 case 134: | |
720 execCatching( | |
721 "\r\n alter table visited ADD PRIMARY KEY (user_id, node_id)\r\n " | |
722 , "multiple primary keys for table" ); | |
723 case 135: | |
724 execCatching( | |
725 "\r\n CREATE INDEX visited_last_node_idx ON visited (last_node_id)\r\n " | |
726 , "already exists" ); | |
727 case 136: | |
728 execCatching( | |
729 "\r\n CREATE INDEX visited_node_idx ON visited (node_id)\r\n " | |
730 , "already exists" ); | |
731 | |
732 case 137: | |
733 execCatching( | |
734 "\r\n ALTER TABLE ONLY file_avatar \r\n ADD CONSTRAINT file_avatar_user_id_fkey FOREIGN KEY (user_id) REFERENCES user_(user_id) ON DELETE CASCADE\r\n " | |
735 , "already exists" ); | |
736 case 138: | |
737 up.execStep( null ); | |
738 case 139: | |
739 execCatching( | |
740 "\r\n ALTER TABLE ONLY file_temp \r\n ADD CONSTRAINT file_temp_user_id_fkey FOREIGN KEY (user_id) REFERENCES user_(user_id) ON DELETE CASCADE\r\n " | |
741 , "already exists" ); | |
742 case 140: | |
743 execCatching( | |
744 "\r\n ALTER TABLE ONLY mailing_list \r\n ADD CONSTRAINT mailing_list_node_id_fkey FOREIGN KEY (node_id) REFERENCES node(node_id) ON DELETE CASCADE\r\n " | |
745 , "already exists" ); | |
746 case 141: | |
747 up.execStep( null ); | |
748 case 142: | |
749 execCatching( | |
750 "\r\n ALTER TABLE ONLY node \r\n ADD CONSTRAINT node_new_owner_id_fkey FOREIGN KEY (owner_id) REFERENCES user_(user_id)\r\n " | |
751 , "already exists" ); | |
752 case 143: | |
753 execCatching( | |
754 "\r\n ALTER TABLE ONLY node \r\n ADD CONSTRAINT node_node_id_fkey FOREIGN KEY (node_id) REFERENCES node_msg(node_id) DEFERRABLE INITIALLY DEFERRED\r\n " | |
755 , "already exists" ); | |
756 case 144: | |
757 up.execStep( null ); | |
758 case 145: | |
759 up.execStep( null ); | |
760 case 146: | |
761 execCatching( | |
762 "\r\n ALTER TABLE ONLY paid \r\n ADD CONSTRAINT paid_user_id_fkey FOREIGN KEY (user_id) REFERENCES user_(user_id) ON DELETE CASCADE\r\n " | |
763 , "already exists" ); | |
764 case 147: | |
765 execCatching( | |
766 "\r\n ALTER TABLE ONLY site \r\n ADD CONSTRAINT site_root_node_id_fkey FOREIGN KEY (root_node_id) REFERENCES node(node_id) DEFERRABLE INITIALLY DEFERRED\r\n " | |
767 , "already exists" ); | |
768 case 148: | |
769 up.execStep( null ); | |
770 case 149: | |
771 execCatching( | |
772 "\r\n ALTER TABLE ONLY subscription \r\n ADD CONSTRAINT subscription_user_id_fkey FOREIGN KEY (user_id) REFERENCES user_(user_id) ON DELETE CASCADE\r\n " | |
773 , "already exists" ); | |
774 case 150: | |
775 up.execStep( null ); | |
776 case 151: | |
777 execCatching( | |
778 "\r\n ALTER TABLE ONLY tag \r\n ADD CONSTRAINT tag_user_id_fkey FOREIGN KEY (user_id) REFERENCES user_(user_id) ON DELETE CASCADE\r\n " | |
779 , "already exists" ); | |
780 case 152: | |
781 execCatching( | |
782 "\r\n ALTER TABLE ONLY user_property \r\n ADD CONSTRAINT user_property_user_id_fkey FOREIGN KEY (user_id) REFERENCES user_(user_id) ON DELETE CASCADE\r\n " | |
783 , "already exists" ); | |
784 case 153: | |
785 up.execStep( null ); | |
786 case 154: | |
787 up.execStep( null ); | |
788 case 155: | |
789 up.execStep( null ); | |
790 case 156: | |
791 execCatching( | |
792 "\r\n ALTER TABLE ONLY visited \r\n ADD CONSTRAINT visited_user_id_fkey FOREIGN KEY (user_id) REFERENCES user_(user_id) ON DELETE CASCADE\r\n " | |
793 , "already exists" ); | |
794 case 157: | |
795 up.execStep( null ); | |
796 | |
797 // problematic constraints | |
798 case 158: | |
799 execCatching( | |
800 "\r\n ALTER TABLE ONLY file_node \r\n ADD CONSTRAINT file_node_node_id_fkey FOREIGN KEY (node_id) REFERENCES node(node_id) ON DELETE CASCADE\r\n " | |
801 , "already exists" ); | |
802 case 159: | |
803 execCatching( | |
804 "\r\n ALTER TABLE ONLY node_msg \r\n ADD CONSTRAINT node_msg_node_id_fkey FOREIGN KEY (node_id) REFERENCES node(node_id) ON DELETE CASCADE\r\n " | |
805 , "already exists" ); | |
806 case 160: | |
807 execCatching( | |
808 "\r\n ALTER TABLE ONLY node \r\n ADD CONSTRAINT node_parent_id_fkey FOREIGN KEY (parent_id) REFERENCES node(node_id) ON DELETE CASCADE\r\n " | |
809 , "already exists" ); | |
810 case 161: | |
811 execCatching( | |
812 "\r\n ALTER TABLE ONLY node_property \r\n ADD CONSTRAINT node_property_node_id_fkey FOREIGN KEY (node_id) REFERENCES node(node_id) ON DELETE CASCADE\r\n " | |
813 , "already exists" ); | |
814 case 162: | |
815 execCatching( | |
816 "\r\n ALTER TABLE ONLY subscription \r\n ADD CONSTRAINT subscription_node_id_fkey FOREIGN KEY (node_id) REFERENCES node(node_id) ON DELETE CASCADE\r\n " | |
817 , "already exists" ); | |
818 case 163: | |
819 execCatching( | |
820 "\r\n ALTER TABLE ONLY tag \r\n ADD CONSTRAINT tag_node_id_fkey FOREIGN KEY (node_id) REFERENCES node(node_id) ON DELETE CASCADE\r\n " | |
821 , "already exists" ); | |
822 case 164: | |
823 execCatching( | |
824 "\r\n ALTER TABLE ONLY view_count \r\n ADD CONSTRAINT view_count_node_id_fkey FOREIGN KEY (node_id) REFERENCES node(node_id) ON DELETE CASCADE\r\n " | |
825 , "already exists" ); | |
826 case 165: | |
827 execCatching( | |
828 "\r\n ALTER TABLE ONLY visited \r\n ADD CONSTRAINT visited_last_node_id_fkey FOREIGN KEY (last_node_id) REFERENCES node(node_id) ON DELETE CASCADE\r\n " | |
829 , "already exists" ); | |
830 case 166: | |
831 execCatching( | |
832 "\r\n ALTER TABLE ONLY visited \r\n ADD CONSTRAINT visited_node_id_fkey FOREIGN KEY (node_id) REFERENCES node(node_id) ON DELETE CASCADE\r\n " | |
833 , "already exists" ); | |
834 } | |
835 } | |
836 } | |
837 |