]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2276] Upgrade global param values in DB
authorThomas Markwalder <tmark@isc.org>
Thu, 6 Jul 2023 14:24:26 +0000 (10:24 -0400)
committerThomas Markwalder <tmark@isc.org>
Thu, 6 Jul 2023 14:27:25 +0000 (14:27 +0000)
Convert ddns-use-conflict-resolution to
ddns-conflict-resolution-mode in DB

configure.ac
    Added new upgrade files

src/bin/admin/tests/mysql_tests.sh.in
src/bin/admin/tests/pgsql_tests.sh.in
    new upgrade tests

src/lib/mysql/mysql_constants.h
src/lib/pgsql/pgsql_connection.h
    update schema version

src/share/database/scripts/mysql/.gitignore
src/share/database/scripts/mysql/Makefile.am
src/share/database/scripts/mysql/upgrade_019_to_020.sh.in
    new upgrade script

src/share/database/scripts/mysql/dhcpdb_create.mysql
    added conversion logic to stay in sync with upgrade script

src/share/database/scripts/pgsql/Makefile.am
src/share/database/scripts/pgsql/.gitignore
src/share/database/scripts/pgsql/upgrade_018_to_019.sh.in
    new upgrade script

src/share/database/scripts/pgsql/dhcpdb_create.pgsql
    added conversion logic to stay in sync with upgrade script

13 files changed:
configure.ac
src/bin/admin/tests/mysql_tests.sh.in
src/bin/admin/tests/pgsql_tests.sh.in
src/lib/mysql/mysql_constants.h
src/lib/pgsql/pgsql_connection.h
src/share/database/scripts/mysql/.gitignore
src/share/database/scripts/mysql/Makefile.am
src/share/database/scripts/mysql/dhcpdb_create.mysql
src/share/database/scripts/mysql/upgrade_019_to_020.sh.in [new file with mode: 0644]
src/share/database/scripts/pgsql/.gitignore
src/share/database/scripts/pgsql/Makefile.am
src/share/database/scripts/pgsql/dhcpdb_create.pgsql
src/share/database/scripts/pgsql/upgrade_018_to_019.sh.in [new file with mode: 0644]

index 9ef5eaa370865242257c721a83cff27a0c28bcaf..8beb2aeb2808365d771f5f2b4fbf3f05c102cd3d 100644 (file)
@@ -1704,6 +1704,8 @@ AC_CONFIG_FILES([src/share/database/scripts/mysql/upgrade_017_to_018.sh],
                 [chmod +x src/share/database/scripts/mysql/upgrade_017_to_018.sh])
 AC_CONFIG_FILES([src/share/database/scripts/mysql/upgrade_018_to_019.sh],
                 [chmod +x src/share/database/scripts/mysql/upgrade_018_to_019.sh])
+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/wipe_data.sh],
                 [chmod +x src/share/database/scripts/mysql/wipe_data.sh])
 AC_CONFIG_FILES([src/share/database/scripts/pgsql/Makefile])
@@ -1753,6 +1755,8 @@ AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_016_to_017.sh],
                 [chmod +x src/share/database/scripts/pgsql/upgrade_016_to_017.sh])
 AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_017_to_018.sh],
                 [chmod +x src/share/database/scripts/pgsql/upgrade_017_to_018.sh])
+AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_018_to_019.sh],
+                [chmod +x src/share/database/scripts/pgsql/upgrade_018_to_019.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])
index 889ce522bb9ae2945ed83eb9431cdc3dc1d82088..4f4d42f8da368d74956101cdef8d4f5d12522720 100644 (file)
@@ -814,6 +814,14 @@ mysql_upgrade_18_to_19_test() {
     run_statement "ipv6_reservations_insert" "$qry" "3001::99"
 }
 
