Commit e7fd02a5 authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[3968] New constraints added to the upgrade scripts and tests.

Also, updated the lease_hwaddr_source table with missing
entries from the lease.cc.
parent f87000bd
......@@ -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 $$
......
......@@ -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 $$
......
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
......@@ -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);"
......
......@@ -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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment