]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[4237] Added MySQL ENGINE to all table creates, fixed hosts table not dropping
authorThomas Markwalder <tmark@isc.org>
Fri, 11 Dec 2015 19:51:18 +0000 (14:51 -0500)
committerThomas Markwalder <tmark@isc.org>
Fri, 11 Dec 2015 19:51:18 +0000 (14:51 -0500)
All MySQL text to create tables sets ENGINE to INNODB
MySQL unit tests now reliably drop the "hosts" table

src/bin/admin/scripts/mysql/dhcpdb_create.mysql
    Added "ENGINE = INNODB" table creates where needed

src/bin/admin/scripts/mysql/upgrade_1.0_to_2.0.sh.in
src/bin/admin/scripts/mysql/upgrade_2.0_to_3.0.sh.in
    Added "ENGINE = INNODB" table creates where needed

src/bin/admin/tests/data/mysql.lease6_dump_test.reference.csv
    Reversed order of reference file to match INNODB result

src/bin/admin/tests/dhcpdb_create_1.0.mysql
    Added "ENGINE = INNODB" table creates where needed

src/bin/admin/tests/mysql_tests.sh.in
    Removed unnecessary explicit drop of ipv6_reservations

src/lib/dhcpsrv/tests/mysql_schema.cc
    Added MySQL error output on statement failures

src/lib/dhcpsrv/tests/schema_mysql_copy.h
    const char* destroy_statement[]
        Added statement to turn off referential integrity checks, so all
        tables will get dropped.  "hosts" table was being left behind.

    const char* create_statement[]
        Added "ENGINE = INNODB" table creates where needed

src/bin/admin/scripts/mysql/dhcpdb_create.mysql
src/bin/admin/scripts/mysql/upgrade_1.0_to_2.0.sh.in
src/bin/admin/scripts/mysql/upgrade_2.0_to_3.0.sh.in
src/bin/admin/tests/data/mysql.lease6_dump_test.reference.csv
src/bin/admin/tests/dhcpdb_create_1.0.mysql
src/bin/admin/tests/mysql_tests.sh.in
src/lib/dhcpsrv/tests/mysql_schema.cc
src/lib/dhcpsrv/tests/schema_mysql_copy.h

index ad85cb59df5e4b6f60d7bb25bbca796486e82ccb..31c01249dc04ea520670e2c542101bf313a8c59f 100755 (executable)
@@ -92,7 +92,8 @@ CREATE INDEX lease6_by_iaid_subnet_id_duid ON lease6 (iaid, subnet_id, duid);
 CREATE TABLE lease6_types (
     lease_type TINYINT PRIMARY KEY NOT NULL,    # Lease type code.
     name VARCHAR(5)                             # Name of the lease type
-    );
+    ) ENGINE = INNODB;
+
 START TRANSACTION;
 INSERT INTO lease6_types VALUES (0, "IA_NA");   # Non-temporary v6 addresses
 INSERT INTO lease6_types VALUES (1, "IA_TA");   # Temporary v6 addresses
@@ -111,7 +112,7 @@ COMMIT;
 CREATE TABLE schema_version (
     version INT PRIMARY KEY NOT NULL,       # Major version number
     minor INT                               # Minor version number
-    );
+    ) ENGINE = INNODB;
 START TRANSACTION;
 INSERT INTO schema_version VALUES (1, 0);
 COMMIT;
@@ -136,7 +137,7 @@ ALTER TABLE lease6
 CREATE TABLE lease_hwaddr_source (
     hwaddr_source INT PRIMARY KEY NOT NULL,
     name VARCHAR(40)
-);
+) ENGINE = INNODB;
 
 # Hardware address obtained from raw sockets
 INSERT INTO lease_hwaddr_source VALUES (1, "HWADDR_SOURCE_RAW");
