Skip to content

Commit f04c101

Browse files
committed
[#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
1 parent ed680fd commit f04c101

File tree

7 files changed

+96
-5
lines changed

7 files changed

+96
-5
lines changed

configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,8 @@ AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_018_to_019.sh],
18001800
[chmod +x src/share/database/scripts/pgsql/upgrade_018_to_019.sh])
18011801
AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_019_to_020.sh],
18021802
[chmod +x src/share/database/scripts/pgsql/upgrade_019_to_020.sh])
1803+
AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_020_to_021.sh],
1804+
[chmod +x src/share/database/scripts/pgsql/upgrade_020_to_021.sh])
18031805
AC_CONFIG_FILES([src/share/database/scripts/pgsql/wipe_data.sh],
18041806
[chmod +x src/share/database/scripts/pgsql/wipe_data.sh])
18051807
AC_CONFIG_FILES([src/share/yang/Makefile])

src/bin/admin/tests/pgsql_tests.sh.in

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -888,10 +888,27 @@ pgsql_upgrade_18_to_19_test() {
888888
}
889889

890890
pgsql_upgrade_19_to_20_test() {
891-
# For now this function only verifies version number.
892-
version=$("${kea_admin}" db-version pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}")
893-
assert_str_eq "20.0" "${version}" 'Expected kea-admin to return %s, returned value was %s'
891+
# Verify that lease6_by_sunet_id_address index on lease6 is keyed by
892+
# attributes number 5 and 1 (i.e. subnet-id and address)
893+
qry="select ix.indkey as keys from pg_class t, pg_class i, pg_index ix \
894+
where t.oid = ix.indrelid and i.oid = ix.indexrelid and \
895+
i.relname = 'lease6_by_subnet_id_address' and t.relname = 'lease6';"
896+
run_statement "verify lease6_by_subnet_id_address" "$qry"
897+
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
898+
assert_str_eq '5 1' "${OUTPUT}" "${query}: expected output %s, returned %s"
894899
}
900+
901+
pgsql_upgrade_20_to_21_test() {
902+
# Verify that dhcp4_server_modification_ts index on dhcp4_server is keyed by
903+
# attribute number 4, modification_ts
904+
qry="select ix.indkey as keys from pg_class t, pg_class i, pg_index ix \
905+
where t.oid = ix.indrelid and i.oid = ix.indexrelid and \
906+
i.relname = 'dhcp4_server_modification_ts' and t.relname = 'dhcp4_server';"
907+
run_statement "verify lease6_by_subnet_id_address" "$qry"
908+
assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
909+
assert_str_eq '4' "${OUTPUT}" "${query}: expected output %s, returned %s"
910+
}
911+
895912
pgsql_upgrade_test() {
896913
test_start "pgsql.upgrade"
897914

@@ -910,7 +927,7 @@ pgsql_upgrade_test() {
910927

911928
# Verify upgraded schema reports the latest version.
912929
version=$("${kea_admin}" db-version pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}")
913-
assert_str_eq "20.0" "${version}" 'Expected kea-admin to return %s, returned value was %s'
930+
assert_str_eq "21.0" "${version}" 'Expected kea-admin to return %s, returned value was %s'
914931

915932
# Check 1.0 to 2.0 upgrade
916933
pgsql_upgrade_1_0_to_2_0_test
@@ -966,6 +983,9 @@ pgsql_upgrade_test() {
966983
# Check 19 to 20 upgrade
967984
pgsql_upgrade_19_to_20_test
968985

986+
# Check 20 to 21 upgrade
987+
pgsql_upgrade_20_to_21_test
988+
969989
# Let's wipe the whole database
970990
pgsql_wipe
971991

src/lib/pgsql/pgsql_connection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace isc {
1818
namespace db {
1919

2020
/// @brief Define the PostgreSQL backend version.
21-
const uint32_t PGSQL_SCHEMA_VERSION_MAJOR = 20;
21+
const uint32_t PGSQL_SCHEMA_VERSION_MAJOR = 21;
2222
const uint32_t PGSQL_SCHEMA_VERSION_MINOR = 0;
2323

2424
// Maximum number of parameters that can be used a statement

src/share/database/scripts/pgsql/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@
2323
/upgrade_017_to_018.sh
2424
/upgrade_018_to_019.sh
2525
/upgrade_019_to_020.sh
26+
/upgrade_020_to_021.sh
2627
/wipe_data.sh

src/share/database/scripts/pgsql/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pgsql_SCRIPTS += upgrade_016_to_017.sh
3434
pgsql_SCRIPTS += upgrade_017_to_018.sh
3535
pgsql_SCRIPTS += upgrade_018_to_019.sh
3636
pgsql_SCRIPTS += upgrade_019_to_020.sh
37+
pgsql_SCRIPTS += upgrade_020_to_021.sh
3738
pgsql_SCRIPTS += wipe_data.sh
3839

3940
DISTCLEANFILES = ${pgsql_SCRIPTS}

src/share/database/scripts/pgsql/dhcpdb_create.pgsql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6325,6 +6325,18 @@ UPDATE schema_version
63256325

63266326
-- This line concludes the schema upgrade to version 20.0.
63276327

6328+
-- This line starts the schema upgrade to version 21.0.
6329+
6330+
-- Correct dhcp4_server_modifcation_ts to index the dhcp4_server table.
6331+
DROP INDEX dhcp4_server_modification_ts;
6332+
CREATE INDEX dhcp4_server_modification_ts ON dhcp4_server (modification_ts);
6333+
6334+
-- Update the schema version number.
6335+
UPDATE schema_version
6336+
SET version = '21', minor = '0';
6337+
6338+
-- This line concludes the schema upgrade to version 21.0.
6339+
63286340
-- Commit the script transaction.
63296341
COMMIT;
63306342

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/sh
2+
3+
# Copyright (C) 2023-2024 Internet Systems Consortium, Inc. ("ISC")
4+
#
5+
# This Source Code Form is subject to the terms of the Mozilla Public
6+
# License, v. 2.0. If a copy of the MPL was not distributed with this
7+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
8+
9+
# Exit with error if commands exit with non-zero and if undefined variables are
10+
# used.
11+
set -eu
12+
13+
# shellcheck disable=SC2034
14+
# SC2034: ... appears unused. Verify use (or export if used externally).
15+
prefix="@prefix@"
16+
17+
# Include utilities based on location of this script. Check for sources first,
18+
# so that the unexpected situations with weird paths fall on the default
19+
# case of installed.
20+
script_path=$(cd "$(dirname "${0}")" && pwd)
21+
if test "${script_path}" = "@abs_top_builddir@/src/share/database/scripts/pgsql"; then
22+
# shellcheck source=./src/bin/admin/admin-utils.sh.in
23+
. "@abs_top_builddir@/src/bin/admin/admin-utils.sh"
24+
else
25+
# shellcheck source=./src/bin/admin/admin-utils.sh.in
26+
. "@datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh"
27+
fi
28+
29+
VERSION=$(pgsql_version "$@")
30+
31+
if [ "$VERSION" != "20.0" ]; then
32+
printf 'This script upgrades 20.0 to 21.0. '
33+
printf 'Reported version is %s. Skipping upgrade.\n' "${VERSION}"
34+
exit 0
35+
fi
36+
37+
psql "$@" >/dev/null <<EOF
38+
START TRANSACTION;
39+
40+
-- This line starts the schema upgrade to version 21.0.
41+
42+
-- Correct dhcp4_server_modifcation_ts to index the dhcp4_server table.
43+
DROP INDEX dhcp4_server_modification_ts;
44+
CREATE INDEX dhcp4_server_modification_ts ON dhcp4_server (modification_ts);
45+
46+
-- Update the schema version number.
47+
UPDATE schema_version
48+
SET version = '21', minor = '0';
49+
50+
-- This line concludes the schema upgrade to version 21.0.
51+
52+
-- Commit the script transaction.
53+
COMMIT;
54+
55+
EOF

0 commit comments

Comments
 (0)