Parcourir la source

[5102] Updated MySQL and PgSQL schemas with 'client-id' host id type.

Marcin Siodelski il y a 8 ans
Parent
commit
ec873ef2f2

+ 2 - 0
configure.ac

@@ -1805,9 +1805,11 @@ AC_CONFIG_FILES([Makefile
                  src/share/database/scripts/mysql/upgrade_3.0_to_4.0.sh
                  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/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
                  tools/Makefile
                  tools/path_replacer.sh
 ])

+ 4 - 4
src/bin/admin/tests/mysql_tests.sh.in

@@ -193,7 +193,7 @@ mysql_upgrade_test() {
 
     assert_str_eq "1.0" ${version} "Expected kea-admin to return %s, returned value was %s"
 
-    # Ok, we have a 1.0 database. Let's upgrade it to 5.0
+    # Ok, we have a 1.0 database. Let's upgrade it to 5.1
     ${keaadmin} lease-upgrade mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
     ERRCODE=$?
 
@@ -300,7 +300,7 @@ EOF
     count=`mysql_execute "${qry}"`
     ERRCODE=$?
     assert_eq 0 $ERRCODE "select from host_identifier_type failed. (expected status code %d, returned %d)"
-    assert_eq 3 "$count" "host_identifier_type does not contain correct number of entries. (expected count %d, returned %d)"
+    assert_eq 4 "$count" "host_identifier_type does not contain correct number of entries. (expected count %d, returned %d)"
 
     # verify that foreign key fk_host_identifier_type exists
     qry="show create table hosts";
@@ -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.0
+    # Verify upgraded schema reports version 5.1
     version=$(${keaadmin} lease-version mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir)
-    assert_str_eq "5.0" ${version} "Expected kea-admin to return %s, returned value was %s"
+    assert_str_eq "5.1" ${version} "Expected kea-admin to return %s, returned value was %s"
 
     # Let's wipe the whole database
     mysql_wipe

+ 8 - 3
src/bin/admin/tests/pgsql_tests.sh.in

@@ -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.0" ${version} "Expected kea-admin to return %s, returned value was %s"
+    assert_str_eq "3.1" ${version} "Expected kea-admin to return %s, returned value was %s"
 
     # Let's wipe the whole database
     pgsql_wipe
@@ -197,10 +197,12 @@ pgsql_upgrade_2_0_to_3_0() {
     ERRCODE=$?
     assert_eq 0 $ERRCODE "select from lease_hwaddr_source failed. (expected status code %d, returned %d)"
     assert_eq 1 "$output" "lease_hwaddr_source does not contain entry for HWADDR_SOURCE_UKNOWN. (record count %d, expected %d)"
+}
 
-    # Verify upgraded schemd reports version 3.0.
+pgsql_upgrade_3_0_to_3_1() {
+    # Verify upgraded schemd reports version 3.1.
     version=$(${keaadmin} lease-version pgsql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir)
-    assert_str_eq "3.0" ${version} "Expected kea-admin to return %s, returned value was %s"
+    assert_str_eq "3.1" ${version} "Expected kea-admin to return %s, returned value was %s"
 }
 
 pgsql_upgrade_test() {
@@ -222,6 +224,9 @@ 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
+
     # Let's wipe the whole database
     pgsql_wipe
 

+ 2 - 2
src/lib/dhcpsrv/mysql_connection.h

@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -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 = 0;
+const uint32_t MYSQL_SCHEMA_VERSION_MINOR = 1;
 
 //@}
 

+ 1 - 1
src/lib/dhcpsrv/pgsql_connection.h

@@ -19,7 +19,7 @@ namespace dhcp {
 
 /// @brief Define PostgreSQL backend version: 3.0
 const uint32_t PG_SCHEMA_VERSION_MAJOR = 3;
-const uint32_t PG_SCHEMA_VERSION_MINOR = 0;
+const uint32_t PG_SCHEMA_VERSION_MINOR = 1;
 
 // Maximum number of parameters that can be used a statement
 // @todo This allows us to use an initializer list (since we can't

+ 1 - 0
src/share/database/scripts/mysql/.gitignore

@@ -3,3 +3,4 @@
 /upgrade_3.0_to_4.0.sh
 /upgrade_4.0_to_4.1.sh
 /upgrade_4.1_to_5.0.sh
+/upgrade_5.0_to_5.1.sh

+ 16 - 3
src/share/database/scripts/mysql/dhcpdb_create.mysql

@@ -420,9 +420,9 @@ CREATE TABLE IF NOT EXISTS host_identifier_type (
 ) ENGINE = INNODB;
 
 START TRANSACTION;
-INSERT INTO host_identifier_type VALUES (0, 'hw-address'); # Non-temporary v6 addresses
-INSERT INTO host_identifier_type VALUES (1, 'duid');       # Temporary v6 addresses
-INSERT INTO host_identifier_type VALUES (2, 'circuit-id'); # Prefix delegations
+INSERT INTO host_identifier_type VALUES (0, 'hw-address');
+INSERT INTO host_identifier_type VALUES (1, 'duid');
+INSERT INTO host_identifier_type VALUES (2, 'circuit-id');
 COMMIT;
 
 # Add a constraint that any identifier type value added to the hosts
@@ -480,6 +480,19 @@ UPDATE schema_version
 SET version = '5', minor = '0';
 # This line concludes database upgrade to version 5.0.
 
+# Add indexes for lease tables which will be used to perform searches
+# for all leases by subnet id.
+CREATE INDEX lease4_subnet_id ON lease4 (subnet_id ASC);
+CREATE INDEX lease6_subnet_id ON lease6 (subnet_id ASC);
+
+# Add missing 'client-id' host identifier type.
+INSERT INTO host_identifier_type VALUES (3, 'client-id');
+
+# Update the schema version number
+UPDATE schema_version
+SET version = '5', minor = '1';
+# This line concludes database upgrade to version 5.1.
+
 # Notes:
 #
 # Indexes

+ 32 - 0
src/share/database/scripts/mysql/upgrade_5.0_to_5.1.sh.in

@@ -0,0 +1,32 @@
+#!/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.0" ]; then
+    printf "This script upgrades 5.0 to 5.1. Reported version is $VERSION. Skipping upgrade.\n"
+    exit 0
+fi
+
+mysql "$@" <<EOF
+
+# Add missing 'client-id' host identifier type.
+INSERT INTO host_identifier_type VALUES (3, 'client-id');
+
+# Update the schema version number
+UPDATE schema_version
+SET version = '5', minor = '1';
+# This line concludes database upgrade to version 5.1.
+
+EOF
+
+RESULT=$?
+
+exit $?

+ 1 - 0
src/share/database/scripts/pgsql/.gitignore

@@ -1,2 +1,3 @@
 upgrade_1.0_to_2.0.sh
 upgrade_2.0_to_3.0.sh
+upgrade_3.0_to_3.1.sh

+ 11 - 0
src/share/database/scripts/pgsql/dhcpdb_create.pgsql

@@ -483,6 +483,17 @@ UPDATE schema_version
 
 -- Schema 3.0 specification ends here.
 
+-- This is a placeholder for the changes between 3.0 and 3.1. Even if there
+-- are no further changes the schema version should be set to 3.1, because
+-- we have added a missing 'client-id' host reservation type entry in the
+-- 3.0 -> 3.1 upgrade script. This entry had been accidentally omitted when
+-- the 2.0 -> 3.0 upgrade script was created.
+
+-- Set 3.1 schema version.
+UPDATE schema_version
+    SET version = '3', minor = '1';
+
+
 -- Commit the script transaction.
 COMMIT;
 

+ 47 - 0
src/share/database/scripts/pgsql/upgrade_3.0_to_3.1.sh.in

@@ -0,0 +1,47 @@
+#!/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.0" ]; then
+    printf "This script upgrades 3.0 to 3.1. Reported version is $VERSION. Skipping upgrade.\n"
+    exit 0
+fi
+
+psql "$@" >/dev/null <<EOF
+
+START TRANSACTION;
+
+-- Upgrade to schema 3.1 begins here:
+
+-- The 'client-id' host identifier type was missing in the
+-- 2.0 -> 3.0 upgrade script. However, it was present in the
+-- dhcpdb_create.pgsql file. This means that this entry may
+-- or may not be present. By the conditional insert below we
+-- will only insert it if it doesn't exist.
+INSERT INTO host_identifier_type (type, name)
+  SELECT 3, 'client-id'
+    WHERE NOT EXISTS (
+        SELECT type FROM host_identifier_type WHERE type = 3
+    );
+
+-- Set 3.1 schema version.
+UPDATE schema_version
+    SET version = '3', minor = '1';
+
+-- Schema 3.1 specification ends here.
+
+-- Commit the script transaction
+COMMIT;
+
+EOF
+
+exit $RESULT
+