[chmod +x src/share/database/scripts/mysql/upgrade_021_to_022.sh])
AC_CONFIG_FILES([src/share/database/scripts/mysql/upgrade_022_to_023.sh],
[chmod +x src/share/database/scripts/mysql/upgrade_022_to_023.sh])
+AC_CONFIG_FILES([src/share/database/scripts/mysql/upgrade_023_to_024.sh],
+ [chmod +x src/share/database/scripts/mysql/upgrade_023_to_024.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_021_to_022.sh])
AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_022_to_023.sh],
[chmod +x src/share/database/scripts/pgsql/upgrade_022_to_023.sh])
+AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_023_to_024.sh],
+ [chmod +x src/share/database/scripts/pgsql/upgrade_023_to_024.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])
echo "Processing $script file..."
"${script}" --host="${db_host}" --user="${db_user}" \
--password="${db_password}" "${db_name}" ${extra_arguments}
- done
+ done | sort -V
version=$(checked_mysql_version)
printf 'Schema version reported after upgrade: %s\n' "${version}"
echo "Processing $script file..."
"${script}" -U "${db_user}" -h "${db_host}" \
-d "${db_name}" ${extra_arguments}
- done
+ done | sort -V
version=$(checked_pgsql_version)
printf 'Schema version reported after upgrade: %s\n' "${version}"
assert_str_eq 'released' "${OUTPUT}" "${qry}: expected output %s, returned %s"
}
+mysql_upgrade_23_to_24_test() {
+ query="SELECT count(id) from option_def_data_type"
+ run_command \
+ mysql_execute "${query}"
+ assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
+ assert_str_eq '18' "${OUTPUT}" "${query}: expected output %s, returned %s"
+}
+
mysql_upgrade_test() {
test_start "mysql.upgrade"
# 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 "23.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
+ assert_str_eq "24.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 18.0 to 19.0.
mysql_upgrade_18_to_19_test
-
# Check upgrade from 22.0 to 23.0.
mysql_upgrade_22_to_23_test
+ # Check upgrade from 23.0 to 24.0.
+ mysql_upgrade_23_to_24_test
+
# Let's wipe the whole database
mysql_wipe
run_command \
"${kea_admin}" db-version pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}"
version="${OUTPUT}"
- assert_str_eq "23.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
+ assert_str_eq "24.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
# Let's wipe the whole database
pgsql_wipe
assert_str_eq 'released' "${OUTPUT}" "${query}: expected output %s, returned %s"
}
+pgsql_upgrade_23_to_24_test() {
+ query="SELECT count(id) from option_def_data_type"
+ run_command \
+ pgsql_execute "${query}"
+ assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d"
+ assert_str_eq '18' "${OUTPUT}" "${query}: expected output %s, returned %s"
+}
+
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 "23.0" "${version}" 'Expected kea-admin to return %s, returned value was %s'
+ assert_str_eq "24.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_test
# Check 22 to 23 upgrade
pgsql_upgrade_22_to_23_test
+ # Check 23 to 24 upgrade
+ pgsql_upgrade_23_to_24_test
+
# Let's wipe the whole database
pgsql_wipe
OPT_FQDN_TYPE,
// Type to be used only internally. Allows convenient notation of the option config.
OPT_INTERNAL_TYPE,
- OPT_RECORD_TYPE,
- OPT_UNKNOWN_TYPE
+ OPT_RECORD_TYPE = 254, // Do not alter this value.
+ OPT_UNKNOWN_TYPE = 255 // Do not alter this value.
};
/// @brief Parameters being used to make up an option definition.
option_cast->toText());
}
+// Verify converstion of OptionDefintion type strings to type enums.
+TEST(OptionDataTypeUtil, typeToString) {
+ EXPECT_EQ(OPT_EMPTY_TYPE, OptionDataTypeUtil::getDataType("empty"));
+ EXPECT_EQ(OPT_BINARY_TYPE, OptionDataTypeUtil::getDataType("binary"));
+ EXPECT_EQ(OPT_BOOLEAN_TYPE, OptionDataTypeUtil::getDataType("boolean"));
+ EXPECT_EQ(OPT_INT8_TYPE, OptionDataTypeUtil::getDataType("int8"));
+ EXPECT_EQ(OPT_INT16_TYPE, OptionDataTypeUtil::getDataType("int16"));
+ EXPECT_EQ(OPT_INT32_TYPE, OptionDataTypeUtil::getDataType("int32"));
+ EXPECT_EQ(OPT_UINT8_TYPE, OptionDataTypeUtil::getDataType("uint8"));
+ EXPECT_EQ(OPT_UINT16_TYPE, OptionDataTypeUtil::getDataType("uint16"));
+ EXPECT_EQ(OPT_UINT32_TYPE, OptionDataTypeUtil::getDataType("uint32"));
+ EXPECT_EQ(OPT_IPV4_ADDRESS_TYPE, OptionDataTypeUtil::getDataType("ipv4-address"));
+ EXPECT_EQ(OPT_IPV6_ADDRESS_TYPE, OptionDataTypeUtil::getDataType("ipv6-address"));
+ EXPECT_EQ(OPT_IPV6_PREFIX_TYPE, OptionDataTypeUtil::getDataType("ipv6-prefix"));
+ EXPECT_EQ(OPT_PSID_TYPE, OptionDataTypeUtil::getDataType("psid"));
+ EXPECT_EQ(OPT_STRING_TYPE, OptionDataTypeUtil::getDataType("string"));
+ EXPECT_EQ(OPT_TUPLE_TYPE, OptionDataTypeUtil::getDataType("tuple"));
+ EXPECT_EQ(OPT_FQDN_TYPE, OptionDataTypeUtil::getDataType("fqdn"));
+ // EXPECT_EQ(OPT_INTERNAL_TYPE, OptionDataTypeUtil::getDataType("internal"));
+ EXPECT_EQ(OPT_RECORD_TYPE, OptionDataTypeUtil::getDataType("record"));
+ EXPECT_EQ(OPT_UNKNOWN_TYPE, OptionDataTypeUtil::getDataType("bogus"));
+}
+
+// Verify converstion of OptionDefintion type enums to type strings.
+TEST(OptionDataTypeUtil, stringToType) {
+ EXPECT_EQ("empty", OptionDataTypeUtil::getDataTypeName(OPT_EMPTY_TYPE));
+ EXPECT_EQ("binary", OptionDataTypeUtil::getDataTypeName( OPT_BINARY_TYPE));
+ EXPECT_EQ("boolean", OptionDataTypeUtil::getDataTypeName(OPT_BOOLEAN_TYPE));
+ EXPECT_EQ("int8", OptionDataTypeUtil::getDataTypeName(OPT_INT8_TYPE));
+ EXPECT_EQ("int16", OptionDataTypeUtil::getDataTypeName(OPT_INT16_TYPE));
+ EXPECT_EQ("int32", OptionDataTypeUtil::getDataTypeName(OPT_INT32_TYPE));
+ EXPECT_EQ("uint8", OptionDataTypeUtil::getDataTypeName(OPT_UINT8_TYPE));
+ EXPECT_EQ("uint16", OptionDataTypeUtil::getDataTypeName(OPT_UINT16_TYPE));
+ EXPECT_EQ("uint32", OptionDataTypeUtil::getDataTypeName(OPT_UINT32_TYPE));
+ EXPECT_EQ("ipv4-address", OptionDataTypeUtil::getDataTypeName(OPT_IPV4_ADDRESS_TYPE));
+ EXPECT_EQ("ipv6-address", OptionDataTypeUtil::getDataTypeName(OPT_IPV6_ADDRESS_TYPE));
+ EXPECT_EQ("ipv6-prefix", OptionDataTypeUtil::getDataTypeName(OPT_IPV6_PREFIX_TYPE));
+ EXPECT_EQ("psid", OptionDataTypeUtil::getDataTypeName(OPT_PSID_TYPE));
+ EXPECT_EQ("string", OptionDataTypeUtil::getDataTypeName(OPT_STRING_TYPE));
+ EXPECT_EQ("tuple", OptionDataTypeUtil::getDataTypeName(OPT_TUPLE_TYPE));
+ EXPECT_EQ("fqdn", OptionDataTypeUtil::getDataTypeName(OPT_FQDN_TYPE));
+ // EXPECT_EQ("internal", OptionDataTypeUtil::getDataTypeName(OPT_INTERNAL_TYPE));
+ EXPECT_EQ("record", OptionDataTypeUtil::getDataTypeName(OPT_RECORD_TYPE));
+ EXPECT_EQ("unknown", OptionDataTypeUtil::getDataTypeName(OPT_UNKNOWN_TYPE));
+}
+
} // anonymous namespace
/// @name Current database schema version values.
//@{
-const uint32_t MYSQL_SCHEMA_VERSION_MAJOR = 23;
+const uint32_t MYSQL_SCHEMA_VERSION_MAJOR = 24;
const uint32_t MYSQL_SCHEMA_VERSION_MINOR = 0;
//@}
namespace db {
/// @brief Define the PostgreSQL backend version.
-const uint32_t PGSQL_SCHEMA_VERSION_MAJOR = 23;
+const uint32_t PGSQL_SCHEMA_VERSION_MAJOR = 24;
const uint32_t PGSQL_SCHEMA_VERSION_MINOR = 0;
// Maximum number of parameters that can be used a statement
/upgrade_020_to_021.sh
/upgrade_021_to_022.sh
/upgrade_022_to_023.sh
+/upgrade_023_to_024.sh
/wipe_data.sh
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 += wipe_data.sh
DISTCLEANFILES = ${mysql_SCRIPTS}
-- This line concludes the schema upgrade to version 23.0.
+-- This line starts the schema upgrade to version 24.0.
+
+-- Create a function to conditionally migrate option_def data type
+-- values. If they are updating from 2.6.1 this has been done already
+-- and we don't want to do it twice.
+DROP PROCEDURE IF EXISTS updateOptionDataDef;
+DELIMITER $$
+CREATE PROCEDURE updateOptionDataDef()
+BEGIN
+ DECLARE skipper TINYINT;
+
+ SELECT COUNT(table_name) FROM information_schema.tables
+ WHERE table_schema LIKE database() AND table_name = 'option_def_data_type' into skipper;
+
+ IF skipper = 0 THEN
+ -- First we migrate existing OPT_RECORD_TYPE values
+ -- If they're coming from pre-2.6.0 record type is 17, from
+ -- 2.6.0 or 2.7.0 it is 18. No viable to way to know where we
+ -- started.
+ UPDATE dhcp4_option_def SET type = 254 WHERE type >= 17 AND record_types IS NOT NULL;
+ UPDATE dhcp6_option_def SET type = 254 WHERE type >= 17 AND record_types IS NOT NULL;
+
+ -- Create the table that enumerates option definition data types.
+ CREATE TABLE option_def_data_type (
+ id TINYINT UNSIGNED NOT NULL PRIMARY KEY,
+ name VARCHAR(32) NOT NULL
+ ) ENGINE = InnoDB;
+
+ -- Now insert supported types.
+ -- We skip (9, 'any-address') as it is not externally supported.
+ INSERT INTO option_def_data_type VALUES
+ (0, 'empty'),
+ (1, 'binary'),
+ (2, 'boolean'),
+ (3, 'int8"'),
+ (4, 'int16'),
+ (5, 'int32'),
+ (6, 'uint8'),
+ (7, 'uint16'),
+ (8, 'uint32'),
+ (10, 'ipv4-address'),
+ (11, 'ipv6-address'),
+ (12, 'ipv6-prefix'),
+ (13, 'psid'),
+ (14, 'string'),
+ (15, 'tuple'),
+ (16, 'fqdn'),
+ (17, 'internal'),
+ (254, 'record');
+
+ -- Add foreign key constraints to enforce only valid types.
+ ALTER TABLE dhcp4_option_def
+ ADD CONSTRAINT fk_option_def_data_type4 FOREIGN KEY (type) REFERENCES option_def_data_type(id);
+
+ ALTER TABLE dhcp6_option_def
+ ADD CONSTRAINT fk_option_def_data_type6 FOREIGN KEY (type) REFERENCES option_def_data_type(id);
+ END IF;
+END $$
+DELIMITER ;
+
+call updateOptionDataDef();
+
+-- Get rid of the now obsolete function.
+DROP PROCEDURE 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.
+
# Notes:
#
# Indexes
DROP FUNCTION IF EXISTS isJsonSupported;
DROP TABLE IF EXISTS lease6_relay_id;
DROP TABLE IF EXISTS lease6_remote_id;
+DROP TABLE IF EXISTS option_def_data_type;
--- /dev/null
+#!/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}" != "23.0"; then
+ printf 'This script upgrades 23.0 to 24.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 24.0.
+
+-- Create a function to conditionally migrate option_def data type
+-- values. If they are updating from 2.6.1 this has been done already
+-- and we don't want to do it twice.
+DROP PROCEDURE IF EXISTS updateOptionDataDef;
+DELIMITER $$
+CREATE PROCEDURE updateOptionDataDef()
+BEGIN
+ DECLARE skipper TINYINT;
+
+ SELECT COUNT(table_name) FROM information_schema.tables
+ WHERE table_schema LIKE database() AND table_name = 'option_def_data_type' into skipper;
+
+ IF skipper = 0 THEN
+ -- First we migrate existing OPT_RECORD_TYPE values
+ -- If they're coming from pre-2.6.0 record type is 17, from
+ -- 2.6.0 or 2.7.0 it is 18. No viable to way to know where we
+ -- started.
+ UPDATE dhcp4_option_def SET type = 254 WHERE type >= 17 AND record_types IS NOT NULL;
+ UPDATE dhcp6_option_def SET type = 254 WHERE type >= 17 AND record_types IS NOT NULL;
+
+ -- Create the table that enumerates option definition data types.
+ CREATE TABLE option_def_data_type (
+ id TINYINT UNSIGNED NOT NULL PRIMARY KEY,
+ name VARCHAR(32) NOT NULL
+ ) ENGINE = InnoDB;
+
+ -- Now insert supported types.
+ -- We skip (9, 'any-address') as it is not externally supported.
+ INSERT INTO option_def_data_type VALUES
+ (0, 'empty'),
+ (1, 'binary'),
+ (2, 'boolean'),
+ (3, 'int8"'),
+ (4, 'int16'),
+ (5, 'int32'),
+ (6, 'uint8'),
+ (7, 'uint16'),
+ (8, 'uint32'),
+ (10, 'ipv4-address'),
+ (11, 'ipv6-address'),
+ (12, 'ipv6-prefix'),
+ (13, 'psid'),
+ (14, 'string'),
+ (15, 'tuple'),
+ (16, 'fqdn'),
+ (17, 'internal'),
+ (254, 'record');
+
+ -- Add foreign key constraints to enforce only valid types.
+ ALTER TABLE dhcp4_option_def
+ ADD CONSTRAINT fk_option_def_data_type4 FOREIGN KEY (type) REFERENCES option_def_data_type(id);
+
+ ALTER TABLE dhcp6_option_def
+ ADD CONSTRAINT fk_option_def_data_type6 FOREIGN KEY (type) REFERENCES option_def_data_type(id);
+ END IF;
+END $$
+DELIMITER ;
+
+call updateOptionDataDef();
+
+-- Get rid of the now obsolete function.
+DROP PROCEDURE 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.
+
+EOF
/upgrade_020_to_021.sh
/upgrade_021_to_022.sh
/upgrade_022_to_023.sh
+/upgrade_023_to_024.sh
/wipe_data.sh
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 += wipe_data.sh
DISTCLEANFILES = ${pgsql_SCRIPTS}
UPDATE schema_version
SET version = '23', minor = '0';
--- This line concludes the schema upgrade to version 23.0.
+-- This line starts the schema upgrade to version 24.0.
+
+-- Create a function to conditionally migrate option_def data type
+-- values. If they are updating from 2.6.1 this has been done already
+-- and we don't want to do it twice.
+DROP FUNCTION IF EXISTS updateOptionDataDef();
+CREATE OR REPLACE FUNCTION updateOptionDataDef() RETURNS text AS $$
+ DECLARE skipper BOOLEAN;
+BEGIN
+ SELECT exists(SELECT FROM pg_tables WHERE tablename = 'option_def_data_type') into skipper;
+ IF skipper THEN
+ -- Table already exists which means the migration was already done.
+ RETURN 'EXISTS';
+ END IF;
+
+ -- First we migrate existing OPT_RECORD_TYPE values
+ -- If they're coming from pre-2.6.0 record type is 17, from
+ -- 2.6.0 or 2.7.0 it is 18. No viable to way to know where we
+ -- started.
+
+ -- Can we attempt to discern between internal and rec by testing
+ -- record_types?
+ UPDATE dhcp4_option_def SET type = 254 WHERE type >= 17 AND record_types IS NOT NULL;
+ UPDATE dhcp6_option_def SET type = 254 WHERE type >= 17 AND record_types IS NOT NULL;
+
+ -- Create the table that enumerates option definition data types.
+ CREATE TABLE option_def_data_type (
+ id smallint NOT NULL,
+ name VARCHAR(32) NOT NULL,
+ PRIMARY KEY (id)
+ );
+
+ -- Now insert supported types.
+ -- We skip (9, 'any-address') as it is not externally supported.
+ INSERT INTO option_def_data_type VALUES
+ (0, 'empty'),
+ (1, 'binary'),
+ (2, 'boolean'),
+ (3, 'int8"'),
+ (4, 'int16'),
+ (5, 'int32'),
+ (6, 'uint8'),
+ (7, 'uint16'),
+ (8, 'uint32'),
+ (10, 'ipv4-address'),
+ (11, 'ipv6-address'),
+ (12, 'ipv6-prefix'),
+ (13, 'psid'),
+ (14, 'string'),
+ (15, 'tuple'),
+ (16, 'fqdn'),
+ (17, 'internal'),
+ (254, 'record');
+
+ -- Add foreign key constraints to enforce only valid types.
+ ALTER TABLE dhcp4_option_def
+ ADD CONSTRAINT fk_option_def_data_type4 FOREIGN KEY (type) REFERENCES option_def_data_type(id);
+
+ ALTER TABLE dhcp6_option_def
+ ADD CONSTRAINT fk_option_def_data_type6 FOREIGN KEY (type) REFERENCES option_def_data_type(id);
+
+ RETURN 'UPDATED';
+END;
+$$ LANGUAGE plpgsql;
+
+select updateOptionDataDef();
+
+-- Get rid of the now obsolete function.
+DROP FUNCTION IF EXISTS updateOptionDataDef();
+
+UPDATE schema_version
+ SET version = '24', minor = '0';
+-- This line concludes the schema upgrade to version 24.0.
-- Commit the script transaction.
COMMIT;
DROP FUNCTION IF EXISTS proc_stat_lease6_update ();
DROP FUNCTION IF EXISTS proc_stat_lease6_delete ();
DROP TABLE IF EXISTS logs CASCADE;
+DROP TABLE IF EXISTS option_def_data_type CASCADE;
-- config backend procedures for DHCPv6
DROP FUNCTION IF EXISTS createAuditRevisionDHCP6(audit_ts TIMESTAMP WITH TIME ZONE, server_tag VARCHAR(64),
--- /dev/null
+#!/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" != "23.0" ]; then
+ printf 'This script upgrades 23.0 to 24.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 24.0.
+
+-- Create a function to conditionally migrate option_def data type
+-- values. If they are updating from 2.6.1 this has been done already
+-- and we don't want to do it twice.
+DROP FUNCTION IF EXISTS updateOptionDataDef();
+CREATE OR REPLACE FUNCTION updateOptionDataDef() RETURNS text AS \$\$
+ DECLARE skipper BOOLEAN;
+BEGIN
+ SELECT exists(SELECT FROM pg_tables WHERE tablename = 'option_def_data_type') into skipper;
+ IF skipper THEN
+ -- Table already exists which means the migration was already done.
+ RETURN 'EXISTS';
+ END IF;
+
+ -- First we migrate existing OPT_RECORD_TYPE values
+ -- If they're coming from pre-2.6.0 record type is 17, from
+ -- 2.6.0 or 2.7.0 it is 18. No viable to way to know where we
+ -- started.
+
+ -- Can we attempt to discern between internal and rec by testing
+ -- record_types?
+ UPDATE dhcp4_option_def SET type = 254 WHERE type >= 17 AND record_types IS NOT NULL;
+ UPDATE dhcp6_option_def SET type = 254 WHERE type >= 17 AND record_types IS NOT NULL;
+
+ -- Create the table that enumerates option definition data types.
+ CREATE TABLE option_def_data_type (
+ id smallint NOT NULL,
+ name VARCHAR(32) NOT NULL,
+ PRIMARY KEY (id)
+ );
+
+ -- Now insert supported types.
+ -- We skip (9, 'any-address') as it is not externally supported.
+ INSERT INTO option_def_data_type VALUES
+ (0, 'empty'),
+ (1, 'binary'),
+ (2, 'boolean'),
+ (3, 'int8"'),
+ (4, 'int16'),
+ (5, 'int32'),
+ (6, 'uint8'),
+ (7, 'uint16'),
+ (8, 'uint32'),
+ (10, 'ipv4-address'),
+ (11, 'ipv6-address'),
+ (12, 'ipv6-prefix'),
+ (13, 'psid'),
+ (14, 'string'),
+ (15, 'tuple'),
+ (16, 'fqdn'),
+ (17, 'internal'),
+ (254, 'record');
+
+ -- Add foreign key constraints to enforce only valid types.
+ ALTER TABLE dhcp4_option_def
+ ADD CONSTRAINT fk_option_def_data_type4 FOREIGN KEY (type) REFERENCES option_def_data_type(id);
+
+ ALTER TABLE dhcp6_option_def
+ ADD CONSTRAINT fk_option_def_data_type6 FOREIGN KEY (type) REFERENCES option_def_data_type(id);
+
+ RETURN 'UPDATED';
+END;
+\$\$ LANGUAGE plpgsql;
+
+select updateOptionDataDef();
+
+-- Get rid of the now obsolete function.
+DROP FUNCTION IF EXISTS updateOptionDataDef();
+
+UPDATE schema_version
+ SET version = '24', minor = '0';
+
+-- This line concludes the schema upgrade to version 24.0.
+
+-- Commit the script transaction.
+COMMIT;
+
+EOF