From: Marcin Siodelski Date: Thu, 15 Oct 2015 17:57:15 +0000 (+0200) Subject: [3968] Added additional constraints to mysql creation script. X-Git-Tag: trac3874_base~1^2~4 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=acb688a9cb6b5d4ebb1b4f18dc084af43d73e59c;p=thirdparty%2Fkea.git [3968] Added additional constraints to mysql creation script. --- diff --git a/src/bin/admin/scripts/mysql/dhcpdb_create.mysql b/src/bin/admin/scripts/mysql/dhcpdb_create.mysql index c30b463ffa..65b2cbc5b9 100755 --- a/src/bin/admin/scripts/mysql/dhcpdb_create.mysql +++ b/src/bin/admin/scripts/mysql/dhcpdb_create.mysql @@ -273,7 +273,36 @@ 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; + +# 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); + +# 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); # Insert currently defined state names. INSERT INTO lease_state VALUES (0, "default");