]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3583] add client_classes to option tables
authorThomas Markwalder <tmark@isc.org>
Mon, 30 Sep 2024 16:10:42 +0000 (12:10 -0400)
committerThomas Markwalder <tmark@isc.org>
Tue, 15 Oct 2024 17:51:57 +0000 (13:51 -0400)
/src/share/database/scripts/mysql/upgrade_025_to_026.sh.in
/src/share/database/scripts/pgsql/upgrade_025_to_026.sh.in
    - new files

/src/share/database/scripts/mysql/dhcpdb_create.mysql
/src/share/database/scripts/pgsql/dhcpdb_create.pgsql
    - adds client_classes to option tables

/configure.ac
/src/share/database/scripts/mysql/.gitignore
/src/share/database/scripts/mysql/Makefile.am
/src/share/database/scripts/pgsql/.gitignore
/src/share/database/scripts/pgsql/Makefile.am
    - added new upgrade files

/src/bin/admin/tests/pgsql_tests.sh.in
/src/bin/admin/tests/mysql_tests.sh.in
    - Updated for new schema 26

/src/lib/mysql/mysql_constants.h
/src/lib/pgsql/pgsql_connection.h
     Updated schema version

13 files changed:
configure.ac
src/bin/admin/tests/mysql_tests.sh.in
src/bin/admin/tests/pgsql_tests.sh.in
src/lib/mysql/mysql_constants.h
src/lib/pgsql/pgsql_connection.h
src/share/database/scripts/mysql/.gitignore
src/share/database/scripts/mysql/Makefile.am
src/share/database/scripts/mysql/dhcpdb_create.mysql
src/share/database/scripts/mysql/upgrade_025_to_026.sh.in [new file with mode: 0644]
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_025_to_026.sh.in [new file with mode: 0644]

index 0e44735fdf5028fad4dd5e1f6d02b2aa0d2a5a6e..9fc41611fcc7f13800a0366b86da7c134f3cae50 100644 (file)
@@ -1778,6 +1778,8 @@ AC_CONFIG_FILES([src/share/database/scripts/mysql/upgrade_023_to_024.sh],
                 [chmod +x src/share/database/scripts/mysql/upgrade_023_to_024.sh])
 AC_CONFIG_FILES([src/share/database/scripts/mysql/upgrade_024_to_025.sh],
                 [chmod +x src/share/database/scripts/mysql/upgrade_024_to_025.sh])
+AC_CONFIG_FILES([src/share/database/scripts/mysql/upgrade_025_to_026.sh],
+                [chmod +x src/share/database/scripts/mysql/upgrade_025_to_026.sh])
 AC_CONFIG_FILES([src/share/database/scripts/mysql/wipe_data.sh],
                 [chmod +x src/share/database/scripts/mysql/wipe_data.sh])
 AC_CONFIG_FILES([src/share/database/scripts/pgsql/Makefile])
@@ -1841,6 +1843,8 @@ AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_023_to_024.sh],
                 [chmod +x src/share/database/scripts/pgsql/upgrade_023_to_024.sh])
 AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_024_to_025.sh],
                 [chmod +x src/share/database/scripts/pgsql/upgrade_024_to_025.sh])
+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/wipe_data.sh],
                 [chmod +x src/share/database/scripts/pgsql/wipe_data.sh])
 AC_CONFIG_FILES([src/share/yang/Makefile])
index 648fddfc8eaf22b4aa44b92975118481dc357128..223e576f39bc60dd07696ab5840806e55e2020f9 100644 (file)
@@ -843,6 +843,20 @@ mysql_upgrade_24_to_25_test() {
     assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
 }
 
