[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])
}
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"
# 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
# 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
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
/upgrade_017_to_018.sh
/upgrade_018_to_019.sh
/upgrade_019_to_020.sh
+/upgrade_020_to_021.sh
/wipe_data.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}
-- 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;
--- /dev/null
+#!/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