]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/build-db.sh
Merge branch 'master' of ssh://yeti.esilibrary.com/home/evergreen/evergreen-equinox...
[Evergreen.git] / Open-ILS / src / sql / Pg / build-db.sh
1 #!/bin/sh
2
3 # ---------------------------------------------------------------------------
4 # Store command line args for later use
5 # args: {db-host} {db-port} {db-name} {db-user} {db-password} {verbose}
6 # ---------------------------------------------------------------------------
7 PGHOST=$1
8 PGPORT=$2
9 PGDATABASE=$3
10 PGUSER=$4
11 PGPASSWORD=$5
12 VERBOSE=$6
13 export PGHOST PGPORT PGDATABASE PGUSER PGPASSWORD
14
15 # ---------------------------------------------------------------------------
16 # Lookup the database version from the PostgreSQL server.
17 # ---------------------------------------------------------------------------
18 DB_VERSION=`psql -qtc 'show server_version;' | xargs | cut -c1,3`
19 if [ -z "$DB_VERSION" ] || [ `echo $DB_VERSION | grep -c '[^0-9]'` != 0 ]; then
20   cat <<EOM
21 ********************************************************************************
22 * Could not determine the version of PostgreSQL you have installed.  Our best  *
23 * guess was:                                                                   *
24 * $DB_VERSION
25 * which didn't make any sense.  For assistance, please email                   *
26 * open-ils-general@list.georgialibraries.org or join #Evergreen on the         *
27 * freenode IRC network.                                                        *
28 ********************************************************************************
29 EOM
30   exit 1
31 fi
32
33 # ---------------------------------------------------------------------------
34 # Validate fts-config file is available for specified DB_VERSION.
35 # ---------------------------------------------------------------------------
36 if [ -e "000.english.pg$DB_VERSION.fts-config.sql" ]; then
37   fts_config_file="000.english.pg$DB_VERSION.fts-config.sql"
38 else
39   # -------------------------------------------------------------------------
40   # Attempt to auto-detect the latest available config file.
41   # -------------------------------------------------------------------------
42   last_ver=""
43   for i in $(seq 80 99 | sort -rn); do
44     if [ -e "000.english.pg$i.fts-config.sql" ]; then
45       last_ver=$i
46       break
47     fi
48   done
49   if [ -z "$last_ver" ]; then
50     cat <<EOM
51 ********************************************************************************
52 * Cannot locate any configuration files for  full text search config.  This    *
53 * may indicate a problem with your copy of the source files.  We attempted to  *
54 * find files like 000.english.pg83.fts-config.sql in this directory:           *
55 * `pwd` 
56 * but were unsuccessful.  Aborting.                                            *
57 ********************************************************************************
58 EOM
59     exit 1
60   fi
61
62   a=$DB_VERSION  # preserves the text alignment below, in a cheap fashion
63   b=$last_ver    # assuming of course two character DB_VERSION and last_ver
64 cat <<EOM
65 ********************************************************************************
66 * There is no configuration for full text search config, for the database      *
67 * version you have installed ($a).  If you're not really sure why, you should  *
68 * proabably press 'Control-C' now, and abort.  To continue using the latest    *
69 * available version ($b), press enter. For assistance, please email            *
70 * open-ils-general@list.georgialibraries.org or join #Evergreen on the         *
71 * freenode IRC network.                                                        *
72 ********************************************************************************
73 EOM
74   read unused
75   fts_config_file="000.english.pg$last_ver.fts-config.sql"
76 fi
77
78 # ---------------------------------------------------------------------------
79 # This describes the order in which the SQL files will be eval'd by psql.
80 # ---------------------------------------------------------------------------
81 ordered_file_list="
82   000.functions.general.sql
83
84   $fts_config_file
85
86   001.schema.offline.sql
87
88   002.schema.config.sql
89   002.functions.aggregate.sql
90   002.functions.config.sql
91
92   005.schema.actors.sql
93   006.schema.permissions.sql
94   008.schema.query.sql
95   010.schema.biblio.sql
96   011.schema.authority.sql
97   012.schema.vandelay.sql
98   015.schema.staging.sql
99   020.schema.functions.sql
100   030.schema.metabib.sql
101   040.schema.asset.sql
102   070.schema.container.sql
103   080.schema.money.sql
104   090.schema.action.sql
105   095.schema.booking.sql
106  
107   099.matrix_weights.sql 
108   100.circ_matrix.sql
109   110.hold_matrix.sql
110
111   210.schema.serials.sql
112   200.schema.acq.sql
113   201.acq.audit-functions.sql
114
115   300.schema.staged_search.sql
116   400.schema.action_trigger.sql
117   
118   500.view.cross-schema.sql
119   
120   800.fkeys.sql
121   
122   900.audit-functions.sql
123   901.audit-tables.sql
124   950.data.seed-values.sql
125   951.data.MODS-xsl.sql
126   952.data.MODS3-xsl.sql
127   953.data.MODS32-xsl.sql
128   954.data.MODS33-xsl.sql
129   954.data.marc21expand880.sql
130
131   990.schema.unapi.sql
132   
133   reporter-schema.sql
134   extend-reporter.sql
135
136   999.functions.global.sql
137 "
138
139 # ---------------------------------------------------------------------------
140 # Import files via psql, warn user on error, suggest abort.
141 # ---------------------------------------------------------------------------
142 for sql_file in $ordered_file_list; do
143   # It would be wise to turn this on only if confidence is high that errors in
144   # scripts will result in terminal failures.  Currently, there are a couple
145   # that seem benign.  --asjoyner
146   # export ON_ERROR_STOP=1
147
148   export PGHOST PGPORT PGDATABASE PGUSER PGPASSWORD
149   # Hide most of the harmless messages that obscure real problems
150   if [ -z "$VERBOSE" ]; then
151     psql -f $sql_file 2>&1 | grep -v NOTICE | grep -v "^INSERT"
152   else
153     psql -f $sql_file
154   fi
155   if [ $? != 0 ]; then
156     cat <<EOM
157 ********************************************************************************
158 * There was an error with a database configuration file:                       *
159 * $sql_file
160 * It is very likely that your installation will be unsuccessful because of     *
161 * this error.  Press Control-C to abort, or press enter to charge ahead.       *
162 ********************************************************************************
163 EOM
164     read unused
165   fi
166 done
167