]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2957] Fix dhcp4_server_modification_ts index
authorThomas Markwalder <tmark@isc.org>
Thu, 18 Apr 2024 18:33:11 +0000 (18:33 +0000)
committerThomas Markwalder <tmark@isc.org>
Mon, 22 Apr 2024 11:24:32 +0000 (11:24 +0000)
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

configure.ac
src/bin/admin/tests/pgsql_tests.sh.in
src/lib/pgsql/pgsql_connection.h
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_020_to_021.sh.in [new file with mode: 0644]

index 4e6bfd4bd2165f099e08a5acb264d8e5ad7eecad..a1574b065b949ac9e26fc1ecccf3c399019774ac 100644 (file)
@@ -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])
index 2f9404a7747571ca66db8eeed98cf1491c2a1e0b..f710bf8fbb5e8f46ebc66339ca966808bdf015b8 100644 (file)
@@ -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
 
index 6290b1ec0950195a04336d2b90d8f0e524fb8528..09c432ff64fd53fbd8081d5fff5067519bb1a997 100644 (file)
@@ -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
index b4156d8989c301e2562491981016e7e9e405b475..b8e0b819f2aa377c706e293d7215348dda5f1924 100644 (file)
@@ -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
index 32685c44e52239ac17421a6eaa4ccf8721198e04..a7049a4c96afcd58faf3d0e42ca85439c4858dfa 100644 (file)
@@ -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}
index 36502129f33e5b8ef4c175e835a5763dd0c2bab8..bececdcd769b94591ac52df445ee6df33042c00b 100644 (file)
@@ -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 (file)
index 0000000..65b2e04
--- /dev/null
@@ -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 <<EOF
+START TRANSACTION;
+
+-- 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;
+
+EOF