]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1387] Checkpoint: updated schema
authorFrancis Dupont <fdupont@isc.org>
Mon, 1 Jul 2024 16:40:30 +0000 (18:40 +0200)
committerFrancis Dupont <fdupont@isc.org>
Wed, 4 Sep 2024 13:09:40 +0000 (15:09 +0200)
src/bin/admin/tests/mysql_tests.sh.in
src/bin/admin/tests/pgsql_tests.sh.in
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_024_025.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_023_to_024.sh.in
src/share/database/scripts/pgsql/upgrade_024_025.sh.in [new file with mode: 0644]

index e429b53f62c2eba9ec6e3364c520816c4b60d3a0..368555e940c5ae994911b42488afa9447fb3ef8f 100644 (file)
@@ -829,6 +829,20 @@ mysql_upgrade_23_to_24_test() {
     assert_str_eq '18' "${OUTPUT}" "${query}: expected output %s, returned %s"
 }
 
+mysql_upgrade_24_to_25_test() {
+    # excluded_prefix should have been added to ipv6_reservations
+    qry="select excluded_prefix from ipv6_reservations limit 1"
+    run_command \
+        mysql_execute "${qry}"
+    assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
+
+    # excluded_prefix_len should have been added to ipv6_reservations
+    qry="select excluded_prefix_len from ipv6_reservations 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"
@@ -1519,6 +1533,9 @@ SET @disable_audit = 0"
     # Check upgrade from 23.0 to 24.0.
     mysql_upgrade_23_to_24_test
 
+    # Check upgrade from 24.0 to 25.0.
+    mysql_upgrade_24_to_25_test
+
     # Let's wipe the whole database
     mysql_wipe
 
index f3962f970940659bf466b575e9e64920abe25fbb..e68c65128a86e3fc9e521120014eeabda2cdb0a8 100644 (file)
@@ -925,6 +925,17 @@ pgsql_upgrade_23_to_24_test() {
     assert_str_eq '18' "${OUTPUT}" "${query}: expected output %s, returned %s"
 }
 
+pgsql_upgrade_24_to_25_test() {
+    # Added excluded_prefix to ipv6_reservations
+    run_command \
+        pgsql_execute "select excluded_prefix from ipv6_reservations"
+    assert_eq 0 "${EXIT_CODE}" "ipv6_reservations is missing excluded_prefix column. (expected status code %d, returned %d)"
+    # Added excluded_prefix_len to ipv6_reservations
+    run_command \
+        pgsql_execute "select excluded_prefix_len from ipv6_reservations"
+    assert_eq 0 "${EXIT_CODE}" "ipv6_reservations is missing excluded_prefix_len column. (expected status code %d, returned %d)"
+}
+
 pgsql_upgrade_test() {
     test_start "pgsql.upgrade"
 
@@ -1008,6 +1019,9 @@ pgsql_upgrade_test() {
     # Check 23 to 24 upgrade
     pgsql_upgrade_23_to_24_test
 
+    # Check 24 to 25 upgrade
+    pgsql_upgrade_24_to_25_test
+
     # Let's wipe the whole database
     pgsql_wipe
 
index d99c5a2f2e0420b061eafd57417133728e9c19be..9cd5c0f4b67caf1dde2eb8d3a2c1734b67b4fba0 100644 (file)
@@ -32,4 +32,5 @@
 /upgrade_021_to_022.sh
 /upgrade_022_to_023.sh
 /upgrade_023_to_024.sh
+/upgrade_024_to_025.sh
 /wipe_data.sh
index d74e597641b7f733141098a64b5bfdaa67a08742..4b7f238b15944b3e4ae6cdad196f9dc55a42160e 100644 (file)
@@ -43,6 +43,7 @@ mysql_SCRIPTS += upgrade_020_to_021.sh
 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 += wipe_data.sh
 
 DISTCLEANFILES = ${mysql_SCRIPTS}
index 7461b50296c499f7c524cd7d9cf82ccc36309259..59e478ba9a91fa1e177402e7441aa5b22c229d76 100644 (file)
@@ -6010,6 +6010,19 @@ UPDATE schema_version
 
 -- This line concludes the schema upgrade to version 24.0.
 
+-- This line starts the schema upgrade to version 25.0
+
+-- Add prefix exclude option to IPv6 reservations.
+ALTER TABLE ipv6_reservations
+    ADD COLUMN excluded_prefix BINARY(16) DEFAULT NULL,
+    ADD COLUMN excluded_prefix_len TINYINT(3) UNSIGNED NOT NULL DEFAULT 0;
+
+-- Update the schema version number.
+UPDATE schema_version
+    SET version = '25', minor = '0';
+
+-- This line concludes the schema upgrade to version 25.0
+
 # Notes:
 #
 # Indexes
diff --git a/src/share/database/scripts/mysql/upgrade_024_025.sh.in b/src/share/database/scripts/mysql/upgrade_024_025.sh.in
new file mode 100644 (file)
index 0000000..7ba378e
--- /dev/null
@@ -0,0 +1,69 @@
+#!/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}" != "24.0"; then
+    printf 'This script upgrades 24.0 to 25.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 25.0.
+
+-- Add prefix exclude option to IPv6 reservations.
+ALTER TABLE ipv6_reservations
+    ADD COLUMN excluded_prefix BINARY(16) DEFAULT NULL,
+    ADD COLUMN excluded_prefix_len TINYINT(3) UNSIGNED NOT NULL DEFAULT 0;
+
+-- Update the schema version number.
+UPDATE schema_version
+    SET version = '25', minor = '0';
+
+-- This line concludes the schema upgrade to version 25.0.
+EOF
index 9c47fd671b1dee5bc150732efc959dde771f8416..94c42ddf49c76643fda35aa24cc7bd392bb4ded0 100644 (file)
@@ -27,4 +27,5 @@
 /upgrade_021_to_022.sh
 /upgrade_022_to_023.sh
 /upgrade_023_to_024.sh
+/upgrade_024_to_025.sh
 /wipe_data.sh
index a05e9b7a50c7607fbb6e269274c52f04464227c4..29881ce8d7af89f19cb1c97eef1550e8a4c07d9f 100644 (file)
@@ -38,6 +38,7 @@ pgsql_SCRIPTS += upgrade_020_to_021.sh
 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 += wipe_data.sh
 
 DISTCLEANFILES = ${pgsql_SCRIPTS}
index b212312afa35ae5db041b5719a5cfca6b114b0f8..0bed48e86b68fcda657b0737c3fa52d6f971f192 100644 (file)
@@ -6465,11 +6465,25 @@ SELECT updateOptionDataDef();
 -- Get rid of the now obsolete function.
 DROP FUNCTION IF EXISTS updateOptionDataDef();
 
+-- Update the schema version number.
 UPDATE schema_version
     SET version = '24', minor = '0';
 
 -- This line concludes the schema upgrade to version 24.0.
 
+-- This line starts the schema upgrade to version 25.0
+
+-- Add prefix exclude option to IPv6 reservations.
+ALTER TABLE ipv6_reservations
+    ADD COLUMN excluded_prefix INET DEFAULT NULL,
+    ADD COLUMN excluded_prefix_len SMALLINT NOT NULL;
+
+-- Update the schema version number.
+UPDATE schema_version
+    SET version = '25', minor = '0';
+
+-- This line concludes the schema upgrade to version 25.0.
+
 -- Commit the script transaction.
 COMMIT;
 
index 5130e4ce588414be8ee2d3449e0f80e7acb2855e..e46a4f701a6e41050988fddf414cd34c960a3c03 100644 (file)
@@ -113,6 +113,7 @@ SELECT updateOptionDataDef();
 -- Get rid of the now obsolete function.
 DROP FUNCTION IF EXISTS updateOptionDataDef();
 
+-- Update the schema version number.
 UPDATE schema_version
     SET version = '24', minor = '0';
 
diff --git a/src/share/database/scripts/pgsql/upgrade_024_025.sh.in b/src/share/database/scripts/pgsql/upgrade_024_025.sh.in
new file mode 100644 (file)
index 0000000..806b135
--- /dev/null
@@ -0,0 +1,56 @@
+#!/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" != "24.0" ]; then
+    printf 'This script upgrades 24.0 to 25.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 25.0.
+
+-- Add prefix exclude option to IPv6 reservations.
+ALTER TABLE ipv6_reservations
+    ADD COLUMN excluded_prefix INET DEFAULT NULL,
+    ADD COLUMN excluded_prefix_len SMALLINT NOT NULL DEFAULT '0';
+
+-- Update the schema version number.
+UPDATE schema_version
+    SET version = '25', minor = '0';
+
+-- This line concludes the schema upgrade to version 25.0.
+
+-- Commit the script transaction.
+COMMIT;
+
+EOF