diff options
author | Marcin Siodelski <marcin@isc.org> | 2024-04-18 15:25:48 +0200 |
---|---|---|
committer | Marcin Siodelski <marcin@isc.org> | 2024-06-19 12:34:18 +0200 |
commit | a52bf68db907f9dd9f7bc829bb711637909912b0 (patch) | |
tree | 96c0a561b3fa3412d56723ef7ba20f470263bcb1 /src/share | |
parent | [#3436] fixed compilation (diff) | |
download | kea-a52bf68db907f9dd9f7bc829bb711637909912b0.tar.xz kea-a52bf68db907f9dd9f7bc829bb711637909912b0.zip |
[#3246] Do not delete soft released leases
Diffstat (limited to 'src/share')
6 files changed, 158 insertions, 0 deletions
diff --git a/src/share/database/scripts/mysql/.gitignore b/src/share/database/scripts/mysql/.gitignore index 6d84ac028e..653d970974 100644 --- a/src/share/database/scripts/mysql/.gitignore +++ b/src/share/database/scripts/mysql/.gitignore @@ -30,4 +30,5 @@ /upgrade_019_to_020.sh /upgrade_020_to_021.sh /upgrade_021_to_022.sh +/upgrade_022_to_023.sh /wipe_data.sh diff --git a/src/share/database/scripts/mysql/dhcpdb_create.mysql b/src/share/database/scripts/mysql/dhcpdb_create.mysql index abcb6ce1ee..c3c51ecb02 100644 --- a/src/share/database/scripts/mysql/dhcpdb_create.mysql +++ b/src/share/database/scripts/mysql/dhcpdb_create.mysql @@ -5907,6 +5907,26 @@ UPDATE schema_version -- This line concludes the schema upgrade to version 22.0. +-- This line starts the schema upgrade to version 22.0. + +-- Update the schema version number. +UPDATE schema_version + SET version = '22', minor = '0'; + +-- This line concludes the schema upgrade to version 22.0. + +-- This line starts the schema upgrade to version 23.0. + +-- Introduce new lease state indicating that the lease has been +-- released by a client. +INSERT INTO lease_state VALUES (3, 'released'); + +-- Update the schema version number. +UPDATE schema_version + SET version = '23', minor = '0'; + +-- This line concludes the schema upgrade to version 23.0. + # Notes: # # Indexes diff --git a/src/share/database/scripts/mysql/upgrade_022_to_023.sh.in b/src/share/database/scripts/mysql/upgrade_022_to_023.sh.in new file mode 100644 index 0000000000..3a4b7abed5 --- /dev/null +++ b/src/share/database/scripts/mysql/upgrade_022_to_023.sh.in @@ -0,0 +1,68 @@ +#!/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}" != "22.0"; then + printf 'This script upgrades 22.0 to 23.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 23.0. + +-- Introduce new lease state indicating that the lease has been +-- released by a client. +INSERT INTO lease_state VALUES (3, 'released'); + +-- Update the schema version number. +UPDATE schema_version + SET version = '23', minor = '0'; + +-- This line concludes the schema upgrade to version 23.0. +EOF diff --git a/src/share/database/scripts/pgsql/.gitignore b/src/share/database/scripts/pgsql/.gitignore index 5a8ec39377..b039f2d937 100644 --- a/src/share/database/scripts/pgsql/.gitignore +++ b/src/share/database/scripts/pgsql/.gitignore @@ -25,4 +25,5 @@ /upgrade_019_to_020.sh /upgrade_020_to_021.sh /upgrade_021_to_022.sh +/upgrade_022_to_023.sh /wipe_data.sh diff --git a/src/share/database/scripts/pgsql/dhcpdb_create.pgsql b/src/share/database/scripts/pgsql/dhcpdb_create.pgsql index 79fee4f5a5..8459ffff4c 100644 --- a/src/share/database/scripts/pgsql/dhcpdb_create.pgsql +++ b/src/share/database/scripts/pgsql/dhcpdb_create.pgsql @@ -6377,6 +6377,19 @@ UPDATE schema_version -- This line concludes the schema upgrade to version 22.0. +-- This line starts the schema upgrade to version 23.0. + +-- Introduce new lease state indicating that the lease has been +-- released by a client. +INSERT INTO lease_state VALUES (3, 'released'); + +-- Update the schema version number. +UPDATE schema_version + SET version = '23', minor = '0'; + +-- This line concludes the schema upgrade to version 23.0. + + -- Commit the script transaction. COMMIT; diff --git a/src/share/database/scripts/pgsql/upgrade_022_to_023.sh.in b/src/share/database/scripts/pgsql/upgrade_022_to_023.sh.in new file mode 100644 index 0000000000..13d6d5a8f9 --- /dev/null +++ b/src/share/database/scripts/pgsql/upgrade_022_to_023.sh.in @@ -0,0 +1,55 @@ +#!/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" != "22.0" ]; then + printf 'This script upgrades 22.0 to 23.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 23.0. + +-- Introduce new lease state indicating that the lease has been +-- released by a client. +INSERT INTO lease_state VALUES (3, 'released'); + +-- Update the schema version number. +UPDATE schema_version + SET version = '23', minor = '0'; + +-- This line concludes the schema upgrade to version 23.0. + +-- Commit the script transaction. +COMMIT; + +EOF |