+mysql_upgrade_19_to_20_test() {
+    # The function, mysql_ddns_conflict_resolution_mode_update_test, is called explicitly
+    # and tests conversion of ddns-use-conflict-resolution to ddns-conflict-resolution-mode.
+    # 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 "20.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
+}
+
 mysql_upgrade_test() {
 
     test_start "mysql.upgrade"
@@ -835,7 +843,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 "19.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
+    assert_str_eq "20.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
 
     # Let's check that the new tables are indeed there.
 
@@ -1498,6 +1506,9 @@ SET @disable_audit = 0"
     # Check upgrade from 18.0 to 19.0.
     mysql_upgrade_18_to_19_test
 
+    # Check upgrade from 19.0 to 20.0.
+    mysql_upgrade_19_to_20_test
+
     # Let's wipe the whole database
     mysql_wipe
 
@@ -2865,6 +2876,69 @@ insert into ipv6_reservations (address, prefix_len, type, dhcp6_iaid, host_id) \
     test_finish 0
 }
 
+# Verifies that you can upgrade from an earlier version and
+# that CB global parameter entries for 'ddns-use-conflict-resolution'
+# will get translated to 'ddns-conflict-resolution-mode'.
+mysql_ddns_conflict_resolution_mode_update_test() {
+    test_start "mysql.ddns_conflict_resolution_mode_update_test"
+
+    # Let's wipe the whole database
+    mysql_wipe
+
+    # We need to create an older database.
+    # Initialize database to schema 1.0.
+    mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
+
+    # Now upgrade to schema 19.0.
+    mysql_upgrade_schema_to_version 19.0
+
+    # Now insert global parameter instances of ddns-use-conflict-resolution.
+    sql=\
+"set @disable_audit = 1; \
+ insert into dhcp4_global_parameter (name,value, modification_ts,parameter_type)\
+    values ('ddns-use-conflict-resolution', 'false', current_time(),2);
+ insert into dhcp4_global_parameter (name,value, modification_ts,parameter_type)\
+    values ('ddns-use-conflict-resolution', 'true', current_time(),2);
+ insert into dhcp6_global_parameter (name,value, modification_ts,parameter_type)\
+    values ('ddns-use-conflict-resolution', 'false', current_time(),2);
+ insert into dhcp6_global_parameter (name,value, modification_ts,parameter_type)\
+    values ('ddns-use-conflict-resolution', 'true', current_time(),2);"
+
+    run_statement "insert ddns_conflict_resolution_mode" "$sql"
+
+    # Verify the inserted record counts.
+    qry="select count(*) from dhcp4_global_parameter where name='ddns-use-conflict-resolution';"
+    run_statement "#get 4_global parameter count before update" "$qry" 2
+
+    qry="select count(*) from dhcp6_global_parameter where name='ddns-use-conflict-resolution';"
+    run_statement "#get 6_global parameter count before update" "$qry" 2
+
+    # Upgrade to schema 20.0
+    mysql_upgrade_schema_to_version 20.0
+
+    # Verify we converted parameters correctly.
+    qry="select count(*) from dhcp4_global_parameter where name='ddns-conflict-resolution-mode' and\
+         value='check-with-dhcid'"
+    run_statement "#get 4_check-with-dhcid after update" "$qry" 1
+
+    qry="select count(*) from dhcp4_global_parameter where name='ddns-conflict-resolution-mode' and\
+         value='no-check-with-dhcid'"
+    run_statement "#get 4_no-check-with-dhcid after update" "$qry" 1
+
+    qry="select count(*) from dhcp6_global_parameter where name='ddns-conflict-resolution-mode' and\
+         value='check-with-dhcid'"
+    run_statement "#get 6_check-with-dhcid after update" "$qry" 1
+
+    qry="select count(*) from dhcp6_global_parameter where name='ddns-conflict-resolution-mode' and\
+         value='no-check-with-dhcid'"
+    run_statement "#get 6_no-check-with-dhcid after update" "$qry" 1
+
+    # Let's wipe the whole database
+    mysql_wipe
+
+    test_finish 0
+}
+
 # Run tests.
 mysql_db_init_test
 mysql_host_reservation_init_test
