From: Thomas Markwalder Date: Thu, 18 Apr 2024 18:33:11 +0000 (+0000) Subject: [#2957] Fix dhcp4_server_modification_ts index X-Git-Tag: Kea-2.5.8~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f04c101f64bbb3ee3bc7d16f78244bffad660a48;p=thirdparty%2Fkea.git [#2957] Fix dhcp4_server_modification_ts index src/share/database/scripts/pgsql/upgrade_020_to_021.sh.in - new file, corrects dhcp4_server_modifcation_ts index configure.ac added src/share/database/scripts/pgsql/upgrade_020_to_021.sh src/bin/admin/tests/pgsql_tests.sh.in Added pgsql_upgrade_20_to_21_test() src/lib/pgsql/pgsql_connection.h Updated schema version src/share/database/scripts/pgsql/.gitignore src/share/database/scripts/pgsql/Makefile.am Added upgrade_020_to_021.sh src/share/database/scripts/pgsql/dhcpdb_create.pgsql Added correction of dhcp4_server_modifcation_ts index --- diff --git a/configure.ac b/configure.ac index 4e6bfd4bd2..a1574b065b 100644 --- a/configure.ac +++ b/configure.ac @@ -1800,6 +1800,8 @@ AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_018_to_019.sh], [chmod +x src/share/database/scripts/pgsql/upgrade_018_to_019.sh]) AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_019_to_020.sh], [chmod +x src/share/database/scripts/pgsql/upgrade_019_to_020.sh]) +AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_020_to_021.sh], + [chmod +x src/share/database/scripts/pgsql/upgrade_020_to_021.sh]) AC_CONFIG_FILES([src/share/database/scripts/pgsql/wipe_data.sh], [chmod +x src/share/database/scripts/pgsql/wipe_data.sh]) AC_CONFIG_FILES([src/share/yang/Makefile]) diff --git a/src/bin/admin/tests/pgsql_tests.sh.in b/src/bin/admin/tests/pgsql_tests.sh.in index 2f9404a774..f710bf8fbb 100644 --- a/src/bin/admin/tests/pgsql_tests.sh.in +++ b/src/bin/admin/tests/pgsql_tests.sh.in @@ -888,10 +888,27 @@ pgsql_upgrade_18_to_19_test() { } pgsql_upgrade_19_to_20_test() { - # For now this function only verifies version number. - version=$("${kea_admin}" db-version pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}") - assert_str_eq "20.0" "${version}" 'Expected kea-admin to return %s, returned value was %s' + # Verify that lease6_by_sunet_id_address index on lease6 is keyed by + # attributes number 5 and 1 (i.e. subnet-id and address) + qry="select ix.indkey as keys from pg_class t, pg_class i, pg_index ix \ + where t.oid = ix.indrelid and i.oid = ix.indexrelid and \ + i.relname = 'lease6_by_subnet_id_address' and t.relname = 'lease6';" + run_statement "verify lease6_by_subnet_id_address" "$qry" + assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq '5 1' "${OUTPUT}" "${query}: expected output %s, returned %s" } + +pgsql_upgrade_20_to_21_test() { + # Verify that dhcp4_server_modification_ts index on dhcp4_server is keyed by + # attribute number 4, modification_ts + qry="select ix.indkey as keys from pg_class t, pg_class i, pg_index ix \ + where t.oid = ix.indrelid and i.oid = ix.indexrelid and \ + i.relname = 'dhcp4_server_modification_ts' and t.relname = 'dhcp4_server';" + run_statement "verify lease6_by_subnet_id_address" "$qry" + assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" + assert_str_eq '4' "${OUTPUT}" "${query}: expected output %s, returned %s" +} + pgsql_upgrade_test() { test_start "pgsql.upgrade" @@ -910,7 +927,7 @@ pgsql_upgrade_test() { # Verify upgraded schema reports the latest version. version=$("${kea_admin}" db-version pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}") - assert_str_eq "20.0" "${version}" 'Expected kea-admin to return %s, returned value was %s' + assert_str_eq "21.0" "${version}" 'Expected kea-admin to return %s, returned value was %s' # Check 1.0 to 2.0 upgrade pgsql_upgrade_1_0_to_2_0_test @@ -966,6 +983,9 @@ pgsql_upgrade_test() { # Check 19 to 20 upgrade pgsql_upgrade_19_to_20_test + # Check 20 to 21 upgrade + pgsql_upgrade_20_to_21_test + # Let's wipe the whole database pgsql_wipe diff --git a/src/lib/pgsql/pgsql_connection.h b/src/lib/pgsql/pgsql_connection.h index 6290b1ec09..09c432ff64 100644 --- a/src/lib/pgsql/pgsql_connection.h +++ b/src/lib/pgsql/pgsql_connection.h @@ -18,7 +18,7 @@ namespace isc { namespace db { /// @brief Define the PostgreSQL backend version. -const uint32_t PGSQL_SCHEMA_VERSION_MAJOR = 20; +const uint32_t PGSQL_SCHEMA_VERSION_MAJOR = 21; const uint32_t PGSQL_SCHEMA_VERSION_MINOR = 0; // Maximum number of parameters that can be used a statement diff --git a/src/share/database/scripts/pgsql/.gitignore b/src/share/database/scripts/pgsql/.gitignore index b4156d8989..b8e0b819f2 100644 --- a/src/share/database/scripts/pgsql/.gitignore +++ b/src/share/database/scripts/pgsql/.gitignore @@ -23,4 +23,5 @@ /upgrade_017_to_018.sh /upgrade_018_to_019.sh /upgrade_019_to_020.sh +/upgrade_020_to_021.sh /wipe_data.sh diff --git a/src/share/database/scripts/pgsql/Makefile.am b/src/share/database/scripts/pgsql/Makefile.am index 32685c44e5..a7049a4c96 100644 --- a/src/share/database/scripts/pgsql/Makefile.am +++ b/src/share/database/scripts/pgsql/Makefile.am @@ -34,6 +34,7 @@ pgsql_SCRIPTS += upgrade_016_to_017.sh pgsql_SCRIPTS += upgrade_017_to_018.sh pgsql_SCRIPTS += upgrade_018_to_019.sh pgsql_SCRIPTS += upgrade_019_to_020.sh +pgsql_SCRIPTS += upgrade_020_to_021.sh pgsql_SCRIPTS += wipe_data.sh DISTCLEANFILES = ${pgsql_SCRIPTS} diff --git a/src/share/database/scripts/pgsql/dhcpdb_create.pgsql b/src/share/database/scripts/pgsql/dhcpdb_create.pgsql index 36502129f3..bececdcd76 100644 --- a/src/share/database/scripts/pgsql/dhcpdb_create.pgsql +++ b/src/share/database/scripts/pgsql/dhcpdb_create.pgsql @@ -6325,6 +6325,18 @@ UPDATE schema_version -- This line concludes the schema upgrade to version 20.0. +-- This line starts the schema upgrade to version 21.0. + +-- Correct dhcp4_server_modifcation_ts to index the dhcp4_server table. +DROP INDEX dhcp4_server_modification_ts; +CREATE INDEX dhcp4_server_modification_ts ON dhcp4_server (modification_ts); + +-- Update the schema version number. +UPDATE schema_version + SET version = '21', minor = '0'; + +-- This line concludes the schema upgrade to version 21.0. + -- Commit the script transaction. COMMIT; diff --git a/src/share/database/scripts/pgsql/upgrade_020_to_021.sh.in b/src/share/database/scripts/pgsql/upgrade_020_to_021.sh.in new file mode 100644 index 0000000000..65b2e0496e --- /dev/null +++ b/src/share/database/scripts/pgsql/upgrade_020_to_021.sh.in @@ -0,0 +1,55 @@ +#!/bin/sh + +# Copyright (C) 2023-2024 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 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# Exit with error if commands exit with non-zero and if undefined variables are +# used. +set -eu + +# shellcheck disable=SC2034 +# SC2034: ... appears unused. Verify use (or export if used externally). +prefix="@prefix@" + +# Include utilities based on location of this script. Check for sources first, +# so that the unexpected situations with weird paths fall on the default +# case of installed. +script_path=$(cd "$(dirname "${0}")" && pwd) +if test "${script_path}" = "@abs_top_builddir@/src/share/database/scripts/pgsql"; then + # shellcheck source=./src/bin/admin/admin-utils.sh.in + . "@abs_top_builddir@/src/bin/admin/admin-utils.sh" +else + # shellcheck source=./src/bin/admin/admin-utils.sh.in + . "@datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh" +fi + +VERSION=$(pgsql_version "$@") + +if [ "$VERSION" != "20.0" ]; then + printf 'This script upgrades 20.0 to 21.0. ' + printf 'Reported version is %s. Skipping upgrade.\n' "${VERSION}" + exit 0 +fi + +psql "$@" >/dev/null <