From: Marcin Siodelski Date: Fri, 14 Apr 2017 21:39:13 +0000 (+0200) Subject: [5102] Updated MySQL and PgSQL schemas with 'client-id' host id type. X-Git-Tag: trac5243x_base~13^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec873ef2f25781dab2deb9dbb5071a219d0fef15;p=thirdparty%2Fkea.git [5102] Updated MySQL and PgSQL schemas with 'client-id' host id type. --- diff --git a/configure.ac b/configure.ac index 19ee2e9349..11fea24719 100644 --- a/configure.ac +++ b/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 ]) diff --git a/src/bin/admin/tests/mysql_tests.sh.in b/src/bin/admin/tests/mysql_tests.sh.in index b6eec8c56b..6074b464af 100644 --- a/src/bin/admin/tests/mysql_tests.sh.in +++ b/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 diff --git a/src/bin/admin/tests/pgsql_tests.sh.in b/src/bin/admin/tests/pgsql_tests.sh.in index 660550ce52..5ed6e92f93 100644 --- a/src/bin/admin/tests/pgsql_tests.sh.in +++ b/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 diff --git a/src/lib/dhcpsrv/mysql_connection.h b/src/lib/dhcpsrv/mysql_connection.h index 6340e7e572..d2559c534c 100644 --- a/src/lib/dhcpsrv/mysql_connection.h +++ b/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; //@} diff --git a/src/lib/dhcpsrv/pgsql_connection.h b/src/lib/dhcpsrv/pgsql_connection.h index f915001238..9788972535 100644 --- a/src/lib/dhcpsrv/pgsql_connection.h +++ b/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 diff --git a/src/share/database/scripts/mysql/.gitignore b/src/share/database/scripts/mysql/.gitignore index 24f5157980..f4c4eb0e8b 100644 --- a/src/share/database/scripts/mysql/.gitignore +++ b/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 diff --git a/src/share/database/scripts/mysql/dhcpdb_create.mysql b/src/share/database/scripts/mysql/dhcpdb_create.mysql index 50577d7340..a6bb30f14d 100644 --- a/src/share/database/scripts/mysql/dhcpdb_create.mysql +++ b/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 diff --git a/src/share/database/scripts/mysql/upgrade_5.0_to_5.1.sh.in b/src/share/database/scripts/mysql/upgrade_5.0_to_5.1.sh.in new file mode 100644 index 0000000000..86385baddd --- /dev/null +++ b/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 "$@" < 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; diff --git a/src/share/database/scripts/pgsql/upgrade_3.0_to_3.1.sh.in b/src/share/database/scripts/pgsql/upgrade_3.0_to_3.1.sh.in new file mode 100644 index 0000000000..a65b28250e --- /dev/null +++ b/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 < 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 +