summaryrefslogtreecommitdiffstats
path: root/src/share/database/scripts
diff options
context:
space:
mode:
authorThomas Markwalder <tmark@isc.org>2023-06-14 17:02:55 +0200
committerThomas Markwalder <tmark@isc.org>2023-06-21 20:21:08 +0200
commit5ed24d58390f73ad303da28a8947ac4c8071f32b (patch)
tree4d4533743a2224199aef87d97877363ac79edc30 /src/share/database/scripts
parent[#2913] Update Authors to remove unneeded addition (diff)
downloadkea-5ed24d58390f73ad303da28a8947ac4c8071f32b.tar.xz
kea-5ed24d58390f73ad303da28a8947ac4c8071f32b.zip
[#2909] Mysql v6 addresses to binary
lease6.address and ipv6_reservations.address columns changed from varbinary(39) to binary(16). lease6.binaddr column removed deleted: src/share/api/binary-address6-upgrade.json new file: src/share/database/scripts/mysql/upgrade_018_to_019.sh.in configure.ac added new mysql upgrade script doc/sphinx/arm/hooks-lease-query.rst removed doc for binary-address6-upgrade command src/bin/admin/tests/mysql_tests.sh.in modified to use inet6_aton/ntoa as now needed Updated to test upgrage src/lib/dhcpsrv/lease_mgr.h LeaseMgr::upgradeBinaryAddress6() - no longer abstract, provides a dummy implemention src/lib/dhcpsrv/mysql_host_data_source.cc Change v6 reservation address to binary src/lib/dhcpsrv/mysql_lease_mgr.* Remove lease6.binaddr and uses Change lease6.address to binary src/lib/mysql/mysql_constants.h Update schema version src/share/api/api_files.mk Remove binary-address6-upgrade.json src/share/database/scripts/mysql/Makefile.am Add upgrade script src/share/database/scripts/mysql/dhcpdb_create.mysql Modify lease6, ipv6_reservations, and impacted functions
Diffstat (limited to 'src/share/database/scripts')
-rw-r--r--src/share/database/scripts/mysql/.gitignore1
-rw-r--r--src/share/database/scripts/mysql/Makefile.am1
-rw-r--r--src/share/database/scripts/mysql/dhcpdb_create.mysql114
-rw-r--r--src/share/database/scripts/mysql/upgrade_018_to_019.sh.in168
4 files changed, 284 insertions, 0 deletions
diff --git a/src/share/database/scripts/mysql/.gitignore b/src/share/database/scripts/mysql/.gitignore
index d6056d5a66..195dfc3841 100644
--- a/src/share/database/scripts/mysql/.gitignore
+++ b/src/share/database/scripts/mysql/.gitignore
@@ -26,4 +26,5 @@
/upgrade_015_to_016.sh
/upgrade_016_to_017.sh
/upgrade_017_to_018.sh
+/upgrade_018_to_019.sh
/wipe_data.sh
diff --git a/src/share/database/scripts/mysql/Makefile.am b/src/share/database/scripts/mysql/Makefile.am
index 3b6ae7242c..8849bf18fe 100644
--- a/src/share/database/scripts/mysql/Makefile.am
+++ b/src/share/database/scripts/mysql/Makefile.am
@@ -37,6 +37,7 @@ mysql_SCRIPTS += upgrade_014_to_015.sh
mysql_SCRIPTS += upgrade_015_to_016.sh
mysql_SCRIPTS += upgrade_016_to_017.sh
mysql_SCRIPTS += upgrade_017_to_018.sh
+mysql_SCRIPTS += upgrade_018_to_019.sh
mysql_SCRIPTS += wipe_data.sh
DISTCLEANFILES = ${mysql_SCRIPTS}
diff --git a/src/share/database/scripts/mysql/dhcpdb_create.mysql b/src/share/database/scripts/mysql/dhcpdb_create.mysql
index 259e703d88..d5be31209a 100644
--- a/src/share/database/scripts/mysql/dhcpdb_create.mysql
+++ b/src/share/database/scripts/mysql/dhcpdb_create.mysql
@@ -5677,6 +5677,120 @@ UPDATE schema_version
-- This line concludes the schema upgrade to version 18.0.
+-- This line starts the schema upgrade to version 19.0.
+-- Drop binaddr column and index.
+DROP INDEX lease6_by_binaddr ON lease6;
+ALTER TABLE lease6
+ DROP COLUMN binaddr;
+
+-- Change data type of lease6.address column.
+ALTER TABLE lease6 MODIFY COLUMN address BINARY(16);
+
+-- Change data type of ipv6_reservations.address column.
+ALTER TABLE ipv6_reservations MODIFY COLUMN address BINARY(16);
+
+-- Convert binary lease6 address to text
+DROP PROCEDURE IF EXISTS lease6DumpData;
+DELIMITER $$
+CREATE PROCEDURE lease6DumpData()
+BEGIN
+ SELECT
+ INET6_NTOA(address),
+ IFNULL(colonSeparatedHex(HEX(duid)), ''),
+ valid_lifetime,
+ UNIX_TIMESTAMP(expire),
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd,
+ fqdn_rev,
+ REPLACE(hostname, ',', '&#x2c'),
+ IFNULL(colonSeparatedHex(HEX(hwaddr)), ''),
+ state,
+ REPLACE(IFNULL(user_context, ''), ',', '&#x2c'),
+ hwtype,
+ hwaddr_source,
+ pool_id
+ FROM lease6
+ ORDER BY address;
+END $$
+DELIMITER ;
+
+-- Drop and create lease6Upload stored procedure with conversion to
+-- address to binary
+DROP PROCEDURE IF EXISTS lease6Upload;
+DELIMITER $$
+CREATE PROCEDURE lease6Upload(
+ IN address VARCHAR(39),
+ IN duid VARCHAR(130),
+ IN valid_lifetime INT UNSIGNED,
+ IN expire BIGINT UNSIGNED,
+ IN subnet_id INT UNSIGNED,
+ IN pref_lifetime INT UNSIGNED,
+ IN lease_type TINYINT,
+ IN iaid INT UNSIGNED,
+ IN prefix_len TINYINT UNSIGNED,
+ IN fqdn_fwd TINYINT,
+ IN fqdn_rev TINYINT,
+ IN hostname VARCHAR(255),
+ IN hwaddr VARCHAR(64),
+ IN state INT UNSIGNED,
+ IN user_context TEXT,
+ IN hwtype SMALLINT,
+ IN hwaddr_source INT UNSIGNED,
+ IN pool_id INT UNSIGNED
+)
+BEGIN
+ INSERT INTO lease6 (
+ address,
+ duid,
+ valid_lifetime,
+ expire,
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd,
+ fqdn_rev,
+ hostname,
+ hwaddr,
+ state,
+ user_context,
+ hwtype,
+ hwaddr_source,
+ pool_id
+ ) VALUES (
+ INET6_ATON(address),
+ UNHEX(REPLACE(duid, ':', '')),
+ valid_lifetime,
+ FROM_UNIXTIME(expire),
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd,
+ fqdn_rev,
+ REPLACE(hostname, '&#x2c', ','),
+ UNHEX(REPLACE(hwaddr, ':', '')),
+ state,
+ REPLACE(user_context, '&#x2c', ','),
+ hwtype,
+ hwaddr_source,
+ pool_id
+ );
+END $$
+DELIMITER ;
+
+-- Update the schema version number.
+UPDATE schema_version
+ SET version = '19', minor = '0';
+
+-- This line concludes the schema upgrade to version 19.0.
+
# Notes:
#
# Indexes
diff --git a/src/share/database/scripts/mysql/upgrade_018_to_019.sh.in b/src/share/database/scripts/mysql/upgrade_018_to_019.sh.in
new file mode 100644
index 0000000000..78eaf047a2
--- /dev/null
+++ b/src/share/database/scripts/mysql/upgrade_018_to_019.sh.in
@@ -0,0 +1,168 @@
+#!/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}" != "18.0"; then
+ printf 'This script upgrades 18.0 to 19.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 19.0.
+-- Drop binaddr column and index.
+DROP INDEX lease6_by_binaddr ON lease6;
+ALTER TABLE lease6
+ DROP COLUMN binaddr;
+
+-- Change data type of lease6.address column.
+ALTER TABLE lease6 MODIFY COLUMN address BINARY(16);
+
+-- Change data type of ipv6_reservations.address column.
+ALTER TABLE ipv6_reservations MODIFY COLUMN address BINARY(16);
+
+-- Convert binary lease6 address to text
+DROP PROCEDURE IF EXISTS lease6DumpData;
+DELIMITER $$
+CREATE PROCEDURE lease6DumpData()
+BEGIN
+ SELECT
+ INET6_NTOA(address),
+ IFNULL(colonSeparatedHex(HEX(duid)), ''),
+ valid_lifetime,
+ UNIX_TIMESTAMP(expire),
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd,
+ fqdn_rev,
+ REPLACE(hostname, ',', '&#x2c'),
+ IFNULL(colonSeparatedHex(HEX(hwaddr)), ''),
+ state,
+ REPLACE(IFNULL(user_context, ''), ',', '&#x2c'),
+ hwtype,
+ hwaddr_source,
+ pool_id
+ FROM lease6
+ ORDER BY address;
+END $$
+DELIMITER ;
+
+-- Drop and create lease6Upload stored procedure with conversion to
+-- address to binary
+DROP PROCEDURE IF EXISTS lease6Upload;
+DELIMITER $$
+CREATE PROCEDURE lease6Upload(
+ IN address VARCHAR(39),
+ IN duid VARCHAR(130),
+ IN valid_lifetime INT UNSIGNED,
+ IN expire BIGINT UNSIGNED,
+ IN subnet_id INT UNSIGNED,
+ IN pref_lifetime INT UNSIGNED,
+ IN lease_type TINYINT,
+ IN iaid INT UNSIGNED,
+ IN prefix_len TINYINT UNSIGNED,
+ IN fqdn_fwd TINYINT,
+ IN fqdn_rev TINYINT,
+ IN hostname VARCHAR(255),
+ IN hwaddr VARCHAR(64),
+ IN state INT UNSIGNED,
+ IN user_context TEXT,
+ IN hwtype SMALLINT,
+ IN hwaddr_source INT UNSIGNED,
+ IN pool_id INT UNSIGNED
+)
+BEGIN
+ INSERT INTO lease6 (
+ address,
+ duid,
+ valid_lifetime,
+ expire,
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd,
+ fqdn_rev,
+ hostname,
+ hwaddr,
+ state,
+ user_context,
+ hwtype,
+ hwaddr_source,
+ pool_id
+ ) VALUES (
+ INET6_ATON(address),
+ UNHEX(REPLACE(duid, ':', '')),
+ valid_lifetime,
+ FROM_UNIXTIME(expire),
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd,
+ fqdn_rev,
+ REPLACE(hostname, '&#x2c', ','),
+ UNHEX(REPLACE(hwaddr, ':', '')),
+ state,
+ REPLACE(user_context, '&#x2c', ','),
+ hwtype,
+ hwaddr_source,
+ pool_id
+ );
+END $$
+DELIMITER ;
+
+-- Update the schema version number.
+UPDATE schema_version
+ SET version = '19', minor = '0';
+
+-- This line concludes the schema upgrade to version 19.0.
+EOF