index e9854ca4455e75bec86e083ba3c2060b8739814d..27eed8c694ed90ab31d41e29cc04e5d91f0c5ba0 100644 (file)
@@ -24,7 +24,7 @@ ALTER TABLE lease6
 CREATE TABLE lease_hwaddr_source (
     hwaddr_source INT PRIMARY KEY NOT NULL,
     name VARCHAR(40)
-);
+) ENGINE = INNODB;
 
 -- See src/lib/dhcp/dhcp/pkt.h for detailed explanation
 INSERT INTO lease_hwaddr_source VALUES (1, "HWADDR_SOURCE_RAW");
index cc85d409340f7dd161b6bb1382f85dd811f2ecb4..1551cd8f43d8cf8f63a3fb76503c97f8da796b77 100755 (executable)
@@ -28,7 +28,8 @@ dhcp4_client_classes VARCHAR(255) NULL ,
 dhcp6_client_classes VARCHAR(255) NULL ,
 PRIMARY KEY (host_id) ,
 INDEX key_dhcp4_identifier_subnet_id (dhcp_identifier ASC, dhcp_identifier_type ASC) ,
-INDEX key_dhcp6_identifier_subnet_id (dhcp_identifier ASC, dhcp_identifier_type ASC, dhcp6_subnet_id ASC) );
+INDEX key_dhcp6_identifier_subnet_id (dhcp_identifier ASC, dhcp_identifier_type ASC, dhcp6_subnet_id ASC) 
+) ENGINE = INNODB;
 
 CREATE TABLE IF NOT EXISTS ipv6_reservations (
 reservation_id INT NOT NULL AUTO_INCREMENT ,
@@ -43,7 +44,8 @@ CONSTRAINT fk_ipv6_reservations_Host
 FOREIGN KEY (host_id )
 REFERENCES hosts (host_id )
 ON DELETE NO ACTION
-ON UPDATE NO ACTION);
+ON UPDATE NO ACTION
+) ENGINE = INNODB;
 
 CREATE TABLE IF NOT EXISTS dhcp4_options (
 option_id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
@@ -62,7 +64,8 @@ CONSTRAINT fk_options_host1
 FOREIGN KEY (host_id )
 REFERENCES hosts (host_id )
 ON DELETE NO ACTION
-ON UPDATE NO ACTION);
+ON UPDATE NO ACTION
+) ENGINE = INNODB;
 
 CREATE TABLE IF NOT EXISTS dhcp6_options (
 option_id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
@@ -81,7 +84,8 @@ CONSTRAINT fk_options_host10
 FOREIGN KEY (host_id )
 REFERENCES hosts (host_id )
 ON DELETE NO ACTION
-ON UPDATE NO ACTION);
+ON UPDATE NO ACTION
+) ENGINE = INNODB;
 
 DELIMITER $$
 CREATE TRIGGER host_BDEL BEFORE DELETE ON hosts FOR EACH ROW
index 7992a382e385542b57ff80b25db18bcc936a21a5..696a8919ca0133c321f23aab9d7bcf3a5e282dd2 100644 (file)
@@ -1,4 +1,4 @@
 address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source,state
+10,3230,30,2015-04-04 01:15:30,40,50,IA_TA,60,70,1,1,one.example.com,3830,90,HWADDR_SOURCE_REMOTE_ID,default
 11,,30,2015-05-05 02:30:45,40,50,IA_TA,60,70,1,1,,3830,90,HWADDR_SOURCE_RAW,declined
 12,3231,30,2015-06-06 11:01:07,40,50,IA_TA,60,70,1,1,three.example.com,3830,90,HWADDR_SOURCE_DUID,expired-reclaimed
-10,3230,30,2015-04-04 01:15:30,40,50,IA_TA,60,70,1,1,one.example.com,3830,90,HWADDR_SOURCE_REMOTE_ID,default
index b78b5140fd1d2e97853f887e828c15a153321ed7..ff95170062fe4f5e513b6cbbfab4d733bc387e86 100644 (file)
@@ -84,7 +84,7 @@ CREATE INDEX lease6_by_iaid_subnet_id_duid ON lease6 (iaid, subnet_id, duid);
 CREATE TABLE lease6_types (
     lease_type TINYINT PRIMARY KEY NOT NULL,    # Lease type code.
     name VARCHAR(5)                             # Name of the lease type
-    );
+    ) ENGINE = INNODB;
 START TRANSACTION;
 INSERT INTO lease6_types VALUES (0, "IA_NA");   # Non-temporary v6 addresses
 INSERT INTO lease6_types VALUES (1, "IA_TA");   # Temporary v6 addresses
