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