run_statement "dhcp4_global_parameter_server" "$qry"
# table: dhcp4_option_def
- qry="select id, code, name, space, type, modification_ts, array, encapsulate, record_types, user_context from dhcp4_option_def"
+ qry="select id, code, name, space, type, modification_ts, is_array, encapsulate, record_types, user_context from dhcp4_option_def"
run_statement "dhcp4_option_def" "$qry"
# table: dhcp4_option_def_server
run_statement "dhcp6_global_parameter_server" "$qry"
# table: dhcp6_option_def
- qry="select id, code, name, space, type, modification_ts, array, encapsulate, record_types, user_context from dhcp6_option_def"
+ qry="select id, code, name, space, type, modification_ts, is_array, encapsulate, record_types, user_context from dhcp6_option_def"
run_statement "dhcp6_option_def" "$qry"
# table: dhcp6_option_def_server
version=$(${keaadmin} db-version mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir)
assert_str_eq "8.2" ${version} "Expected kea-admin to return %s, returned value was %s"
+ # Verify that dhcp4_option_def column name is is_array
+ qry="select is_array from dhcp4_option_def"
+ run_statement "dhcp4_option_def verify is_array column" "$qry"
+
+ # Verify that dhcp6_option_def column name is is_array
+ qry="select is_array from dhcp6_option_def"
+ run_statement "dhcp6_option_def verify is_array column" "$qry"
+
# Let's wipe the whole database
mysql_wipe
space VARCHAR(128) NOT NULL,
type TINYINT UNSIGNED NOT NULL,
modification_ts TIMESTAMP NOT NULL,
- array TINYINT(1) NOT NULL,
+ is_array TINYINT(1) NOT NULL,
encapsulate VARCHAR(128) NOT NULL,
record_types VARCHAR(512) DEFAULT NULL,
user_context LONGTEXT,
space VARCHAR(128) NOT NULL,
type TINYINT UNSIGNED NOT NULL,
modification_ts TIMESTAMP NOT NULL,
- array TINYINT(1) NOT NULL,
+ is_array TINYINT(1) NOT NULL,
encapsulate VARCHAR(128) NOT NULL,
record_types VARCHAR(512) DEFAULT NULL,
user_context LONGTEXT,
DROP TABLE IF EXISTS parameter_data_type;
DROP PROCEDURE IF EXISTS createAuditRevisionDHCP4;
DROP PROCEDURE IF EXISTS createAuditEntryDHCP4;
+DROP PROCEDURE IF EXISTS createOptionAuditDHCP4;
DROP TRIGGER IF EXISTS dhcp4_global_parameter_AINS;
DROP TRIGGER IF EXISTS dhcp4_global_parameter_AUPD;
DROP TRIGGER IF EXISTS dhcp4_global_parameter_ADEL;
DROP TABLE IF EXISTS dhcp6_audit_revision;
DROP PROCEDURE IF EXISTS createAuditRevisionDHCP6;
DROP PROCEDURE IF EXISTS createAuditEntryDHCP6;
+DROP PROCEDURE IF EXISTS createOptionAuditDHCP6;
DROP TRIGGER IF EXISTS dhcp6_global_parameter_AINS;
DROP TRIGGER IF EXISTS dhcp6_global_parameter_AUPD;
DROP TRIGGER IF EXISTS dhcp6_global_parameter_ADEL;
space VARCHAR(128) NOT NULL,
type TINYINT UNSIGNED NOT NULL,
modification_ts TIMESTAMP NOT NULL,
- array TINYINT(1) NOT NULL,
+ is_array TINYINT(1) NOT NULL,
encapsulate VARCHAR(128) NOT NULL,
record_types VARCHAR(512) DEFAULT NULL,
user_context LONGTEXT,
space VARCHAR(128) NOT NULL,
type TINYINT UNSIGNED NOT NULL,
modification_ts TIMESTAMP NOT NULL,
- array TINYINT(1) NOT NULL,
+ is_array TINYINT(1) NOT NULL,
encapsulate VARCHAR(128) NOT NULL,
record_types VARCHAR(512) DEFAULT NULL,
user_context LONGTEXT,
VERSION=`mysql_version "$@"`
+# We need to set global RESULT when we exit. This is checked by callers.
+bail() {
+ RESULT=$1
+ exit $1
+}
+
if [ "$VERSION" != "8.1" ]; then
printf "This script upgrades 8.1 to 8.2. Reported version is $VERSION. Skipping upgrade.\n"
- exit 0
+ bail 0
+fi
+
+# Get the schema name from database argument. We need this to
+# query information_schema for the right database.
+for arg in $@
+do
+ cnt=`echo $arg | grep -c "^\-\-"`
+ if [ $cnt -eq 0 ]
+ then
+ schema="$arg"
+ break;
+ fi
+done
+
+# Make sure we can id the schema
+if [ -z $schema ]
+then
+ printf "Could not find database schema name in cmd line args: $@\n"
+ bail 255
fi
+# Save the command line args, as we use these later change_column function.
+cmdargs="$@"
+
+# Function to rename a column in a table.
+change_column() {
+ local schema="$1"
+ local table="$2"
+ local ocolumn="$3"
+ local ncolumn="$4"
+
+ # First let's find out if the column name in the table actually needs updating.
+ sql="select count(column_name) from information_schema.columns where table_schema='$schema' and table_name = '$table' and column_name = '$ocolumn'"
+
+ count=`mysql -N -B $cmdargs -e "$sql"`
+ if [ $? -ne 0 ]
+ then
+ printf "change_column: schema query failed [$sql]\n"
+ bail 255;
+ fi
+
+ # If we found a match record, the column needs to be renamed
+ if [ "$count" -eq 1 ]
+ then
+ sql="ALTER TABLE $table CHANGE COLUMN $ocolumn $ncolumn"
+ mysql -N -B $cmdargs -e "$sql"
+ if [ $? -ne 0 ]
+ then
+ printf "change_column: alter query failed: [$sql]\n"
+ bail 255;
+ fi
+ else
+ printf "$table column is already correct\n"
+ fi
+}
+
mysql "$@" <<EOF
# Drop existing trigger on the dhcp4_shared_network table.
EOF
RESULT=$?
+if [ $RESULT -ne 0 ]
+then
+ exit $RESULT
+fi
+
+# We need to rename the columns in the option def tables because "array" is
+# a MySQL keyword as of 8.0.17
+change_column $schema dhcp4_option_def array "is_array TINYINT(1) NOT NULL"
+change_column $schema dhcp6_option_def array "is_array TINYINT(1) NOT NULL"
-exit $?
+bail 0