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