]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#853, !26-p] Update schema scripts and tests
authorThomas Markwalder <tmark@isc.org>
Fri, 23 Aug 2019 14:11:57 +0000 (10:11 -0400)
committerThomas Markwalder <tmark@isc.org>
Mon, 26 Aug 2019 13:39:05 +0000 (09:39 -0400)
src/bin/admin/tests/mysql_tests.sh.in
    Updated expected column names
    Added check of column names for 8.0 to 8.2 upgrade

src/share/database/scripts/mysql/dhcpdb_create.mysql
    Changed array column to is_array in dhcp4/6_option_def tables

src/share/database/scripts/mysql/dhcpdb_drop.mysql
    Added missing drops for createOptionAuditDHCP4/6

src/share/database/scripts/mysql/upgrade_6.0_to_7.0.sh.in
    Changed array column to is_array in dhcp4/6_option_def tables

src/share/database/scripts/mysql/upgrade_8.1_to_8.2.sh.in
    Added logic to conditionally change column names

src/bin/admin/tests/mysql_tests.sh.in
src/share/database/scripts/mysql/dhcpdb_create.mysql
src/share/database/scripts/mysql/dhcpdb_drop.mysql
src/share/database/scripts/mysql/upgrade_6.0_to_7.0.sh.in
src/share/database/scripts/mysql/upgrade_8.1_to_8.2.sh.in

index b8566d66ec216ddbf062358c7c852a00c88f8c64..0823b754c41d0fa147f95e5b963ca73d4ab2e819 100644 (file)
@@ -499,7 +499,7 @@ EOF
     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
@@ -555,7 +555,7 @@ EOF
     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
@@ -725,6 +725,14 @@ EOF
     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
 
index ae4f886975f990073bb79e82264c4fb37472b116..2acfafa601f2eec9ea58673a18656aa543def4ae 100644 (file)
@@ -879,7 +879,7 @@ CREATE TABLE IF NOT EXISTS dhcp4_option_def (
     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,
@@ -1136,7 +1136,7 @@ CREATE TABLE IF NOT EXISTS dhcp6_option_def (
     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,
index 8071caf2d925452325779d14ef19592096dfc45d..43a62e9d9d8ad74bc6420bf02c1859d150e6b9f6 100644 (file)
@@ -62,6 +62,7 @@ DROP TABLE IF EXISTS modification;
 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;
@@ -80,6 +81,7 @@ DROP TRIGGER IF EXISTS dhcp4_options_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;
index 47c29130ea0f35ab3adbfb4c0c8eed8820fbd7be..9c04bfac44245d33a2afc799780067750a49c0ca 100644 (file)
@@ -214,7 +214,7 @@ CREATE TABLE IF NOT EXISTS dhcp4_option_def (
     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,
@@ -457,7 +457,7 @@ CREATE TABLE IF NOT EXISTS dhcp6_option_def (
     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,
index 53e072c8ff0ebe6d83d4a6e47b5cac3779fc8f66..2e35b19f8ead9070f3514640efedc650b4783503 100644 (file)
@@ -11,11 +11,71 @@ fi
 
 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.
@@ -426,5 +486,14 @@ SET version = '8', minor = '2';
 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