]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3968] Added additional constraints to mysql creation script.
authorMarcin Siodelski <marcin@isc.org>
Thu, 15 Oct 2015 17:57:15 +0000 (19:57 +0200)
committerMarcin Siodelski <marcin@isc.org>
Thu, 15 Oct 2015 17:57:15 +0000 (19:57 +0200)
src/bin/admin/scripts/mysql/dhcpdb_create.mysql

index c30b463ffa2a57d133c3060f904631e44c7f3db7..65b2cbc5b9e27ff712328ac0383d8a37776a6971 100755 (executable)
@@ -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");