]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2094] Updated MySQL migration 12
authorMarcin Siodelski <marcin@isc.org>
Mon, 20 Sep 2021 09:51:34 +0000 (11:51 +0200)
committerMarcin Siodelski <marcin@isc.org>
Mon, 20 Sep 2021 21:15:03 +0000 (23:15 +0200)
The dhcp_client_class values are set to NULL when the options do not
belong to a class.

src/bin/admin/tests/mysql_tests.sh.in
src/share/database/scripts/mysql/dhcpdb_create.mysql
src/share/database/scripts/mysql/upgrade_011_to_012.sh.in

index 12af0615fa4833c3cd320fc2958886010b78d5be..b8c02b8f0ca3530f2730d38d71c0d710e52d217c 100644 (file)
@@ -1727,6 +1727,18 @@ mysql_client_class_test() {
              ON c.id = o.class_id WHERE c.name = 'foo'";
     run_statement "#get order index of class foo" "$sql" 1
 
+    sql=\
+"SET @disable_audit = 1; \
+ INSERT INTO ${table_prefix}_options(code, scope_id, dhcp_client_class, modification_ts) \
+     VALUES (222, 0, '', now()); \
+ SET @disable_audit = 0;"
+    run_statement "add option with an empty dhcp_client class" "$sql"
+
+    # Let's make sure that we can upgrade to version 12.0. This version
+    # introduces a foreign key between dhcpX_client_class and dhcpX_options
+    # table. The migration should set the dhcp_client_class to NULL.
+    mysql_upgrade_schema_to_version 12.0
+
     # Let's wipe the whole database
     mysql_wipe
 
index a56b95279a16f635c2e98288430c3dfcc50a4102..c92e903cf786ea0f21137e87628ace05bfc75cf8 100644 (file)
@@ -4046,6 +4046,17 @@ UPDATE schema_version
 
 # This line concludes database upgrade to version 11.
 
+# Ensure that dhcp_client_class is NULL when an option does not
+# belong to any client class. Later, we will add foreign keys for
+# the dhcp_client_class columns, and it requires that the columns
+# are NULL when there are no corresponding client classes.
+SET @disable_audit = 1;
+UPDATE dhcp4_options SET dhcp_client_class = NULL
+    WHERE scope_id <> 2;
+UPDATE dhcp6_options SET dhcp_client_class = NULL
+    WHERE scope_id <> 2;
+SET @disable_audit = 0;
+
 # Add a foreign keys referencing a client classes. If an option is
 # associated with a client class, the option will be deleted
 # along with the deleted client class.
index f24f6192fb093985e15801aeccb899c0039ea702..c4142b2a171e9b4dc31e75edb9c302a35e448e66 100644 (file)
@@ -53,6 +53,17 @@ fi
 
 mysql "$@" <<EOF
 
+-- Ensure that dhcp_client_class is NULL when an option does not
+-- belong to any client class. Later, we will add foreign keys for
+-- the dhcp_client_class columns, and it requires that the columns
+-- are NULL when there are no corresponding client classes.
+SET @disable_audit = 1;
+UPDATE dhcp4_options SET dhcp_client_class = NULL
+    WHERE scope_id <> 2;
+UPDATE dhcp6_options SET dhcp_client_class = NULL
+    WHERE scope_id <> 2;
+SET @disable_audit = 0;
+
 -- Add a foreign keys referencing a client classes. If an option is
 -- associated with a client class, the option will be deleted
 -- along with the deleted client class.