]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2752] Rebased new schemas
authorFrancis Dupont <fdupont@isc.org>
Thu, 30 Mar 2023 13:03:47 +0000 (15:03 +0200)
committerFrancis Dupont <fdupont@isc.org>
Thu, 30 Mar 2023 13:03:47 +0000 (15:03 +0200)
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_015_to_016.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_014_to_015.sh.in [new file with mode: 0644]

index a79293e58dc9caf1cd5ae2dafd4d2ad966fdcab6..3ce0bdbb5c23a45ea49f61652f092dc7d45b15b3 100644 (file)
@@ -1704,6 +1704,8 @@ AC_CONFIG_FILES([src/share/database/scripts/mysql/upgrade_013_to_014.sh],
                 [chmod +x src/share/database/scripts/mysql/upgrade_013_to_014.sh])
 AC_CONFIG_FILES([src/share/database/scripts/mysql/upgrade_014_to_015.sh],
                 [chmod +x src/share/database/scripts/mysql/upgrade_014_to_015.sh])
+AC_CONFIG_FILES([src/share/database/scripts/mysql/upgrade_015_to_016.sh],
+                [chmod +x src/share/database/scripts/mysql/upgrade_015_to_016.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])
@@ -1745,6 +1747,8 @@ AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_012_to_013.sh],
                 [chmod +x src/share/database/scripts/pgsql/upgrade_012_to_013.sh])
 AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_013_to_014.sh],
                 [chmod +x src/share/database/scripts/pgsql/upgrade_013_to_014.sh])
+AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_014_to_015.sh],
+                [chmod +x src/share/database/scripts/pgsql/upgrade_014_to_015.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 5fa34b403f3b9754edb110342ed43b5878a6117c..c6577c18a514bee1145dd023dbf86ef0de582b83 100644 (file)
@@ -344,7 +344,7 @@ mysql_upgrade_12_to_13_test() {
 
     # Check lease4Dump*().
     run_command \
-        mysql_execute "INSERT INTO lease4 VALUES(10,20,30,40,(SELECT FROM_UNIXTIME(1678900000)),50,1,1,'one,example,com',0,'{ \"a\": 1, \"b\": 2 }');"
+        mysql_execute "INSERT INTO lease4 VALUES(10,20,30,40,(SELECT FROM_UNIXTIME(1678900000)),50,1,1,'one,example,com',0,'{ \"a\": 1, \"b\": 2 }',NULL,NULL);"
     assert_eq 0 "${EXIT_CODE}" 'INSERT INTO lease4 failed, expected exit code %d, actual %d'
     assert_str_eq '' "${OUTPUT}"
 
@@ -736,7 +736,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 "15.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
+    assert_str_eq "16.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
 
     # Let's check that the new tables are indeed there.
 
@@ -1366,6 +1366,30 @@ SET @disable_audit = 0;"
     # Check upgrade from 14.0 to 15.0.
     mysql_upgrade_14_to_15_test
 
+    # Check upgrade from 15.0 to 16.0.
+
+    # table: lease4 new relay_id remote_id column and index.
+    qry="select relay_id from lease4"
+    run_statement "lease4" "$qry"
+
+    qry="show indexes from lease4 where key_name = 'lease4_by_relay_id'";
+    run_command \
+        mysql_execute "${qry}"
+    assert_eq 0 "${EXIT_CODE}" "show indexes from lease4 failed. (expected status code %d, returned %d)"
+    count=$(echo "${OUTPUT}" | grep -Fci lease4_by_relay_id)
+    assert_eq 1 "${count}" "lease4_by_relay_id  wrong or missing. (expected count %d, actual %d)"
+
+    # table: lease4 new remote_id column and index.
+    qry="select remote_id from lease4"
+    run_statement "lease4" "$qry"
+
+    qry="show indexes from lease4 where key_name = 'lease4_by_remote_id'";
+    run_command \
+        mysql_execute "${qry}"
+    assert_eq 0 "${EXIT_CODE}" "show indexes from lease4 failed. (expected status code %d, returned %d)"
+    count=$(echo "${OUTPUT}" | grep -Fci lease4_by_remote_id)
+    assert_eq 1 "${count}" "lease4_by_remote_id  wrong or missing. (expected count %d, actual %d)"
+
     # Let's wipe the whole database
     mysql_wipe
 
@@ -1407,9 +1431,9 @@ mysql_lease4_dump_test() {
 
     # Insert the reference record
     insert_sql="\
-insert into lease4 values(10,20,30,40,(SELECT FROM_UNIXTIME(1642000000)),50,1,1,'one.example.com',0,NULL);
-insert into lease4 values(11,NULL,123,40,(SELECT FROM_UNIXTIME(1643210000)),50,1,1,'',1,'{  }');\
-insert into lease4 values(12,22,NULL,40,(SELECT FROM_UNIXTIME(1643212345)),50,1,1,'three,example,com',2,'{ \"a\": 1, \"b\": \"c\" }');"
+insert into lease4 values(10,20,30,40,(SELECT FROM_UNIXTIME(1642000000)),50,1,1,'one.example.com',0,NULL,NULL,NULL);
+insert into lease4 values(11,NULL,123,40,(SELECT FROM_UNIXTIME(1643210000)),50,1,1,'',1,'{  }',NULL,NULL);\
+insert into lease4 values(12,22,NULL,40,(SELECT FROM_UNIXTIME(1643212345)),50,1,1,'three,example,com',2,'{ \"a\": 1, \"b\": \"c\" }',NULL,NULL);"
 
     run_command \
         mysql_execute "$insert_sql"
index 410f8f08ae3fa602e0c0d14c0d1f0df973e98bdd..22b22e22744140feb4411a8ae0f73a20141d8439 100644 (file)
@@ -143,7 +143,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 "14.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
+    assert_str_eq "15.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
 
     # Let's wipe the whole database
     pgsql_wipe
@@ -793,6 +793,18 @@ pgsql_upgrade_13_to_14_test() {
     assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
 }
 
+pgsql_upgrade_14_to_15_test() {
+    # Added relay_id column to lease4
+    run_command \
+        pgsql_execute "select relay_id from lease4;"
+    assert_eq 0 "${EXIT_CODE}" "lease4 is missing relay_id column. (expected status  code %d, returned %d)"
+
+    # Added remote_id column to lease4
+    run_command \
+        pgsql_execute "select remote_id from lease4;"
+    assert_eq 0 "${EXIT_CODE}" "lease4 is missing remote_id column. (expected status  code %d, returned %d)"
+}
+
 pgsql_upgrade_test() {
     test_start "pgsql.upgrade"
 
@@ -810,7 +822,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 "14.0" "${version}" 'Expected kea-admin to return %s, returned value was %s'
+    assert_str_eq "15.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
@@ -848,6 +860,9 @@ pgsql_upgrade_test() {
     # Check 13 to 14 upgrade
     pgsql_upgrade_13_to_14_test
 
+    # Check 14 to 15 upgrade
+    pgsql_upgrade_14_to_15_test
+
     # Let's wipe the whole database
     pgsql_wipe
 
index 03546a6baf823043938d4cf4956e4d64222dd378..f3516c95a0686193dda53c56b0ec287e169752b8 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 = 15;
+const uint32_t MYSQL_SCHEMA_VERSION_MAJOR = 16;
 const uint32_t MYSQL_SCHEMA_VERSION_MINOR = 0;
 
 //@}
index 85430bb3ac44d29438915540cfc939503864a462..4c4940efa00f29ca2f53496ad27b132653a02a1a 100644 (file)
@@ -18,7 +18,7 @@ namespace isc {
 namespace db {
 
 /// @brief Define the PostgreSQL backend version.
-const uint32_t PGSQL_SCHEMA_VERSION_MAJOR = 14;
+const uint32_t PGSQL_SCHEMA_VERSION_MAJOR = 15;
 const uint32_t PGSQL_SCHEMA_VERSION_MINOR = 0;
 
 // Maximum number of parameters that can be used a statement
index 38eabe95078ec711ab05234128de28a4d993c0eb..c9945fdf9e148e00844540ef030ce5568bcb7d6b 100644 (file)
@@ -23,4 +23,5 @@
 /upgrade_012_to_013.sh
 /upgrade_013_to_014.sh
 /upgrade_014_to_015.sh
+/upgrade_015_to_016.sh
 /wipe_data.sh
index a82867c915aac070abdcac5ad7ef12c7a1a302fe..af8c8c5dcbffc956354acaa46c7583c7fa8decd0 100644 (file)
@@ -34,6 +34,7 @@ mysql_SCRIPTS += upgrade_011_to_012.sh
 mysql_SCRIPTS += upgrade_012_to_013.sh
 mysql_SCRIPTS += upgrade_013_to_014.sh
 mysql_SCRIPTS += upgrade_014_to_015.sh
+mysql_SCRIPTS += upgrade_015_to_016.sh
 mysql_SCRIPTS += wipe_data.sh
 
 DISTCLEANFILES = ${mysql_SCRIPTS}
index 656b54ec9db30fdb70b57c469539aa07d2bf50f1..603a7cdca073f0f59a37e3afafb19cc1b9bd915d 100644 (file)
@@ -5089,6 +5089,23 @@ UPDATE schema_version
 
 -- This line concludes the schema upgrade to version 15.
 
+-- This line starts the schema upgrade to version 16.
+
+-- Add relay and remote id colums to DHCPv4 leases.
+ALTER TABLE lease4
+    ADD COLUMN relay_id VARBINARY(128) DEFAULT NULL,
+    ADD COLUMN remote_id VARBINARY(128) DEFAULT NULL;
+
+-- Create relay and remote id indexes.
+CREATE INDEX lease4_by_relay_id ON lease4 (relay_id);
+CREATE INDEX lease4_by_remote_id ON lease4 (remote_id);
+
+-- Update the schema version number.
+UPDATE schema_version
+    SET version = '16', minor = '0';
+
+-- This line concludes the schema upgrade to version 16.
+
 # Notes:
 #
 # Indexes
diff --git a/src/share/database/scripts/mysql/upgrade_015_to_016.sh.in b/src/share/database/scripts/mysql/upgrade_015_to_016.sh.in
new file mode 100644 (file)
index 0000000..49692e7
--- /dev/null
@@ -0,0 +1,71 @@
+#!/bin/sh
+
+# Copyright (C) 2023 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/.
+
+# shellcheck disable=SC1091
+# SC1091: Not following: ... was not specified as input (see shellcheck -x).
+
+# 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. Use installed version if available and
+# use build version if it isn't.
+if test -f "@datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh"; then
+    . "@datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh"
+else
+    . "@abs_top_builddir@/src/bin/admin/admin-utils.sh"
+fi
+
+# Check version.
+version=$(mysql_version "${@}")
+if test "${version}" != "15.0"; then
+    printf 'This script upgrades 15.0 to 16.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 16.
+
+-- Add relay and remote id colums to DHCPv4 leases.
+ALTER TABLE lease4
+    ADD COLUMN relay_id VARBINARY(128) DEFAULT NULL,
+    ADD COLUMN remote_id VARBINARY(128) DEFAULT NULL;
+
+-- Create relay and remote id indexes.
+CREATE INDEX lease4_by_relay_id ON lease4 (relay_id);
+CREATE INDEX lease4_by_remote_id ON lease4 (remote_id);
+
+-- Update the schema version number.
+UPDATE schema_version
+    SET version = '16', minor = '0';
+
+-- This line concludes the schema upgrade to version 16.
+EOF
index 575f7d3ac063216d0ff28a634b9cd2be435c01d8..72383371d362c24ee2bf16f30fbb8ea81415f959 100644 (file)
@@ -17,4 +17,5 @@
 /upgrade_011_to_012.sh
 /upgrade_012_to_013.sh
 /upgrade_013_to_014.sh
+/upgrade_014_to_015.sh
 /wipe_data.sh
index cb55f3a805e270ebf91c713377204b1334ca7e04..35ae50fe1e7af8c04501ff67f26028861e3bb265 100644 (file)
@@ -28,6 +28,7 @@ pgsql_SCRIPTS += upgrade_010_to_011.sh
 pgsql_SCRIPTS += upgrade_011_to_012.sh
 pgsql_SCRIPTS += upgrade_012_to_013.sh
 pgsql_SCRIPTS += upgrade_013_to_014.sh
+pgsql_SCRIPTS += upgrade_014_to_015.sh
 pgsql_SCRIPTS += wipe_data.sh
 
 DISTCLEANFILES = ${pgsql_SCRIPTS}
index 59ca7f4b033fac49c95ef97d22d173b685d03f05..8d71d2ec0dd78a075de5ab452826ce3738dc38fb 100644 (file)
@@ -5649,6 +5649,23 @@ UPDATE schema_version
 
 -- This line concludes the schema upgrade to version 14.
 
+-- This line starts the schema upgrade to version 15.
+
+-- Add relay and remote id colums to DHCPv4 leases.
+ALTER TABLE lease4
+    ADD COLUMN relay_id BYTEA DEFAULT NULL,
+    ADD COLUMN remote_id BYTEA DEFAULT NULL;
+
+-- Create relay and remote id indexes.
+CREATE INDEX lease4_by_relay_id ON lease4 (relay_id);
+CREATE INDEX lease4_by_remote_id ON lease4 (remote_id);
+
+-- Update the schema version number.
+UPDATE schema_version
+    SET version = '15', minor = '0';
+
+-- This line concludes the schema upgrade to version 15.
+
 -- Commit the script transaction.
 COMMIT;
 
diff --git a/src/share/database/scripts/pgsql/upgrade_014_to_015.sh.in b/src/share/database/scripts/pgsql/upgrade_014_to_015.sh.in
new file mode 100644 (file)
index 0000000..aec3c13
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+# Copyright (C) 2023 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/.
+
+# shellcheck disable=SC1091
+# SC1091: Not following: ... was not specified as input (see shellcheck -x).
+
+# 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. Use installed version if available and
+# use build version if it isn't.
+if test -f "@datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh"; then
+    . "@datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh"
+else
+    . "@abs_top_builddir@/src/bin/admin/admin-utils.sh"
+fi
+
+VERSION=$(pgsql_version "$@")
+
+if [ "$VERSION" != "14.0" ]; then
+    printf 'This script upgrades 14.0 to 15.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 15.
+
+-- Add relay and remote id colums to DHCPv4 leases.
+ALTER TABLE lease4
+    ADD COLUMN relay_id BYTEA DEFAULT NULL,
+    ADD COLUMN remote_id BYTEA DEFAULT NULL;
+
+-- Create relay and remote id indexes.
+CREATE INDEX lease4_by_relay_id ON lease4 (relay_id);
+CREATE INDEX lease4_by_remote_id ON lease4 (remote_id);
+
+-- Update the schema version number.
+UPDATE schema_version
+    SET version = '15', minor = '0';
+
+-- This line concludes the schema upgrade to version 15.
+
+-- Commit the script transaction.
+COMMIT;
+
+EOF