3 # setup the db tables required for Ninja
6 target_sched_version
=10
18 usage: $progname [options]
20 Where options can be any combination of:
21 --help|-h Print this cruft and exit
22 --db-user=<username> User merlin should use with db
23 --db-pass=<password> Password for the db user
24 --db-name=<name> Database name
32 expr "z$1" : 'z[^=]*=\(.*\)'
38 db_user
=$
(get_arg
"$1")
45 db_pass
=$
(get_arg
"$1")
52 db_name
=$
(get_arg
"$1")
62 echo "Illegal argument. I have no idea what to make of '$1'"
70 prefix
=$
(dirname $0)"/.."
72 run_sql_file
() # (db_login_opts, sql_script_path)
77 mysql
$db_login_opts < $sql_script_path >/dev
/null
2>/dev
/null
80 if [ "$db_pass" != "" ]
82 db_login_opts
="-u$db_user -p$db_pass $db_name"
84 db_login_opts
="-u$db_user $db_name"
87 db_ver
=$
(mysql
$db_login_opts -Be "SELECT version FROM ninja_db_version" 2>/dev
/null |
sed -n \
$p)
91 # nothing found, insert ninja.sql
92 echo "Installing database tables for Ninja GUI"
93 run_sql_file
"$db_login_opts" "$prefix/sql/mysql/ninja.sql"
94 db_ver
=$
(mysql
$db_login_opts -Be "SELECT version FROM ninja_db_version" 2>/dev
/null |
sed -n \
$p)
97 if [[ "$db_ver" = '' ]]
99 echo "Cannot connect to mysql, cannot install/upgrade database."
103 # deprecated and should be deleted if they exist
104 sla_ver
=$
(mysql
$db_login_opts -Be "SELECT version FROM sla_db_version" 2>/dev
/null |
sed -n \
$p)
105 avail_ver
=$
(mysql
$db_login_opts -Be "SELECT version FROM avail_db_version" 2>/dev
/null |
sed -n \
$p)
107 function all_versions
()
110 new_ver
=`expr $db_ver + 1`
111 echo "Upgrading ninja db from v${db_ver} to v${new_ver}"
112 run_sql_file
"$db_login_opts" "$prefix/sql/mysql/ninja_db_v${db_ver}_to_v${new_ver}.sql"
113 mysql
$db_login_opts -Be "UPDATE ninja_db_version SET version=$new_ver" 2>/dev
/null
117 while [ "$db_ver" -lt "$target_db_version" ]; do
120 # add table for recurring_downtime
121 echo "Installing database table for Recurring Downtime"
122 run_sql_file
"$db_login_opts" "$prefix/sql/mysql/recurring_downtime.sql"
123 mysql
$db_login_opts -Be "UPDATE ninja_db_version SET version=2" 2>/dev
/null
127 php index.php cli
/upgrade_auth
132 php index.php cli
/upgrade_recurring_downtime
136 # we intend to drop all the horrible mess that is the old reports
137 # however, we need to upgrade them first, so the migration will work
138 if [ "$sla_ver" != "" ]; then
139 target_sla_version
=10
140 while [ "$sla_ver" -lt "$target_sla_version" ]
145 upgrade_script
="$prefix/sql/mysql/sla_v5_to_v8.sql"
148 new_ver
=`expr $sla_ver + 1 `
149 upgrade_script
="$prefix/sql/mysql/sla_v${sla_ver}_to_v${new_ver}.sql"
153 echo -n "Upgrading SLA tables from v${sla_ver} to v${new_ver} ... "
154 if [ -r "$upgrade_script" ]
156 run_sql_file
"$db_login_opts" $upgrade_script
157 mysql
$db_login_opts -Be "UPDATE sla_db_version SET version = '$new_ver'" 2>/dev
/null
160 echo "SCRIPT MISSING."
161 echo "Tried to use $upgrade_script"
167 if [ "$avail_ver" != "" ]; then
168 target_avail_version
=15
169 while [ "$avail_ver" -lt $target_avail_version ]
174 upgrade_script
="$prefix/sql/mysql/avail_v2_to_v5.sql"
178 upgrade_script
="$prefix/sql/mysql/avail_v6_to_v8.sql"
181 php
$prefix/index.php cli
/upgrade_excluded
183 upgrade_script
="$prefix/sql/mysql/avail_v${avail_ver}_to_v${new_ver}.sql"
186 new_ver
=`expr $avail_ver + 1 `
187 upgrade_script
="$prefix/sql/mysql/avail_v${avail_ver}_to_v${new_ver}.sql"
192 echo -n "Upgrading AVAIL tables from v${avail_ver} to v${new_ver} ... "
193 if [ -r "$upgrade_script" ]
195 run_sql_file
"$db_login_opts" $upgrade_script
196 mysql
$db_login_opts -Be "UPDATE avail_db_version SET version = '$new_ver'" 2>/dev
/null
199 echo "SCRIPT MISSING."
200 echo "Tried to use $upgrade_script"
206 php index.php db_migrations
/v13_to_v14
210 all_versions
"$db_ver"
215 # check that we have the scheduled reports tables in merlin
216 sched_db_ver
=$
(mysql
$db_login_opts -Be "SELECT version FROM scheduled_reports_db_version" 2>/dev
/null |
sed -n \
$p)
218 if [ "$sched_db_ver" = "" ]
220 echo "Installing database tables for scheduled reports configuration"
221 upgrade_script
="$prefix/sql/mysql/scheduled_reports.sql"
222 run_sql_file
"$db_login_opts" $upgrade_script
223 sched_db_ver
=$
(mysql
$db_login_opts -Be "SELECT version FROM scheduled_reports_db_version" 2>/dev
/null |
sed -n \
$p)
226 sched_db_ver
=$
(echo $sched_db_ver | cut
-d '.' -f1)
227 while [ "$sched_db_ver" -lt "$target_sched_version" ]; do
228 case "$sched_db_ver" in
232 upgrade_script
="$prefix/sql/mysql/scheduled_reports_v${sched_db_ver}_to_v${new_ver}.sql"
235 new_ver
=`expr $sched_db_ver + 1`
236 upgrade_script
="$prefix/sql/mysql/scheduled_reports_v${sched_db_ver}_to_v${new_ver}.sql"
240 echo -n "Upgrading scheduled reports tables from v${sched_db_ver} to v${new_ver}.sql ... "
241 if [ -r "$upgrade_script" ]
243 run_sql_file
"$db_login_opts" $upgrade_script
244 mysql
$db_login_opts -Be "UPDATE scheduled_reports_db_version SET version = '${new_ver}'" 2>/dev
/null
247 echo "SCRIPT MISSING."
248 echo "Tried to use $upgrade_script"
251 sched_db_ver
=$new_ver
254 echo "Database upgrade complete."