]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3396] Moved column alters to new schema 22
authorThomas Markwalder <tmark@isc.org>
Tue, 21 May 2024 17:53:43 +0000 (13:53 -0400)
committerThomas Markwalder <tmark@isc.org>
Tue, 21 May 2024 17:58:34 +0000 (13:58 -0400)
configure.ac
    Added mysql/upgrade_019_to_020.sh

src/bin/admin/tests/mysql_tests.sh.in
    Updated, adjusted for version check

src/lib/mysql/mysql_constants.h
    Bumped schema version to 22

src/share/database/scripts/mysql/.gitignore
    upgrade_019_to_020.sh

src/share/database/scripts/mysql/dhcpdb_create.mysql
    Moved expire column statements into version 22 update section

src/share/database/scripts/mysql/upgrade_020_to_021.sh.in
    Removed expire column updates

src/share/database/scripts/mysql/upgrade_020_to_021.sh.in
    New file, modifies expire columns

configure.ac
src/bin/admin/tests/mysql_tests.sh.in
src/lib/mysql/mysql_constants.h
src/share/database/scripts/mysql/.gitignore
src/share/database/scripts/mysql/dhcpdb_create.mysql
src/share/database/scripts/mysql/upgrade_020_to_021.sh.in
src/share/database/scripts/mysql/upgrade_021_to_022.sh.in [new file with mode: 0644]

index 1f0c2d7040c442f0e915863b115baa26fbe54f4e..2a78b127aa84b888cc5824135adda8d52e99bc2a 100644 (file)
@@ -1762,6 +1762,8 @@ AC_CONFIG_FILES([src/share/database/scripts/mysql/upgrade_019_to_020.sh],
                 [chmod +x src/share/database/scripts/mysql/upgrade_019_to_020.sh])
 AC_CONFIG_FILES([src/share/database/scripts/mysql/upgrade_020_to_021.sh],
                 [chmod +x src/share/database/scripts/mysql/upgrade_020_to_021.sh])
+AC_CONFIG_FILES([src/share/database/scripts/mysql/upgrade_021_to_022.sh],
+                [chmod +x src/share/database/scripts/mysql/upgrade_021_to_022.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])
index 93f6dbb4defa3dce00a430d499ab6487ef6366ba..15b282e43fad1e52ff6b8bf26e360c41660d0c15 100644 (file)
@@ -819,6 +819,12 @@ mysql_upgrade_19_to_21_test() {
     assert_str_eq "21.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
 }
 
+mysql_upgrade_21_to_22_test() {
+    # For now this function only verifies version number.
+    version=$("${kea_admin}" db-version mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}")
+    assert_str_eq "22.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
+}
+
 mysql_upgrade_test() {
 
     test_start "mysql.upgrade"
@@ -840,7 +846,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 "21.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
+    assert_str_eq "22.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
 
     # Let's check that the new tables are indeed there.
 
@@ -1504,7 +1510,10 @@ SET @disable_audit = 0"
     mysql_upgrade_18_to_19_test
 
     # Check upgrade from 19.0 to 21.0.
-    mysql_upgrade_19_to_21_test
+    # mysql_upgrade_19_to_21_test - only checks version
+
+    # Check upgrade from 21.0 to 22.0.
+    mysql_upgrade_21_to_22_test
 
     # Let's wipe the whole database
     mysql_wipe
index 9b37ac45f86384452b5eaf2881162336e20d25fa..a0d79f97fc4797c900f51323b934c5995303107a 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 = 21;
+const uint32_t MYSQL_SCHEMA_VERSION_MAJOR = 22;
 const uint32_t MYSQL_SCHEMA_VERSION_MINOR = 0;
 
 //@}
index 53d22bedcb3ddb1c5ad75e2bf76c6c3a01a6ce37..6d84ac028e393dd8c5bc96bdc13d5c8622888186 100644 (file)
@@ -29,4 +29,5 @@
 /upgrade_018_to_019.sh
 /upgrade_019_to_020.sh
 /upgrade_020_to_021.sh
+/upgrade_021_to_022.sh
 /wipe_data.sh
index 593f2a2822a1dff51bacaffa69677424f8762d9a..cf51c58aae00dc83f51dba5516b00bbc2dfeaf71 100644 (file)
@@ -5857,15 +5857,19 @@ UPDATE schema_version
 -- Add subnet id and address index for lease6.
 CREATE INDEX lease6_by_subnet_id_address ON lease6 (subnet_id, address ASC);
 
+-- This line concludes the schema upgrade to version 21.0.
+
+-- This line starts the schema upgrade to version 22.0.
+
 -- Turn off Mariadb default/on-update for expire column
 ALTER TABLE lease4 MODIFY expire timestamp NULL;
 ALTER TABLE lease6 MODIFY expire timestamp NULL;
 
 -- Update the schema version number.
 UPDATE schema_version
-    SET version = '21', minor = '0';
+    SET version = '22', minor = '0';
 
--- This line concludes the schema upgrade to version 21.0.
+-- This line concludes the schema upgrade to version 22.0.
 
 # Notes:
 #
index 980e452ca5f04c46134264afd8c335034dea3b86..125a50ab1b2bbe90f8f2fb69adada14998646d4f 100644 (file)
@@ -59,10 +59,6 @@ mysql "$@" <<EOF
 -- Add subnet id and address index for lease6.
 CREATE INDEX lease6_by_subnet_id_address ON lease6 (subnet_id, address ASC);
 
--- Turn off Mariadb default/on-update for expire column
-ALTER TABLE lease4 MODIFY expire timestamp NULL;
-ALTER TABLE lease6 MODIFY expire timestamp NULL;
-
 -- Update the schema version number.
 UPDATE schema_version
     SET version = '21', minor = '0';
diff --git a/src/share/database/scripts/mysql/upgrade_021_to_022.sh.in b/src/share/database/scripts/mysql/upgrade_021_to_022.sh.in
new file mode 100644 (file)
index 0000000..61facbd
--- /dev/null
@@ -0,0 +1,68 @@
+#!/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/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}" != "21.0"; then
+    printf 'This script upgrades 21.0 to 22.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 22.0.
+
+-- Turn off Mariadb default/on-update for expire column
+ALTER TABLE lease4 MODIFY expire timestamp NULL;
+ALTER TABLE lease6 MODIFY expire timestamp NULL;
+
+-- Update the schema version number.
+UPDATE schema_version
+    SET version = '22', minor = '0';
+
+-- This line concludes the schema upgrade to version 22.0.
+EOF