From: Marcin Siodelski Date: Thu, 15 Oct 2015 20:00:42 +0000 (+0200) Subject: [3968] Updated PostgreSQL schema per review comments. X-Git-Tag: trac3874_base~1^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1756b9dfaad8a45cb587c91a13c49cbf5a926a9a;p=thirdparty%2Fkea.git [3968] Updated PostgreSQL schema per review comments. --- diff --git a/src/bin/admin/scripts/pgsql/dhcpdb_create.pgsql b/src/bin/admin/scripts/pgsql/dhcpdb_create.pgsql index 9805e8f97e..72b1e64b01 100644 --- a/src/bin/admin/scripts/pgsql/dhcpdb_create.pgsql +++ b/src/bin/admin/scripts/pgsql/dhcpdb_create.pgsql @@ -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(); diff --git a/src/lib/dhcpsrv/tests/schema_pgsql_copy.h b/src/lib/dhcpsrv/tests/schema_pgsql_copy.h index 17aa414ad0..8135f9bca6 100644 --- a/src/lib/dhcpsrv/tests/schema_pgsql_copy.h +++ b/src/lib/dhcpsrv/tests/schema_pgsql_copy.h @@ -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\");",*/