]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/build-db.sh
dependency ordering of config functions
[working/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
85   002.schema.config.sql
86   002.functions.aggregate.sql
87   002.functions.config.sql
88
89   005.schema.actors.sql
90   006.schema.permissions.sql
91   010.schema.biblio.sql
92   011.schema.authority.sql
93   012.schema.vandelay.sql
94   020.schema.functions.sql
95   030.schema.metabib.sql
96   040.schema.asset.sql
97   070.schema.container.sql
98   080.schema.money.sql
99   090.schema.action.sql
100   
101   100.circ_matrix.sql
102   110.hold_matrix.sql
103
104   300.schema.staged_search.sql
105   
106   500.view.cross-schema.sql
107   
108   800.fkeys.sql
109   
110   900.audit-functions.sql
111   901.audit-tables.sql
112   950.data.seed-values.sql
113   951.data.MODS-xsl.sql
114   952.data.MODS3-xsl.sql
115   953.data.MODS32-xsl.sql
116   
117   reporter-schema.sql
118   extend-reporter.sql
119 "
120
121 # ---------------------------------------------------------------------------
122 # Import files via psql, warn user on error, suggest abort.
123 # ---------------------------------------------------------------------------
124 for sql_file in $ordered_file_list; do
125   # It would be wise to turn this on only if confidence is high that errors in
126   # scripts will result in terminal failures.  Currently, there are a couple
127   # that seem benign.  --asjoyner
128   # export ON_ERROR_STOP=1
129
130   export PGHOST PGPORT PGDATABASE PGUSER PGPASSWORD
131   psql -f $sql_file
132   if [ $? != 0 ]; then
133     cat <<EOM
134 ********************************************************************************
135 * There was an error with a database configuration file:                       *
136 * $sql_file
137 * It is very likely that your installation will be unsuccessful because of     *
138 * this error.  Press Control-C to abort, or press enter to charge ahead.       *
139 ********************************************************************************
140 EOM
141     read unused
142   fi
143 done
144