]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3968] Updated PostgreSQL schema per review comments.
authorMarcin Siodelski <marcin@isc.org>
Thu, 15 Oct 2015 20:00:42 +0000 (22:00 +0200)
committerMarcin Siodelski <marcin@isc.org>
Thu, 15 Oct 2015 20:00:42 +0000 (22:00 +0200)
src/bin/admin/scripts/pgsql/dhcpdb_create.pgsql
src/lib/dhcpsrv/tests/schema_pgsql_copy.h

index 9805e8f97e77302a4c64c666b448f548621d17ee..72b1e64b017ed945ef7d23b24c0639b69fb92afe 100644 (file)
@@ -119,8 +119,8 @@ ALTER TABLE lease6
 -- by the expiration time. One of the applications is to retrieve all
 -- expired leases. However, these indexes can be also used to retrieve
 -- leases in a given state regardless of the expiration time.
-CREATE INDEX lease4_by_state_expire ON lease4 (state, expire);
-CREATE INDEX lease6_by_state_expire ON lease6 (state, expire);
+CREATE INDEX lease4_by_state_expire ON lease4 (state ASC, expire ASC);
+CREATE INDEX lease6_by_state_expire ON lease6 (state ASC, expire ASC);
 
 -- Create table holding mapping of the lease states to their names.
 -- This is not used in queries from the DHCP server but rather in
@@ -136,6 +136,24 @@ INSERT INTO lease_state VALUES (1, 'declined');
 INSERT INTO lease_state VALUES (2, 'expired-reclaimed');
 COMMIT;
 
+-- 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);
+
 --
 --  FUNCTION that returns a result set containing the column names for lease4 dumps
 DROP FUNCTION IF EXISTS lease4DumpHeader();
index 17aa414ad04da2c59f48824d185f6f1b3c87f676..8135f9bca6b96ddfb03f301e056be00784cbc34b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
@@ -97,8 +97,8 @@ const char* create_statement[] = {
     "ALTER TABLE lease6 "
         "ADD COLUMN state INT8 DEFAULT 0",
 
-    "CREATE INDEX lease4_by_state_expire ON lease4 (state, expire)",
-    "CREATE INDEX lease6_by_state_expire ON lease6 (state, expire)",
+    "CREATE INDEX lease4_by_state_expire ON lease4 (state ASC, expire ASC)",
+    "CREATE INDEX lease6_by_state_expire ON lease6 (state ASC, expire ASC)",
 
     // Production schema includes the lease_state table which maps
     // the lease states to their names. This is not used in the unit tests
@@ -108,6 +108,18 @@ const char* create_statement[] = {
         "state INT8 PRIMARY KEY NOT NULL,"
         "name VARCHAR(64) NOT NULL);",
 
+    "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)",
+
     "INSERT INTO lease_state VALUES (0, \"default\");",
     "INSERT INTO lease_state VALUES (1, \"declined\");",
     "INSERT INTO lease_state VALUES (2, \"expired-reclaimed\");",*/