@@ -2890,3 +2964,5 @@ mysql_client_class_test dhcp6
 mysql_shrink_server_tag_test
 mysql_update_empty_duid_test
 mysql_update_v6_addresses_to_binary
+mysql_ddns_conflict_resolution_mode_update_test
+
index f9b839e20d032b0c673b7e17daf19ef4e89b7250..08d6b0deb09a32b661ef326c8fe3f97c05196346 100644 (file)
@@ -143,7 +143,7 @@ pgsql_db_version_test() {
     run_command \
         "${kea_admin}" db-version pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}"
     version="${OUTPUT}"
-    assert_str_eq "18.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
+    assert_str_eq "19.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
 
     # Let's wipe the whole database
     pgsql_wipe
@@ -868,6 +868,14 @@ pgsql_upgrade_17_to_18_test() {
     run_statement "ipv6_reservations_insert" "$qry" "3001::99"
 }
 
+pgsql_upgrade_18_to_19_test() {
+    # The function, pgsql_ddns_conflict_resolution_mode_update_test, is called explicitly
+    # and tests conversion of ddns-use-conflict-resolution to ddns-conflict-resolution-mode.
+    # For now this function only verifies version number.
+    version=$("${kea_admin}" db-version pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}")
+    assert_str_eq "19.0" "${version}" 'Expected kea-admin to return %s, returned value was %s'
+}
+
 pgsql_upgrade_test() {
     test_start "pgsql.upgrade"
 
@@ -886,7 +894,7 @@ pgsql_upgrade_test() {
 
     # 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 "18.0" "${version}" 'Expected kea-admin to return %s, returned value was %s'
+    assert_str_eq "19.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
@@ -936,6 +944,9 @@ pgsql_upgrade_test() {
     # Check 17 to 18 upgrade
     pgsql_upgrade_17_to_18_test
 
+    # Check 18 to 19 upgrade
+    pgsql_upgrade_18_to_19_test
+
     # Let's wipe the whole database
     pgsql_wipe
 
@@ -2047,6 +2058,73 @@ insert into ipv6_reservations (address, prefix_len, type, dhcp6_iaid, host_id) \
     test_finish 0
 }
 
+# Verifies that you can upgrade from an earlier version and
+# that reservation_mode values in subnet and shared network tables are
+# converted to new reservations flags.
+pgsql_ddns_conflict_resolution_mode_update_test() {
+    test_start "pgsql_ddns_conflict_resolution_mode_update_test"
+
+    # Let's wipe the whole database
+    pgsql_wipe
+
+    # We need to create an older database with lease data so we can
+    # verify the upgrade mechanisms which prepopulate the lease stat
+    # tables.
+    #
+    # Initialize database to schema 1.0.
+    pgsql_execute_script "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.pgsql"
+    assert_eq 0 "${EXIT_CODE}" "cannot initialize 1.0 database, expected exit code: %d, actual: %d"
+
+    # Now upgrade to schema 18.0
+    pgsql_upgrade_schema_to_version 18.0
+
+    # Now we need insert some subnets and shared networks.
+    sql=\
+"select set_config('kea.disable_audit', 'true', false);\
+ insert into dhcp4_global_parameter (name,value, modification_ts,parameter_type)\
+    values ('ddns-use-conflict-resolution', 'false', current_timestamp, 2);
+ insert into dhcp4_global_parameter (name,value, modification_ts,parameter_type)\
+    values ('ddns-use-conflict-resolution', 'true', current_timestamp, 2);
+ insert into dhcp6_global_parameter (name,value, modification_ts,parameter_type)\
+    values ('ddns-use-conflict-resolution', 'false', current_timestamp,2);
+ insert into dhcp6_global_parameter (name,value, modification_ts,parameter_type)\
+    values ('ddns-use-conflict-resolution', 'true', current_timestamp, 2);"
+
+    run_statement "insert ddns_conflict_resolution_mode" "$sql"
+
+    # Verify the inserted record counts.
+    qry="select count(*) from dhcp4_global_parameter where name='ddns-use-conflict-resolution';"
+    run_statement "#get 4_global parameter count before update" "$qry" 2
+
+    qry="select count(*) from dhcp6_global_parameter where name='ddns-use-conflict-resolution';"
+    run_statement "#get 6_global parameter count before update" "$qry" 2
+
+    # Upgrade to schema 19.0
+    pgsql_upgrade_schema_to_version 19.0
+
+    # Verify we converted parameters correctly.
+    qry="select count(*) from dhcp4_global_parameter where name='ddns-conflict-resolution-mode' and\
+         value='check-with-dhcid'"
+    run_statement "#get 4_check-with-dhcid after update" "$qry" 1
+
+    qry="select count(*) from dhcp4_global_parameter where name='ddns-conflict-resolution-mode' and\
+         value='no-check-with-dhcid'"
+    run_statement "#get 4_no-check-with-dhcid after update" "$qry" 1
+
+    qry="select count(*) from dhcp6_global_parameter where name='ddns-conflict-resolution-mode' and\
+         value='check-with-dhcid'"
+    run_statement "#get 6_check-with-dhcid after update" "$qry" 1
+
+    qry="select count(*) from dhcp6_global_parameter where name='ddns-conflict-resolution-mode' and\
+         value='no-check-with-dhcid'"
+    run_statement "#get 6_no-check-with-dhcid after update" "$qry" 1
+
+    # Let's wipe the whole database
+    pgsql_wipe
+
+    test_finish 0
+}
+
 # Run tests.
 pgsql_db_init_test
 pgsql_db_version_test
@@ -2066,3 +2144,4 @@ pgsql_lease_stat_recount_test
 pgsql_unused_subnet_id_test
 pgsql_update_empty_duid_test
 pgsql_update_v6_addresses_to_binary
+pgsql_ddns_conflict_resolution_mode_update_test
index 0f2cc1c8fcaa3cf03a0f5f70a24568d4233a4b4f..4ea90a74db17fe7006ee8940d6a724ec0017a6ee 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 = 19;
+const uint32_t MYSQL_SCHEMA_VERSION_MAJOR = 20;
 const uint32_t MYSQL_SCHEMA_VERSION_MINOR = 0;
 
 //@}
index 4e8c21a5b1e9a19329c45a4b05ccefd2320831ea..f5d1f134abb1de689c3bbf6836196f126fabdd1a 100644 (file)
@@ -18,7 +18,7 @@ namespace isc {
 namespace db {
 
 /// @brief Define the PostgreSQL backend version.
-const uint32_t PGSQL_SCHEMA_VERSION_MAJOR = 18;
+const uint32_t PGSQL_SCHEMA_VERSION_MAJOR = 19;
 const uint32_t PGSQL_SCHEMA_VERSION_MINOR = 0;
 
 // Maximum number of parameters that can be used a statement
index 195dfc384199cadf3aa85a771b3826153ef4a8a5..7f4b2dbf04eafaaa938e04e8c0774492fc36de79 100644 (file)
@@ -27,4 +27,5 @@
 /upgrade_016_to_017.sh
 /upgrade_017_to_018.sh
 /upgrade_018_to_019.sh
+/upgrade_019_to_020.sh
 /wipe_data.sh
index 8849bf18fe6e31d2807dea6074d5edf7c29f6d47..ee95d34b379bb24dc10df42f47a2415ac172fbee 100644 (file)
@@ -38,6 +38,7 @@ 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 += upgrade_019_to_020.sh
 mysql_SCRIPTS += wipe_data.sh
 
 DISTCLEANFILES = ${mysql_SCRIPTS}
index d05ccaede082540932d1639c7609a7c805affb49..0e78580510d73e6b1436d77850ecec22d71424e7 100644 (file)
@@ -5812,6 +5812,32 @@ UPDATE schema_version
 
 -- This line concludes the schema upgrade to version 19.0.
 
+-- This line starts the schema upgrade to version 20.0.
+
+-- Convert ddns-use-conflict-resolution to ddns-conflict-resolution-mode
+SET @disable_audit = 1;
+UPDATE dhcp4_global_parameter
+SET name = 'ddns-conflict-resolution-mode', value = 'check-with-dhcid', parameter_type = 4
+WHERE name = 'ddns-use-conflict-resolution' and value = 'true';
+
+UPDATE dhcp4_global_parameter
+SET name = 'ddns-conflict-resolution-mode', value = 'no-check-with-dhcid', parameter_type = 4
+WHERE name = 'ddns-use-conflict-resolution' and value = 'false';
+
+UPDATE dhcp6_global_parameter
+SET name = 'ddns-conflict-resolution-mode', value = 'check-with-dhcid', parameter_type = 4
+WHERE name = 'ddns-use-conflict-resolution' and value = 'true';
+
+UPDATE dhcp6_global_parameter
+SET name = 'ddns-conflict-resolution-mode', value = 'no-check-with-dhcid', parameter_type = 4
+WHERE name = 'ddns-use-conflict-resolution' and value = 'false';
+
+-- Update the schema version number.
+UPDATE schema_version
+    SET version = '20', minor = '0';
+
+-- This line concludes the schema upgrade to version 20.0.
+
 # Notes:
 #
 # Indexes
diff --git a/src/share/database/scripts/mysql/upgrade_019_to_020.sh.in b/src/share/database/scripts/mysql/upgrade_019_to_020.sh.in
new file mode 100644 (file)
index 0000000..8d15c44
--- /dev/null
@@ -0,0 +1,81 @@
+#!/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}" != "19.0"; then
+    printf 'This script upgrades 19.0 to 20.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 20.0.
+
+-- Convert ddns-use-conflict-resolution to ddns-conflict-resolution-mode
+SET @disable_audit = 1;
+UPDATE dhcp4_global_parameter
+SET name = 'ddns-conflict-resolution-mode', value = 'check-with-dhcid', parameter_type = 4
+WHERE name = 'ddns-use-conflict-resolution' and value = 'true';
+
+UPDATE dhcp4_global_parameter
+SET name = 'ddns-conflict-resolution-mode', value = 'no-check-with-dhcid', parameter_type = 4
+WHERE name = 'ddns-use-conflict-resolution' and value = 'false';
+
+UPDATE dhcp6_global_parameter
+SET name = 'ddns-conflict-resolution-mode', value = 'check-with-dhcid', parameter_type = 4
+WHERE name = 'ddns-use-conflict-resolution' and value = 'true';
+
+UPDATE dhcp6_global_parameter
+SET name = 'ddns-conflict-resolution-mode', value = 'no-check-with-dhcid', parameter_type = 4
+WHERE name = 'ddns-use-conflict-resolution' and value = 'false';
+
+-- Update the schema version number.
+UPDATE schema_version
+    SET version = '20', minor = '0';
+
+-- This line concludes the schema upgrade to version 20.0.
+EOF
index 36bcce1548a29ebf985b3bf375fd4ffd401666c3..75260ab3ee8062115910693ac3041e8a87484a0d 100644 (file)
@@ -21,4 +21,5 @@
 /upgrade_015_to_016.sh
 /upgrade_016_to_017.sh
 /upgrade_017_to_018.sh
+/upgrade_018_to_019.sh
 /wipe_data.sh
index b38c38071ba3e478ea82fefb92e2975231745362..7c21c667f6fce2b40dfab69023cb098bce92f7de 100644 (file)
@@ -32,6 +32,7 @@ pgsql_SCRIPTS += upgrade_014_to_015.sh
 pgsql_SCRIPTS += upgrade_015_to_016.sh
 pgsql_SCRIPTS += upgrade_016_to_017.sh
 pgsql_SCRIPTS += upgrade_017_to_018.sh
+pgsql_SCRIPTS += upgrade_018_to_019.sh
 pgsql_SCRIPTS += wipe_data.sh
 
 DISTCLEANFILES = ${pgsql_SCRIPTS}
index 93708a145be76307f9158ed5399ed76783a66be0..c5f488329b81588318e13b673ce2eb4f40e6b955 100644 (file)
@@ -6264,6 +6264,32 @@ UPDATE schema_version
 
 -- This line concludes the schema upgrade to version 18.0.
 
+-- This line starts the schema upgrade to version 19.0.
+
+-- Convert ddns-use-conflict-resolution to ddns-conflict-resolution-mode
+SELECT set_config('kea.disable_audit', 'true', false);
+UPDATE dhcp4_global_parameter
+SET name = 'ddns-conflict-resolution-mode', value = 'check-with-dhcid', parameter_type = 4
+WHERE name = 'ddns-use-conflict-resolution' and value = 'true';
+
+UPDATE dhcp4_global_parameter
+SET name = 'ddns-conflict-resolution-mode', value = 'no-check-with-dhcid', parameter_type = 4
+WHERE name = 'ddns-use-conflict-resolution' and value = 'false';
+
+UPDATE dhcp6_global_parameter
+SET name = 'ddns-conflict-resolution-mode', value = 'check-with-dhcid', parameter_type = 4
+WHERE name = 'ddns-use-conflict-resolution' and value = 'true';
+
+UPDATE dhcp6_global_parameter
+SET name = 'ddns-conflict-resolution-mode', value = 'no-check-with-dhcid', parameter_type = 4
+WHERE name = 'ddns-use-conflict-resolution' and value = 'false';
+
+-- Update the schema version number.
+UPDATE schema_version
+    SET version = '19', minor = '0';
+
+-- This line concludes the schema upgrade to version 19.0.
+
 -- Commit the script transaction.
 COMMIT;
 
diff --git a/src/share/database/scripts/pgsql/upgrade_018_to_019.sh.in b/src/share/database/scripts/pgsql/upgrade_018_to_019.sh.in
new file mode 100644 (file)
index 0000000..088fcd2
--- /dev/null
@@ -0,0 +1,67 @@
+#!/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" != "18.0" ]; then
+    printf 'This script upgrades 18.0 to 19.0. '
+    printf 'Reported version is %s. Skipping upgrade.\n' "${VERSION}"
+    exit 0
+fi
+
+psql "$@" >/dev/null <<EOF
+
+-- This line starts the schema upgrade to version 19.0.
+
+-- Convert ddns-use-conflict-resolution to ddns-conflict-resolution-mode
+SELECT set_config('kea.disable_audit', 'true', false);
+UPDATE dhcp4_global_parameter
+SET name = 'ddns-conflict-resolution-mode', value = 'check-with-dhcid', parameter_type = 4
+WHERE name = 'ddns-use-conflict-resolution' and value = 'true';
+
+UPDATE dhcp4_global_parameter
+SET name = 'ddns-conflict-resolution-mode', value = 'no-check-with-dhcid', parameter_type = 4
+WHERE name = 'ddns-use-conflict-resolution' and value = 'false';
+
+UPDATE dhcp6_global_parameter
+SET name = 'ddns-conflict-resolution-mode', value = 'check-with-dhcid', parameter_type = 4
+WHERE name = 'ddns-use-conflict-resolution' and value = 'true';
+
+UPDATE dhcp6_global_parameter
+SET name = 'ddns-conflict-resolution-mode', value = 'no-check-with-dhcid', parameter_type = 4
+WHERE name = 'ddns-use-conflict-resolution' and value = 'false';
+
+-- Update the schema version number.
+UPDATE schema_version
+    SET version = '19', minor = '0';
+
+-- This line concludes the schema upgrade to version 19.0.
+
+-- Commit the script transaction.
+COMMIT;
+
+EOF