+mysql_upgrade_25_to_26_test() {
+    # client_classes been added to dhcp4_options 
+    qry="select client_classes from dhcp4_options limit 1"
+    run_command \
+        mysql_execute "${qry}"
+    assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
+
+    # client_classes been added to dhcp6_options 
+    qry="select client_classes from dhcp6_options limit 1"
+    run_command \
+        mysql_execute "${qry}"
+    assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
+}
+
 mysql_upgrade_test() {
 
     test_start "mysql.upgrade"
@@ -864,7 +878,7 @@ mysql_upgrade_test() {
 
     # Verify that the upgraded schema reports the latest version.
     version=$("${kea_admin}" db-version mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}")
-    assert_str_eq "25.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
+    assert_str_eq "26.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
 
     # Let's check that the new tables are indeed there.
 
@@ -1536,6 +1550,9 @@ SET @disable_audit = 0"
     # Check upgrade from 24.0 to 25.0.
     mysql_upgrade_24_to_25_test
 
+    # Check upgrade from 25.0 to 26.0.
+    mysql_upgrade_25_to_26_test
+
     # Let's wipe the whole database
     mysql_wipe
 
index 28fc8bd2030171a289ccba0dcf7f4d0af21a44ef..9de1bb47d8eb3cd4162e8babc00a6275c459a063 100644 (file)
@@ -142,7 +142,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 "25.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
+    assert_str_eq "26.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
 
     # Let's wipe the whole database
     pgsql_wipe
@@ -936,6 +936,20 @@ pgsql_upgrade_24_to_25_test() {
     assert_eq 0 "${EXIT_CODE}" "ipv6_reservations is missing excluded_prefix_len column. (expected status code %d, returned %d)"
 }
 
+pgsql_upgrade_25_to_26_test() {
+    # client_classes been added to dhcp4_options 
+    qry="select client_classes from dhcp4_options limit 1"
+    run_command \
+        pgsql_execute "${qry}"
+    assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
+
+    # client_classes been added to dhcp6_options 
+    qry="select client_classes from dhcp6_options limit 1"
+    run_command \
+        pgsql_execute "${qry}"
+    assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
+}
+
 pgsql_upgrade_test() {
     test_start "pgsql.upgrade"
 
@@ -954,7 +968,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 "25.0" "${version}" 'Expected kea-admin to return %s, returned value was %s'
+    assert_str_eq "26.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
@@ -1022,6 +1036,9 @@ pgsql_upgrade_test() {
     # Check 24 to 25 upgrade
     pgsql_upgrade_24_to_25_test
 
+    # Check 25 to 26 upgrade
+    pgsql_upgrade_25_to_26_test
+
     # Let's wipe the whole database
     pgsql_wipe
 
index 1ec71737a5bbadab791a3be1b9c3c2ef18c2e13c..8cdcbea4eff4a8cf8e0943ed9a963458c44ebe80 100644 (file)
@@ -52,7 +52,7 @@ const int MLM_MYSQL_FETCH_FAILURE = 0;
 
 /// @name Current database schema version values.
 //@{
-const uint32_t MYSQL_SCHEMA_VERSION_MAJOR = 25;
+const uint32_t MYSQL_SCHEMA_VERSION_MAJOR = 26;
 const uint32_t MYSQL_SCHEMA_VERSION_MINOR = 0;
 
 //@}
index 842539055cfe3951ed78a26836583db5854cc619..5667dd79276aef77b689d436d67ed409c253076c 100644 (file)
@@ -18,7 +18,7 @@ namespace isc {
 namespace db {
 
 /// @brief Define the PostgreSQL backend version.
-const uint32_t PGSQL_SCHEMA_VERSION_MAJOR = 25;
+const uint32_t PGSQL_SCHEMA_VERSION_MAJOR = 26;
 const uint32_t PGSQL_SCHEMA_VERSION_MINOR = 0;
 
 // Maximum number of parameters that can be used a statement
index 9cd5c0f4b67caf1dde2eb8d3a2c1734b67b4fba0..0b4c5489c90b24a0f76dcdbf28ef7ca703525f7c 100644 (file)
@@ -33,4 +33,5 @@
 /upgrade_022_to_023.sh
 /upgrade_023_to_024.sh
 /upgrade_024_to_025.sh
+/upgrade_025_to_026.sh
 /wipe_data.sh
index 4b7f238b15944b3e4ae6cdad196f9dc55a42160e..7bcaba65026ef1c8a049ce4fd79343a2b437e272 100644 (file)
@@ -44,6 +44,7 @@ mysql_SCRIPTS += upgrade_021_to_022.sh
 mysql_SCRIPTS += upgrade_022_to_023.sh
 mysql_SCRIPTS += upgrade_023_to_024.sh
 mysql_SCRIPTS += upgrade_024_to_025.sh
+mysql_SCRIPTS += upgrade_025_to_026.sh
 mysql_SCRIPTS += wipe_data.sh
 
 DISTCLEANFILES = ${mysql_SCRIPTS}
index 3eeb495a3df40507f48569d63294fba0eb621b32..9bd11a78bac50cf12d8460a02479998aad70115c 100644 (file)
@@ -6023,6 +6023,21 @@ UPDATE schema_version
 
 -- This line concludes the schema upgrade to version 25.0.
 
+-- This line starts the schema upgrade to version 26.0.
+
+-- Add client_classes column to options tables for option class taggging.
+ALTER TABLE dhcp4_options
+    ADD COLUMN client_classes LONGTEXT DEFAULT NULL;
+
+ALTER TABLE dhcp6_options
+    ADD COLUMN client_classes LONGTEXT DEFAULT NULL;
+
+-- Update the schema version number.
+UPDATE schema_version
+    SET version = '26', minor = '0';
+
+-- This line concludes the schema upgrade to version 26.0.
+
 # Notes:
 #
 # Indexes
diff --git a/src/share/database/scripts/mysql/upgrade_025_to_026.sh.in b/src/share/database/scripts/mysql/upgrade_025_to_026.sh.in
new file mode 100644 (file)
index 0000000..cc99a63
--- /dev/null
@@ -0,0 +1,71 @@
+#!/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/mysql"; 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
+
+# Check version.
+version=$(mysql_version "${@}")
+if test "${version}" != "25.0"; then
+    printf 'This script upgrades 25.0 to 26.0. '
+    printf 'Reported version is %s. Skipping upgrade.\n' "${version}"
+    exit 0
+fi
+
+# Get the schema name from database argument. We need this to
+# query information_schema for the right database.
+for arg in "${@}"
+do
+    if ! printf '%s' "${arg}" | grep -Eq -- '^--'
+    then
+        schema="$arg"
+        break
+    fi
+done
+
+# Make sure we have the schema.
+if [ -z "$schema" ]
+then
+    printf "Could not find database schema name in cmd line args: %s\n" "${*}"
+    exit 255
+fi
+
+mysql "$@" <<EOF
+
+-- This line starts the schema upgrade to version 26.0.
+
+-- Add client_classes column to options tables for option class taggging.
+ALTER TABLE dhcp4_options
+    ADD COLUMN client_classes LONGTEXT DEFAULT NULL;
+
+ALTER TABLE dhcp6_options
+    ADD COLUMN client_classes LONGTEXT DEFAULT NULL;
+
+-- Update the schema version number.
+UPDATE schema_version
+    SET version = '26', minor = '0';
+
+-- This line concludes the schema upgrade to version 26.0.
+EOF
index 94c42ddf49c76643fda35aa24cc7bd392bb4ded0..ae7b60b0351c7e9da389a008bf7f4482342fcb3c 100644 (file)
@@ -28,4 +28,5 @@
 /upgrade_022_to_023.sh
 /upgrade_023_to_024.sh
 /upgrade_024_to_025.sh
+/upgrade_025_to_026.sh
 /wipe_data.sh
index 29881ce8d7af89f19cb1c97eef1550e8a4c07d9f..fd0ef79f3589b066ca3bdde7786cecf9f664670c 100644 (file)
@@ -39,6 +39,7 @@ pgsql_SCRIPTS += upgrade_021_to_022.sh
 pgsql_SCRIPTS += upgrade_022_to_023.sh
 pgsql_SCRIPTS += upgrade_023_to_024.sh
 pgsql_SCRIPTS += upgrade_024_to_025.sh
+pgsql_SCRIPTS += upgrade_025_to_026.sh
 pgsql_SCRIPTS += wipe_data.sh
 
 DISTCLEANFILES = ${pgsql_SCRIPTS}
index 90e9d52a7725aa2644995da1435632c77eaba695..8d3e938827b19ab7507ee1e99a65eecb4bedcf5f 100644 (file)
@@ -6484,6 +6484,21 @@ UPDATE schema_version
 
 -- This line concludes the schema upgrade to version 25.0.
 
+-- This line starts the schema upgrade to version 26.0.
+
+-- Add client_classes column to options tables for option class taggging.
+ALTER TABLE dhcp4_options
+    ADD COLUMN client_classes TEXT DEFAULT NULL;
+
+ALTER TABLE dhcp6_options
+    ADD COLUMN client_classes TEXT DEFAULT NULL;
+
+-- Update the schema version number.
+UPDATE schema_version
+    SET version = '26', minor = '0';
+
+-- This line concludes the schema upgrade to version 26.0.
+
 -- Commit the script transaction.
 COMMIT;
 
diff --git a/src/share/database/scripts/pgsql/upgrade_025_to_026.sh.in b/src/share/database/scripts/pgsql/upgrade_025_to_026.sh.in
new file mode 100644 (file)
index 0000000..6e14f6b
--- /dev/null
@@ -0,0 +1,58 @@
+#!/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" != "25.0" ]; then
+    printf 'This script upgrades 25.0 to 26.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 26.0.
+
+-- Add client_classes column to options tables for option class taggging.
+ALTER TABLE dhcp4_options
+    ADD COLUMN client_classes TEXT DEFAULT NULL;
+
+ALTER TABLE dhcp6_options
+    ADD COLUMN client_classes TEXT DEFAULT NULL;
+
+-- Update the schema version number.
+UPDATE schema_version
+    SET version = '26', minor = '0';
+
+-- This line concludes the schema upgrade to version 26.0.
+
+-- Commit the script transaction.
+COMMIT;
+
+EOF