# 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");