]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/version-upgrade/2.3-2.4-supplemental.sh
LP#1772028 Add some FK violation functions just in case they are missing
[Evergreen.git] / Open-ILS / src / sql / Pg / version-upgrade / 2.3-2.4-supplemental.sh
1 #!/bin/bash
2
3 echo "Starting update of field_entry values.  This will take a while..."
4 date
5
6 psql -c "UPDATE metabib.identifier_field_entry set value = value;" &
7 psql -c "UPDATE metabib.title_field_entry set value = value;" &
8 psql -c "UPDATE metabib.author_field_entry set value = value;" &
9 psql -c "UPDATE metabib.subject_field_entry set value = value;" &
10 psql -c "UPDATE metabib.keyword_field_entry set value = value;" &
11 psql -c "UPDATE metabib.series_field_entry set value = value;" &
12
13 wait
14
15 echo "Completed update of field_entry values."
16 date
17
18 echo "Starting update of combined field_entry values.  This will also take a while..."
19 psql -c "SELECT count(metabib.update_combined_index_vectors(id)) FROM biblio.record_entry WHERE NOT deleted;" &
20
21 echo "Starting creation of indexes from 0782..."
22 echo "There may be deadlock errors; if they happen, this script will"
23 echo "rebuild the affected invalid indexes at the end."
24 psql -c "CREATE INDEX CONCURRENTLY usr_activity_usr_idx on actor.usr_activity (usr);" &
25 psql -c "CREATE INDEX CONCURRENTLY hold_request_open_idx on action.hold_request (id) where cancel_time IS NULL AND fulfillment_time IS NULL;" &
26 psql -c "CREATE INDEX CONCURRENTLY cp_available_by_circ_lib_idx on asset.copy (circ_lib) where status IN (0,7);" &
27 psql -c "CREATE INDEX CONCURRENTLY edi_message_account_status_idx on acq.edi_message (account,status);" &
28 psql -c "CREATE INDEX CONCURRENTLY atev_def_state on action_trigger.event (event_def,state);" &
29 psql -c "CREATE INDEX CONCURRENTLY hold_transit_copy_hold_idx on action.hold_transit_copy (hold);" &
30
31 wait
32
33 echo "Starting creation of more indexes from 0782..."
34 psql -c "CREATE INDEX CONCURRENTLY hold_request_current_copy_before_cap_idx on action.hold_request (current_copy) where capture_time IS NULL AND cancel_time IS NULL;" &
35 psql -c "CREATE INDEX CONCURRENTLY edi_message_po_idx on acq.edi_message (purchase_order);" &
36
37 wait
38
39 echo "Parallel updates complete."
40 echo "Creating any indexes that may not have been built due to a deadlock"
41 echo "bug in PostgreSQL"
42 date
43
44 rebuildscript=`mktemp`
45 psql -A -t -c "SELECT 'DROP INDEX ' || n.nspname || '.' || i.relname || ';' \
46 FROM pg_index x \
47 JOIN pg_class c ON c.oid = x.indrelid \
48 JOIN pg_class i ON i.oid = x.indexrelid \
49 LEFT JOIN pg_namespace n ON n.oid = c.relnamespace \
50 WHERE c.relkind = 'r'::\"char\" AND i.relkind = 'i'::\"char\" \
51 AND n.nspname IN ('action', 'action_trigger', 'actor', 'acq', 'asset') \
52 AND NOT x.indisvalid;" >  $rebuildscript
53
54 psql -A -t -c "SELECT pg_get_indexdef(i.oid) || ';' \
55 FROM pg_index x \
56 JOIN pg_class c ON c.oid = x.indrelid \
57 JOIN pg_class i ON i.oid = x.indexrelid \
58 LEFT JOIN pg_namespace n ON n.oid = c.relnamespace \
59 WHERE c.relkind = 'r'::\"char\" AND i.relkind = 'i'::\"char\" \
60 AND n.nspname IN ('action', 'action_trigger', 'actor', 'acq', 'asset') \
61 AND NOT x.indisvalid;" >> $rebuildscript
62
63 psql -a -f $rebuildscript
64
65 echo "Combined field_entry values and index creation complete"
66 date