From: Marcin Siodelski Date: Thu, 15 Oct 2015 19:33:38 +0000 (+0200) Subject: [3968] New constraints added to the upgrade scripts and tests. X-Git-Tag: trac3874_base~1^2~2 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=e7fd02a54c3ab00612495e8fd5028f6bac2ed22c;p=thirdparty%2Fkea.git [3968] New constraints added to the upgrade scripts and tests. Also, updated the lease_hwaddr_source table with missing entries from the lease.cc. --- diff --git a/src/bin/admin/scripts/mysql/dhcpdb_create.mysql b/src/bin/admin/scripts/mysql/dhcpdb_create.mysql index 4b0c4656ec..cdcc46ac7a 100755 --- a/src/bin/admin/scripts/mysql/dhcpdb_create.mysql +++ b/src/bin/admin/scripts/mysql/dhcpdb_create.mysql @@ -276,6 +276,11 @@ CREATE TABLE IF NOT EXISTS lease_state ( name VARCHAR(64) NOT NULL ) ENGINE=INNODB; +# Insert currently defined state names. +INSERT INTO lease_state VALUES (0, "default"); +INSERT INTO lease_state VALUES (1, "declined"); +INSERT INTO lease_state VALUES (2, "expired-reclaimed"); + # Add a constraint that any state value added to the lease4 must # map to a value in the lease_state table. ALTER TABLE lease4 @@ -294,9 +299,16 @@ ALTER TABLE lease6 ADD CONSTRAINT fk_lease6_type FOREIGN KEY (lease_type) REFERENCES lease6_types (lease_type); +# Modify the name of one of the HW address sources, and add a new one. +UPDATE lease_hwaddr_source + SET name = 'HWADDR_SOURCE_DOCSIS_CMTS' + WHERE hwaddr_source = 64; + +INSERT INTO lease_hwaddr_source VALUES (128, 'HWADDR_SOURCE_DOCSIS_MODEM'); + # Add UNSIGNED to match with the lease6. ALTER TABLE lease_hwaddr_source - MODIFY COLUMN hwaddr_source INT UNSIGNED NOT NULL DEFAULT 0; + MODIFY COLUMN hwaddr_source INT UNSIGNED NOT NULL; # Add a constraint that non-null hwaddr_source in the lease6 table # must map to an entry in the lease_hwaddr_source. @@ -304,11 +316,6 @@ ALTER TABLE lease6 ADD CONSTRAINT fk_lease6_hwaddr_source FOREIGN KEY (hwaddr_source) REFERENCES lease_hwaddr_source (hwaddr_source); -# Insert currently defined state names. -INSERT INTO lease_state VALUES (0, "default"); -INSERT INTO lease_state VALUES (1, "declined"); -INSERT INTO lease_state VALUES (2, "expired-reclaimed"); - # FUNCTION that returns a result set containing the column names for lease4 dumps DROP PROCEDURE IF EXISTS lease4DumpHeader; DELIMITER $$ diff --git a/src/bin/admin/scripts/mysql/upgrade_3.0_to_4.0.sh.in b/src/bin/admin/scripts/mysql/upgrade_3.0_to_4.0.sh.in index 930b457e2c..ae18cb83a1 100755 --- a/src/bin/admin/scripts/mysql/upgrade_3.0_to_4.0.sh.in +++ b/src/bin/admin/scripts/mysql/upgrade_3.0_to_4.0.sh.in @@ -36,13 +36,49 @@ CREATE INDEX lease6_by_state_expire ON lease6 (state, expire); # direct queries from the lease database management tools. CREATE TABLE IF NOT EXISTS lease_state ( state INT UNSIGNED PRIMARY KEY NOT NULL, - name VARCHAR(64) NOT NULL); + name VARCHAR(64) NOT NULL +) ENGINE=INNODB; # Insert currently defined state names. INSERT INTO lease_state VALUES (0, "default"); INSERT INTO lease_state VALUES (1, "declined"); INSERT INTO lease_state VALUES (2, "expired-reclaimed"); +# Add a constraint that any state value added to the lease4 must +# map to a value in the lease_state table. +ALTER TABLE lease4 + ADD CONSTRAINT fk_lease4_state FOREIGN KEY (state) + REFERENCES lease_state (state); + +# Add a constraint that any state value added to the lease6 must +# map to a value in the lease_state table. +ALTER TABLE lease6 + ADD CONSTRAINT fk_lease6_state FOREIGN KEY (state) + REFERENCES lease_state (state); + +# Add a constraint that lease type in the lease6 table must map +# to a lease type defined in the lease6_types table. +ALTER TABLE lease6 + ADD CONSTRAINT fk_lease6_type FOREIGN KEY (lease_type) + REFERENCES lease6_types (lease_type); + +# Modify the name of one of the HW address sources, and add a new one. +UPDATE lease_hwaddr_source + SET name = 'HWADDR_SOURCE_DOCSIS_CMTS' + WHERE hwaddr_source = 64; + +INSERT INTO lease_hwaddr_source VALUES (128, 'HWADDR_SOURCE_DOCSIS_MODEM'); + +# Add UNSIGNED to match with the lease6. +ALTER TABLE lease_hwaddr_source + MODIFY COLUMN hwaddr_source INT UNSIGNED NOT NULL DEFAULT 0; + +# Add a constraint that non-null hwaddr_source in the lease6 table +# must map to an entry in the lease_hwaddr_source. +ALTER TABLE lease6 + ADD CONSTRAINT fk_lease6_hwaddr_source FOREIGN KEY (hwaddr_source) + REFERENCES lease_hwaddr_source (hwaddr_source); + # FUNCTION that returns a result set containing the column names for lease4 dumps DROP PROCEDURE IF EXISTS lease4DumpHeader; DELIMITER $$ diff --git a/src/bin/admin/tests/data/mysql.lease6_dump_test.reference.csv b/src/bin/admin/tests/data/mysql.lease6_dump_test.reference.csv index 3d530d8b9c..7992a382e3 100644 --- a/src/bin/admin/tests/data/mysql.lease6_dump_test.reference.csv +++ b/src/bin/admin/tests/data/mysql.lease6_dump_test.reference.csv @@ -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,,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 diff --git a/src/bin/admin/tests/mysql_tests.sh.in b/src/bin/admin/tests/mysql_tests.sh.in index b4d3ddeed3..b8d77fbe75 100755 --- a/src/bin/admin/tests/mysql_tests.sh.in +++ b/src/bin/admin/tests/mysql_tests.sh.in @@ -395,7 +395,7 @@ mysql_lease6_dump_test() { # Insert the reference record insert_sql="\ -insert into lease6 values(10,20,30,\"2015-04-04 01:15:30\",40,50,1,60,70,1,1,\"one.example.com\",80,90,0,0);\ +insert into lease6 values(10,20,30,\"2015-04-04 01:15:30\",40,50,1,60,70,1,1,\"one.example.com\",80,90,16,0);\ insert into lease6 values(11,NULL,30,\"2015-05-05 02:30:45\",40,50,1,60,70,1,1,\"\",80,90,1,1);\ insert into lease6 values(12,21,30,\"2015-06-06 11:01:07\",40,50,1,60,70,1,1,\"three.example.com\",80,90,4,2);" diff --git a/src/lib/dhcpsrv/tests/schema_mysql_copy.h b/src/lib/dhcpsrv/tests/schema_mysql_copy.h index ae07e98520..ba32dd7212 100755 --- a/src/lib/dhcpsrv/tests/schema_mysql_copy.h +++ b/src/lib/dhcpsrv/tests/schema_mysql_copy.h @@ -223,8 +223,9 @@ const char* create_statement[] = { "CREATE INDEX lease4_by_state_expire ON lease4 (state, expire)", "CREATE INDEX lease6_by_state_expire ON lease6 (state, expire)", - // Production schema includes the lease_state table which maps - // the lease states to their names. This is not used in the unit tests + // Production schema includes the lease_state table and + // lease_hwaddr_source tables which map to the values in lease4 + // and lease6 tables. This is not used in the unit tests // so it is commented out. /*"CREATE TABLE IF NOT EXISTS lease_state (", @@ -233,8 +234,32 @@ const char* create_statement[] = { "INSERT INTO lease_state VALUES (0, \"default\");", "INSERT INTO lease_state VALUES (1, \"declined\");", - "INSERT INTO lease_state VALUES (2, \"expired-reclaimed\");",*/ + "INSERT INTO lease_state VALUES (2, \"expired-reclaimed\");", + "ALTER TABLE lease4 " + "ADD CONSTRAINT fk_lease4_state FOREIGN KEY (state) " + "REFERENCES lease_state (state)", + + "ALTER TABLE lease6 " + "ADD CONSTRAINT fk_lease6_state FOREIGN KEY (state) " + "REFERENCES lease_state (state)", + + "ALTER TABLE lease6 " + "ADD CONSTRAINT fk_lease6_type FOREIGN KEY (lease_type) " + "REFERENCES lease6_types (lease_type)", + + "UPDATE lease_hwaddr_source " + "SET name = 'HWADDR_SOURCE_DOCSIS_CMTS' " + "WHERE hwaddr_source = 64", + + "INSERT INTO lease_hwaddr_source VALUES (128, 'HWADDR_SOURCE_DOCSIS_MODEM')", + + "ALTER TABLE lease_hwaddr_source " + "MODIFY COLUMN hwaddr_source INT UNSIGNED NOT NULL DEFAULT 0", + + "ALTER TABLE lease6 " + "ADD CONSTRAINT fk_lease6_hwaddr_source FOREIGN KEY (hwaddr_source) " + "REFERENCES lease_hwaddr_source (hwaddr_source)",*/ // Schema upgrade to 4.0 ends here.