[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])
[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])
# 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}"
# 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.
# 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
# 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"
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
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"
# 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
# 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
/// @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;
//@}
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
/upgrade_012_to_013.sh
/upgrade_013_to_014.sh
/upgrade_014_to_015.sh
+/upgrade_015_to_016.sh
/wipe_data.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}
-- 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
--- /dev/null
+#!/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
/upgrade_011_to_012.sh
/upgrade_012_to_013.sh
/upgrade_013_to_014.sh
+/upgrade_014_to_015.sh
/wipe_data.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}
-- 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;
--- /dev/null
+#!/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