summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Markwalder <tmark@isc.org>2024-12-10 14:41:48 +0100
committerThomas Markwalder <tmark@isc.org>2024-12-16 16:31:44 +0100
commit1e6f4b4aa38732e649485040846a2a98d72d4e23 (patch)
tree48ef22543af4b895d65ebf2b96a1ffb575ddbe09
parent[#3663] PgSql CB hook supports ddsn-ttl params (diff)
downloadkea-1e6f4b4aa38732e649485040846a2a98d72d4e23.tar.xz
kea-1e6f4b4aa38732e649485040846a2a98d72d4e23.zip
[#3663] Add ddns ttl columns to pgsql schema
src/share/database/scripts/pgsql/upgrade_027_to_028.sh.in new file - adds ddns-ttl* columns to network and subnet tables src/bin/admin/tests/pgsql_tests.sh.in pgsql_upgrade_27_to_28_test() - new test src/lib/pgsql/pgsql_connection.h schema version bump configure.ac src/share/database/scripts/pgsql/.gitignore src/share/database/scripts/pgsql/Makefile.am added new upgrade file src/share/database/scripts/pgsql/dhcpdb_create.pgsql Add ddns-ttl* columns to network and subnet tables
-rw-r--r--configure.ac2
-rw-r--r--src/bin/admin/tests/pgsql_tests.sh.in34
-rw-r--r--src/lib/pgsql/pgsql_connection.h2
-rw-r--r--src/share/database/scripts/pgsql/.gitignore1
-rw-r--r--src/share/database/scripts/pgsql/Makefile.am1
-rw-r--r--src/share/database/scripts/pgsql/dhcpdb_create.pgsql34
-rw-r--r--src/share/database/scripts/pgsql/upgrade_027_to_028.sh.in75
7 files changed, 146 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac
index 8b19d20ac6..8f6760e25c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1895,6 +1895,8 @@ AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_025_to_026.sh],
[chmod +x src/share/database/scripts/pgsql/upgrade_025_to_026.sh])
AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_026_to_027.sh],
[chmod +x src/share/database/scripts/pgsql/upgrade_026_to_027.sh])
+AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_027_to_028.sh],
+ [chmod +x src/share/database/scripts/pgsql/upgrade_027_to_028.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 d9620c8d2f..55acd51fff 100644
--- a/src/bin/admin/tests/pgsql_tests.sh.in
+++ b/src/bin/admin/tests/pgsql_tests.sh.in
@@ -155,7 +155,7 @@ pgsql_db_version_test() {
run_command \
"${kea_admin}" db-version pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}"
version="${OUTPUT}"
- assert_str_eq "27.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
+ assert_str_eq "28.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
# Let's wipe the whole database
pgsql_wipe
@@ -1083,6 +1083,33 @@ pgsql_upgrade_26_to_27_test() {
check_table_column client_classes dhcp6_pd_pool
}
+pgsql_upgrade_27_to_28_test() {
+
+ # check ddns ttl fields were added to dhcp4_shared_network
+ check_table_column ddns_ttl_percent dhcp4_shared_network
+ check_table_column ddns_ttl dhcp4_shared_network
+ check_table_column ddns_ttl_min dhcp4_shared_network
+ check_table_column ddns_ttl_max dhcp4_shared_network
+
+ # check ddns ttl fields were added to dhcp4_subnet
+ check_table_column ddns_ttl_percent dhcp4_subnet
+ check_table_column ddns_ttl dhcp4_subnet
+ check_table_column ddns_ttl_min dhcp4_subnet
+ check_table_column ddns_ttl_max dhcp4_subnet
+
+ # check ddns ttl fields were added to dhcp6_shared_network
+ check_table_column ddns_ttl_percent dhcp6_shared_network
+ check_table_column ddns_ttl dhcp6_shared_network
+ check_table_column ddns_ttl_min dhcp6_shared_network
+ check_table_column ddns_ttl_max dhcp6_shared_network
+
+ # check ddns ttl fields were added to dhcp6_subnet
+ check_table_column ddns_ttl_percent dhcp6_subnet
+ check_table_column ddns_ttl dhcp6_subnet
+ check_table_column ddns_ttl_min dhcp6_subnet
+ check_table_column ddns_ttl_max dhcp6_subnet
+}
+
pgsql_upgrade_test() {
test_start "pgsql.upgrade"
@@ -1101,7 +1128,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 "27.0" "${version}" 'Expected kea-admin to return %s, returned value was %s'
+ assert_str_eq "28.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
@@ -1175,6 +1202,9 @@ pgsql_upgrade_test() {
# Check 26 to 27 upgrade
pgsql_upgrade_26_to_27_test
+ # Check 27 to 28 upgrade
+ pgsql_upgrade_27_to_28_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 73cad71426..aeae99f503 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 = 27;
+const uint32_t PGSQL_SCHEMA_VERSION_MAJOR = 28;
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 f77ce459a0..50299b57e0 100644
--- a/src/share/database/scripts/pgsql/.gitignore
+++ b/src/share/database/scripts/pgsql/.gitignore
@@ -30,4 +30,5 @@
/upgrade_024_to_025.sh
/upgrade_025_to_026.sh
/upgrade_026_to_027.sh
+/upgrade_027_to_028.sh
/wipe_data.sh
diff --git a/src/share/database/scripts/pgsql/Makefile.am b/src/share/database/scripts/pgsql/Makefile.am
index 25614f3b3a..c0b6f9504d 100644
--- a/src/share/database/scripts/pgsql/Makefile.am
+++ b/src/share/database/scripts/pgsql/Makefile.am
@@ -41,6 +41,7 @@ pgsql_SCRIPTS += upgrade_023_to_024.sh
pgsql_SCRIPTS += upgrade_024_to_025.sh
pgsql_SCRIPTS += upgrade_025_to_026.sh
pgsql_SCRIPTS += upgrade_026_to_027.sh
+pgsql_SCRIPTS += upgrade_027_to_028.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 0350ce87bc..83ec6969da 100644
--- a/src/share/database/scripts/pgsql/dhcpdb_create.pgsql
+++ b/src/share/database/scripts/pgsql/dhcpdb_create.pgsql
@@ -6588,6 +6588,40 @@ SELECT set_config('kea.disable_audit', 'false', false);
UPDATE schema_version
SET version = '27', minor = '0';
+-- This line concludes the schema upgrade to version 27.0.
+
+-- This line starts the schema upgrade to version 28.0.
+
+ALTER TABLE dhcp4_shared_network
+ ADD COLUMN ddns_ttl_percent FLOAT DEFAULT NULL,
+ ADD COLUMN ddns_ttl BIGINT DEFAULT NULL,
+ ADD COLUMN ddns_ttl_min BIGINT DEFAULT NULL,
+ ADD COLUMN ddns_ttl_max BIGINT DEFAULT NULL;
+
+ALTER TABLE dhcp4_subnet
+ ADD COLUMN ddns_ttl_percent FLOAT DEFAULT NULL,
+ ADD COLUMN ddns_ttl BIGINT DEFAULT NULL,
+ ADD COLUMN ddns_ttl_min BIGINT DEFAULT NULL,
+ ADD COLUMN ddns_ttl_max BIGINT DEFAULT NULL;
+
+ALTER TABLE dhcp6_shared_network
+ ADD COLUMN ddns_ttl_percent FLOAT DEFAULT NULL,
+ ADD COLUMN ddns_ttl BIGINT DEFAULT NULL,
+ ADD COLUMN ddns_ttl_min BIGINT DEFAULT NULL,
+ ADD COLUMN ddns_ttl_max BIGINT DEFAULT NULL;
+
+ALTER TABLE dhcp6_subnet
+ ADD COLUMN ddns_ttl_percent FLOAT DEFAULT NULL,
+ ADD COLUMN ddns_ttl BIGINT DEFAULT NULL,
+ ADD COLUMN ddns_ttl_min BIGINT DEFAULT NULL,
+ ADD COLUMN ddns_ttl_max BIGINT DEFAULT NULL;
+
+-- Update the schema version number.
+UPDATE schema_version
+ SET version = '28', minor = '0';
+
+-- This line concludes the schema upgrade to version 28.0.
+
-- Commit the script transaction.
COMMIT;
diff --git a/src/share/database/scripts/pgsql/upgrade_027_to_028.sh.in b/src/share/database/scripts/pgsql/upgrade_027_to_028.sh.in
new file mode 100644
index 0000000000..f7ce30550f
--- /dev/null
+++ b/src/share/database/scripts/pgsql/upgrade_027_to_028.sh.in
@@ -0,0 +1,75 @@
+#!/bin/sh
+
+# Copyright (C) 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" != "27.0" ]; then
+ printf 'This script upgrades 27.0 to 28.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 28.0.
+
+ALTER TABLE dhcp4_shared_network
+ ADD COLUMN ddns_ttl_percent FLOAT DEFAULT NULL,
+ ADD COLUMN ddns_ttl BIGINT DEFAULT NULL,
+ ADD COLUMN ddns_ttl_min BIGINT DEFAULT NULL,
+ ADD COLUMN ddns_ttl_max BIGINT DEFAULT NULL;
+
+ALTER TABLE dhcp4_subnet
+ ADD COLUMN ddns_ttl_percent FLOAT DEFAULT NULL,
+ ADD COLUMN ddns_ttl BIGINT DEFAULT NULL,
+ ADD COLUMN ddns_ttl_min BIGINT DEFAULT NULL,
+ ADD COLUMN ddns_ttl_max BIGINT DEFAULT NULL;
+
+ALTER TABLE dhcp6_shared_network
+ ADD COLUMN ddns_ttl_percent FLOAT DEFAULT NULL,
+ ADD COLUMN ddns_ttl BIGINT DEFAULT NULL,
+ ADD COLUMN ddns_ttl_min BIGINT DEFAULT NULL,
+ ADD COLUMN ddns_ttl_max BIGINT DEFAULT NULL;
+
+ALTER TABLE dhcp6_subnet
+ ADD COLUMN ddns_ttl_percent FLOAT DEFAULT NULL,
+ ADD COLUMN ddns_ttl BIGINT DEFAULT NULL,
+ ADD COLUMN ddns_ttl_min BIGINT DEFAULT NULL,
+ ADD COLUMN ddns_ttl_max BIGINT DEFAULT NULL;
+
+-- Update the schema version number.
+UPDATE schema_version
+ SET version = '28', minor = '0';
+
+-- This line concludes the schema upgrade to version 28.0.
+
+-- Commit the script transaction.
+COMMIT;
+
+EOF