]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5522] Correct subnet id columns types in Postgresql and MySQL schemas
authorThomas Markwalder <tmark@isc.org>
Thu, 1 Feb 2018 21:27:31 +0000 (16:27 -0500)
committerThomas Markwalder <tmark@isc.org>
Thu, 1 Feb 2018 21:27:31 +0000 (16:27 -0500)
  Added upgrade scripts; updated schema create scripts, version numbers
  update tests...

13 files changed:
configure.ac
src/bin/admin/tests/mysql_tests.sh.in
src/bin/admin/tests/pgsql_tests.sh.in
src/lib/dhcpsrv/mysql_connection.h
src/lib/dhcpsrv/pgsql_connection.h
src/share/database/scripts/mysql/.gitignore
src/share/database/scripts/mysql/dhcpdb_create.mysql
src/share/database/scripts/mysql/upgrade_5.1_to_5.2.sh.in [new file with mode: 0644]
src/share/database/scripts/pgsql/.gitignore
src/share/database/scripts/pgsql/Makefile.am
src/share/database/scripts/pgsql/dhcpdb_create.pgsql
src/share/database/scripts/pgsql/upgrade_3.1_to_3.2.sh.in
src/share/database/scripts/pgsql/upgrade_3.2_to_3.3.sh.in [new file with mode: 0644]

index 68e5d78ca94bfccfe654699e3b022181b740313e..428de075899cc2a0054a9e267217fff6bd02bb67 100644 (file)
@@ -1327,11 +1327,13 @@ AC_CONFIG_FILES([Makefile
                  src/share/database/scripts/mysql/upgrade_4.0_to_4.1.sh
                  src/share/database/scripts/mysql/upgrade_4.1_to_5.0.sh
                  src/share/database/scripts/mysql/upgrade_5.0_to_5.1.sh
+                 src/share/database/scripts/mysql/upgrade_5.1_to_5.2.sh
                  src/share/database/scripts/pgsql/Makefile
                  src/share/database/scripts/pgsql/upgrade_1.0_to_2.0.sh
                  src/share/database/scripts/pgsql/upgrade_2.0_to_3.0.sh
                  src/share/database/scripts/pgsql/upgrade_3.0_to_3.1.sh
                  src/share/database/scripts/pgsql/upgrade_3.1_to_3.2.sh
+                 src/share/database/scripts/pgsql/upgrade_3.2_to_3.3.sh
                  tools/Makefile
                  tools/path_replacer.sh
 ])
index 2dc9968a451b50a42cc6170576beb0fee5195141..aa9996a3d18459eb4483a669d955b12e48e4c935 100644 (file)
@@ -351,9 +351,9 @@ EOF
     count=`echo $text | grep -ic unsigned`
     assert_eq 1 $count "dhcp6_subnet_id is not of unsigned type. (expected count %d, returned %d)"
 
-    # Verify upgraded schema reports version 5.1
+    # Verify upgraded schema reports version 5.2
     version=$(${keaadmin} lease-version mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir)
-    assert_str_eq "5.1" ${version} "Expected kea-admin to return %s, returned value was %s"
+    assert_str_eq "5.2" ${version} "Expected kea-admin to return %s, returned value was %s"
 
     # Let's wipe the whole database
     mysql_wipe