@@ -103,7 +103,7 @@ COMMIT;
 CREATE TABLE schema_version (
     version INT PRIMARY KEY NOT NULL,       # Major version number
     minor INT                               # Minor version number
-    );
+    ) ENGINE = INNODB;
 START TRANSACTION;
 INSERT INTO schema_version VALUES (1, 0);
 COMMIT;
index b8d77fbe7593ff06d14b45c2a339d889f58e7e69..4c39d6b25c1d8a7f90f85356ca77fc099e0266ea 100755 (executable)
@@ -38,11 +38,6 @@ keaadmin=@abs_top_builddir@/src/bin/admin/kea-admin
 mysql_wipe() {
     printf "Wiping whole database %s\n" $db_name
 
-    # ipv6_reservations table must be deleted first, as it has contraints that
-    # are dependent on hosts. Therefore hosts table cannot be deleted before
-    # ipv6_reservations.
-    mysql_execute "DROP TABLE IF EXISTS ipv6_reservations;"
-
     # First we build the list of drop table commands
     # We don't bother with "cascade" because as of MySQL
     # 5.1 it is only there to ease porting, it doesn't
index ade43e3e40a5c996ddbf0d245cf54425a5772606..8fdd4c91a371378e4d9976da2743e41c3d0d2e77 100644 (file)
@@ -122,7 +122,9 @@ void createMySQLSchema() {
     // Execute creation statements.
     for (int i = 0; create_statement[i] != NULL; ++i) {
         ASSERT_EQ(0, mysql_query(mysql, create_statement[i]))
-            << "Failed on statement " << i << ": " << create_statement[i];
+            << "Failed on statement " << i << ": " << create_statement[i]
+            << " error: " << mysql_error(mysql) << " (error code "
+            << mysql_errno(mysql) << ")";
     }
 }
 
index a62f24894863aa53eb6b9bd969aa45f740dbb167..b9fcf0ddbf7cbc62b7f58e39b0705df8af198d3c 100755 (executable)
@@ -32,15 +32,13 @@ namespace {
 // Deletion of existing tables.
 
 const char* destroy_statement[] = {
+    // Turning off referential integrity checks ensures tables get dropped
+    "SET SESSION FOREIGN_KEY_CHECKS = 0",
     "DROP TABLE lease4",
     "DROP TABLE lease6",
     "DROP TABLE lease6_types",
     "DROP TABLE lease_hwaddr_source",
     "DROP TABLE schema_version",
-
-    // We need to drop ipv6_reservations before hosts, as it has constrains
-    // that depend on hosts. Therefore hosts table cannot be deleted while
-    // ipv6_reservations exists.
     "DROP TABLE ipv6_reservations",
     "DROP TABLE hosts",
     "DROP TABLE dhcp4_options",
@@ -92,7 +90,7 @@ const char* create_statement[] = {
     "CREATE TABLE lease6_types ("
         "lease_type TINYINT PRIMARY KEY NOT NULL,"
         "name VARCHAR(5)"
-        ")",
+        ") ENGINE = INNODB",
 
     "INSERT INTO lease6_types VALUES (0, \"IA_NA\")",
     "INSERT INTO lease6_types VALUES (1, \"IA_TA\")",
@@ -101,7 +99,7 @@ const char* create_statement[] = {
     "CREATE TABLE schema_version ("
         "version INT PRIMARY KEY NOT NULL,"
         "minor INT"
-        ")",
+        ") ENGINE = INNODB",
 
     "INSERT INTO schema_version VALUES (1, 0)",
     "COMMIT",