index 41b7437e025f7febc64e564f1ecbe260a5db4906..ca46aefb2bd737746c524e16c195415f4692ebb6 100644 (file)
@@ -89,7 +89,7 @@ pgsql_lease_version_test() {
 
     # Verify that kea-admin lease-version returns the correct version
     version=$(${keaadmin} lease-version pgsql -u $db_user -p $db_password -n $db_name)
-    assert_str_eq "3.2" ${version} "Expected kea-admin to return %s, returned value was %s"
+    assert_str_eq "3.3" ${version} "Expected kea-admin to return %s, returned value was %s"
 
     # Let's wipe the whole database
     pgsql_wipe
@@ -199,10 +199,10 @@ pgsql_upgrade_2_0_to_3_0() {
     assert_eq 1 "$output" "lease_hwaddr_source does not contain entry for HWADDR_SOURCE_UNKNOWN. (record count %d, expected %d)"
 }
 
-pgsql_upgrade_3_0_to_3_1() {
-    # Verify upgraded schema reports version 3.1.
+pgsql_upgrade_3_0_to_3_3() {
+    # Verify upgraded schema reports version 3.3.
     version=$(${keaadmin} lease-version pgsql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir)
-    assert_str_eq "3.1" ${version} "Expected kea-admin to return %s, returned value was %s"
+    assert_str_eq "3.3" ${version} "Expected kea-admin to return %s, returned value was %s"
 }
 
 pgsql_upgrade_test() {
@@ -224,8 +224,8 @@ pgsql_upgrade_test() {
     # Check 2.0 to 3.0 upgrade
     pgsql_upgrade_2_0_to_3_0
 
-    # Check 3.0 to 3.1 upgrade
-    pgsql_upgrade_3_0_to_3_1
+    # Check 3.0 to 3.3 upgrade
+    pgsql_upgrade_3_0_to_3_3
 
     # Let's wipe the whole database
     pgsql_wipe
index 322b33fdae19c90f528b8adb814083914aea82d5..44f2b8e384301f1c405337264d76694d6e15fccd 100644 (file)
@@ -41,7 +41,7 @@ extern const int MLM_MYSQL_FETCH_FAILURE;
 /// @name Current database schema version values.
 //@{
 const uint32_t MYSQL_SCHEMA_VERSION_MAJOR = 5;
-const uint32_t MYSQL_SCHEMA_VERSION_MINOR = 1;
+const uint32_t MYSQL_SCHEMA_VERSION_MINOR = 2;
 
 //@}
 
index 9aab9bfa3559f8adc3baa05383fe7312a888aab2..988168ec3079bc48ebca5125a22ddccb64679cdd 100644 (file)
@@ -17,9 +17,9 @@
 namespace isc {
 namespace dhcp {
 
-/// @brief Define PostgreSQL backend version: 3.2
+/// @brief Define PostgreSQL backend version: 3.3
 const uint32_t PG_SCHEMA_VERSION_MAJOR = 3;
-const uint32_t PG_SCHEMA_VERSION_MINOR = 2;
+const uint32_t PG_SCHEMA_VERSION_MINOR = 3;
 
 // Maximum number of parameters that can be used a statement
 // @todo This allows us to use an initializer list (since we can't
index f4c4eb0e8b73dd5eaeefd1f200cab7a72496cea3..95f9c34a658e980926f5898ca48d6df8f49b696a 100644 (file)
@@ -4,3 +4,5 @@
 /upgrade_4.0_to_4.1.sh
 /upgrade_4.1_to_5.0.sh
 /upgrade_5.0_to_5.1.sh
+/upgrade_5.1_to_5.2.sh
+
index bb82fc33ddbc428cccc1b5458ffe140903e8a262..8cb95e5119994a2b10a8e3d6e5525e22b438ee13 100644 (file)
@@ -504,6 +504,16 @@ UPDATE schema_version
 SET version = '5', minor = '1';
 # This line concludes database upgrade to version 5.1.
 
+# Make subnet_id column types consistent with lease table columns
+ALTER TABLE dhcp4_options MODIFY dhcp4_subnet_id INT UNSIGNED;
+ALTER TABLE dhcp6_options MODIFY dhcp6_subnet_id INT UNSIGNED;
+
+# Update the schema version number
+UPDATE schema_version
+SET version = '5', minor = '2';
+
+# This line concludes database upgrade to version 5.2.
+
 # Notes:
 #
 # Indexes
diff --git a/src/share/database/scripts/mysql/upgrade_5.1_to_5.2.sh.in b/src/share/database/scripts/mysql/upgrade_5.1_to_5.2.sh.in
new file mode 100644 (file)
index 0000000..b692f69
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+# Include utilities. Use installed version if available and
+# use build version if it isn't.
+if [ -e @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh ]; then
+    . @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh
+else
+    . @abs_top_builddir@/src/bin/admin/admin-utils.sh
+fi
+
+VERSION=`mysql_version "$@"`
+
+if [ "$VERSION" != "5.1" ]; then
+    printf "This script upgrades 5.1 to 5.2. Reported version is $VERSION. Skipping upgrade.\n"
+    exit 0
+fi
+
+mysql "$@" <<EOF
+
+# Make subnet_id column types consistent with lease table columns
+ALTER TABLE dhcp4_options MODIFY dhcp4_subnet_id INT UNSIGNED;
+ALTER TABLE dhcp6_options MODIFY dhcp6_subnet_id INT UNSIGNED;
+
+# Update the schema version number
+UPDATE schema_version
+SET version = '5', minor = '2';
+# This line concludes database upgrade to version 5.2.
+
+EOF
+
+RESULT=$?
+
+exit $?
index 2bf6d129480e456e51a86c0677a9c74fdb7acdc7..20d673cddac93dc71faaf9298349a510963d55ca 100644 (file)
@@ -2,3 +2,4 @@ upgrade_1.0_to_2.0.sh
 upgrade_2.0_to_3.0.sh
 upgrade_3.0_to_3.1.sh
 upgrade_3.1_to_3.2.sh
+upgrade_3.2_to_3.3.sh
index 3c845dec77edfed4538fc09e119ba2a0bcefde90..8a914a280d0a9dec10403310b11b4161b8963f7a 100644 (file)
@@ -7,10 +7,12 @@ sqlscripts_DATA += upgrade_1.0_to_2.0.sh
 sqlscripts_DATA += upgrade_2.0_to_3.0.sh
 sqlscripts_DATA += upgrade_3.0_to_3.1.sh
 sqlscripts_DATA += upgrade_3.1_to_3.2.sh
+sqlscripts_DATA += upgrade_3.2_to_3.3.sh
 
 DISTCLEANFILES = upgrade_1.0_to_2.0.sh
 DISTCLEANFILES += upgrade_2.0_to_3.0.sh
 DISTCLEANFILES += upgrade_3.0_to_3.1.sh
 DISTCLEANFILES += upgrade_3.1_to_3.2.sh
+DISTCLEANFILES += upgrade_3.2_to_3.3.sh
 
 EXTRA_DIST = ${sqlscripts_DATA}
index 3597b7334051f1859709ebe8ab3344853df38054..af1e27bf3c4d6f024e14e48e104670423f2a2908 100644 (file)
@@ -493,7 +493,7 @@ INSERT INTO host_identifier_type VALUES (4, 'flex-id');
 UPDATE schema_version
     SET version = '3', minor = '1';
 
--- Set 3.2 schema version.
+-- Schema 3.1 specification ends here.
 
 -- Remove constraints which perform too restrictive checks on the inserted
 -- host reservations. We want to be able to insert host reservations which
@@ -528,8 +528,22 @@ CREATE UNIQUE INDEX key_dhcp6_identifier_subnet_id ON hosts
 UPDATE schema_version
     SET version = '3', minor = '2';
 
+-- Schema 3.2 specification ends here.
+
+-- Change subnet ID columns type to BIGINT to match lease4/6 tables 
+ALTER TABLE hosts ALTER COLUMN dhcp4_subnet_id TYPE BIGINT;
+ALTER TABLE hosts ALTER COLUMN dhcp4_subnet_id TYPE BIGINT;
+
+ALTER TABLE dhcp4_options ALTER COLUMN dhcp4_subnet_id TYPE BIGINT;
+ALTER TABLE dhcp6_options ALTER COLUMN dhcp6_subnet_id TYPE BIGINT;
+
+-- Set 3.3 schema version.
+UPDATE schema_version
+    SET version = '3', minor = '3';
+
+-- Schema 3.3 specification ends here.
 
--- Commit the script transaction.
+-- Commit the script transaction
 COMMIT;
 
 -- Notes:
index 3e4c44c66abbe6846d0bc213adf4f0d1360f78df..3581ead6446b2d1efefd0beab2966a5c097c27d3 100644 (file)
@@ -10,8 +10,8 @@ fi
 
 VERSION=`pgsql_version "$@"`
 
-if [ "$VERSION" != "3.0" ]; then
-    printf "This script upgrades 3.0 to 3.1. Reported version is $VERSION. Skipping upgrade.\n"
+if [ "$VERSION" != "3.1" ]; then
+    printf "This script upgrades 3.1 to 3.2. Reported version is $VERSION. Skipping upgrade.\n"
     exit 0
 fi
 
diff --git a/src/share/database/scripts/pgsql/upgrade_3.2_to_3.3.sh.in b/src/share/database/scripts/pgsql/upgrade_3.2_to_3.3.sh.in
new file mode 100644 (file)
index 0000000..3b5fa60
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+# Include utilities. Use installed version if available and
+# use build version if it isn't.
+if [ -e @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh ]; then
+    . @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh
+else
+    . @abs_top_builddir@/src/bin/admin/admin-utils.sh
+fi
+
+VERSION=`pgsql_version "$@"`
+
+if [ "$VERSION" != "3.2" ]; then
+    printf "This script upgrades 3.2 to 3.3. Reported version is $VERSION. Skipping upgrade.\n"
+    exit 0
+fi
+
+psql "$@" >/dev/null <<EOF
+
+START TRANSACTION;
+
+-- Change subnet ID columns type to BIGINT to match lease4/6 tables 
+ALTER TABLE hosts ALTER COLUMN dhcp4_subnet_id TYPE BIGINT;
+ALTER TABLE hosts ALTER COLUMN dhcp4_subnet_id TYPE BIGINT;
+
+ALTER TABLE dhcp4_options ALTER COLUMN dhcp4_subnet_id TYPE BIGINT;
+ALTER TABLE dhcp6_options ALTER COLUMN dhcp6_subnet_id TYPE BIGINT;
+
+-- Set 3.3 schema version.
+UPDATE schema_version
+    SET version = '3', minor = '3';
+
+-- Schema 3.3 specification ends here.
+
+-- Commit the script transaction
+COMMIT;
+
+EOF
+
+exit $RESULT