]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5522] Fixed subnet_id column types in MySQL and Postgres schemas trac5522
authorThomas Markwalder <tmark@isc.org>
Thu, 22 Feb 2018 18:13:34 +0000 (13:13 -0500)
committerThomas Markwalder <tmark@isc.org>
Thu, 22 Feb 2018 18:13:34 +0000 (13:13 -0500)
new file:
    src/share/database/scripts/mysql/upgrade_5.1_to_5.2.sh.in
renamed:
    src/share/database/scripts/mysql/upgrade_5.1_to_6.0.sh.in
    -> src/share/database/scripts/mysql/upgrade_5.2_to_6.0.sh.in

new file:
    src/share/database/scripts/pgsql/upgrade_3.2_to_3.3.sh.in
renamed:
    src/share/database/scripts/pgsql/upgrade_3.2_to_4.0.sh.in
    -> src/share/database/scripts/pgsql/upgrade_3.3_to_4.0.sh.in

src/lib/dhcpsrv/pgsql_host_data_source.cc
    changed OID_INT4 to OID_INT8 for subnet_id inputs in
    TaggedStatements

src/lib/dhcpsrv/tests/generic_host_data_source_unittest.h
src/lib/dhcpsrv/tests/generic_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc
    Added new tests to verify maxium value for subnet_id works

src/share/database/scripts/mysql/dhcpdb_create.mysql
    Added 5.1 to 5.2 changes

src/share/database/scripts/pgsql/dhcpdb_create.pgsql
    Added 3.2 to 3.3 changes

17 files changed:
configure.ac
src/bin/admin/tests/mysql_tests.sh.in
src/lib/dhcpsrv/pgsql_host_data_source.cc
src/lib/dhcpsrv/tests/generic_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/generic_host_data_source_unittest.h
src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc
src/share/database/scripts/mysql/.gitignore
src/share/database/scripts/mysql/Makefile.am
src/share/database/scripts/mysql/dhcpdb_create.mysql
src/share/database/scripts/mysql/upgrade_5.1_to_5.2.sh.in [new file with mode: 0644]
src/share/database/scripts/mysql/upgrade_5.2_to_6.0.sh.in [moved from src/share/database/scripts/mysql/upgrade_5.1_to_6.0.sh.in with 91% similarity]
src/share/database/scripts/pgsql/.gitignore
src/share/database/scripts/pgsql/Makefile.am
src/share/database/scripts/pgsql/dhcpdb_create.pgsql
src/share/database/scripts/pgsql/upgrade_3.2_to_3.3.sh.in [new file with mode: 0644]
src/share/database/scripts/pgsql/upgrade_3.3_to_4.0.sh.in [moved from src/share/database/scripts/pgsql/upgrade_3.2_to_4.0.sh.in with 92% similarity]

index 3c332fd7fd7dbc574866f4b255f7377e90758d61..9604abcfab49f093efd216c40dcfcb6e4e0df9b3 100644 (file)
@@ -1445,13 +1445,15 @@ AC_CONFIG_FILES([Makefile
                  src/share/database/scripts/mysql/upgrade_4.0_to_4.1.sh
                  src/share/database/scripts/mysql/upgrade_4.1_to_5.0.sh
                  src/share/database/scripts/mysql/upgrade_5.0_to_5.1.sh
-                 src/share/database/scripts/mysql/upgrade_5.1_to_6.0.sh
+                 src/share/database/scripts/mysql/upgrade_5.1_to_5.2.sh
+                 src/share/database/scripts/mysql/upgrade_5.2_to_6.0.sh
                  src/share/database/scripts/pgsql/Makefile
                  src/share/database/scripts/pgsql/upgrade_1.0_to_2.0.sh
                  src/share/database/scripts/pgsql/upgrade_2.0_to_3.0.sh
                  src/share/database/scripts/pgsql/upgrade_3.0_to_3.1.sh
                  src/share/database/scripts/pgsql/upgrade_3.1_to_3.2.sh
-                 src/share/database/scripts/pgsql/upgrade_3.2_to_4.0.sh
+                 src/share/database/scripts/pgsql/upgrade_3.2_to_3.3.sh
+                 src/share/database/scripts/pgsql/upgrade_3.3_to_4.0.sh
                  tools/Makefile
                  tools/path_replacer.sh
 ])
index e5233c338db3efc687c64c0ba18586522d611241..8fc4b4455850f7c5b56ffda5ea1c13a13b93aa55 100644 (file)
@@ -363,7 +363,7 @@ EOF
     assert_eq 0 $ERRCODE "select from host_identifier_type failed. (expected status code %d, returned %d)"
     assert_eq 5 "$count" "host_identifier_type does not contain correct number of entries. (expected count %d, returned %d)"
     
-    #table: user_context columns to hosts, dhcp4_options and dhcp6_options (upgrade 5.1 -> 6.0)
+    #table: user_context columns to hosts, dhcp4_options and dhcp6_options (upgrade 5.2 -> 6.0)
     # verify that hosts table includes user_context
     qry="select user_context from hosts";
     count=`mysql_execute "${qry}"`
index 252f22cc4ce31a766b20cd7b3a189e64881b8b18..1df0be6f5cb97f5ff19b3cd11e53111c491874a2 100644 (file)
@@ -1497,7 +1497,7 @@ TaggedStatementArray tagged_statements = { {
     // and client's identifier. Left joining the dhcp4_options table results in
     // multiple rows being returned for the same host.
     {3,
-     { OID_INT4, OID_INT2, OID_BYTEA },
+     { OID_INT8, OID_INT2, OID_BYTEA },
      "get_host_subid4_dhcpid",
      "SELECT h.host_id, h.dhcp_identifier, h.dhcp_identifier_type, "
      "  h.dhcp4_subnet_id, h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
@@ -1517,7 +1517,7 @@ TaggedStatementArray tagged_statements = { {
     // associated with a host. The number of rows returned is a multiplication
     // of number of IPv6 reservations and DHCPv6 options.
     {3,
-     { OID_INT4, OID_INT2, OID_BYTEA },
+     { OID_INT8, OID_INT2, OID_BYTEA },
      "get_host_subid6_dhcpid",
      "SELECT h.host_id, h.dhcp_identifier, "
      "  h.dhcp_identifier_type, h.dhcp4_subnet_id, "
@@ -1541,7 +1541,7 @@ TaggedStatementArray tagged_statements = { {
     // results in multiple rows being returned for the host. The number of
     // rows depends on the number of options defined for the host.
     {2,
-     { OID_INT4, OID_INT8 },
+     { OID_INT8, OID_INT8 },
      "get_host_subid_addr",
      "SELECT h.host_id, h.dhcp_identifier, h.dhcp_identifier_type, "
      "  h.dhcp4_subnet_id, h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
@@ -1591,7 +1591,7 @@ TaggedStatementArray tagged_statements = { {
     // The number of rows returned is multiplication of number of existing
     // IPv6 reservations and DHCPv6 options.
     {2,
-     { OID_INT4, OID_VARCHAR },
+     { OID_INT8, OID_VARCHAR },
      "get_host_subid6_addr",
      "SELECT h.host_id, h.dhcp_identifier, "
      "  h.dhcp_identifier_type, h.dhcp4_subnet_id, "
@@ -1621,7 +1621,7 @@ TaggedStatementArray tagged_statements = { {
     // Inserts a host into the 'hosts' table. Returns the inserted host id.
     {12,
      { OID_BYTEA, OID_INT2,
-       OID_INT4, OID_INT4, OID_INT8, OID_VARCHAR,
+       OID_INT8, OID_INT8, OID_INT8, OID_VARCHAR,
        OID_VARCHAR, OID_VARCHAR, OID_TEXT },
      "insert_host",
      "INSERT INTO hosts(dhcp_identifier, dhcp_identifier_type, "
@@ -1669,7 +1669,7 @@ TaggedStatementArray tagged_statements = { {
     // PgSqlHostDataSourceImpl::DEL_HOST_ADDR4
     // Deletes a v4 host that matches (subnet-id, addr4)
     {2,
-     { OID_INT4, OID_INT8 },
+     { OID_INT8, OID_INT8 },
      "del_host_addr4",
      "DELETE FROM hosts WHERE dhcp4_subnet_id = $1 AND ipv4_address = $2"
     },
@@ -1677,7 +1677,7 @@ TaggedStatementArray tagged_statements = { {
     // PgSqlHostDataSourceImpl::DEL_HOST_SUBID4_ID
     // Deletes a v4 host that matches (subnet4-id, identifier-type, identifier)
     {3,
-     { OID_INT4, OID_INT2, OID_BYTEA },
+     { OID_INT8, OID_INT2, OID_BYTEA },
      "del_host_subid4_id",
      "DELETE FROM hosts WHERE dhcp4_subnet_id = $1 "
      "AND dhcp_identifier_type = $2 "
@@ -1687,7 +1687,7 @@ TaggedStatementArray tagged_statements = { {
     // PgSqlHostDataSourceImpl::DEL_HOST_SUBID6_ID
     // Deletes a v6 host that matches (subnet6-id, identifier-type, identifier)
     {3,
-     { OID_INT4, OID_INT2, OID_BYTEA },
+     { OID_INT8, OID_INT2, OID_BYTEA },
      "del_host_subid6_id",
      "DELETE FROM hosts WHERE dhcp6_subnet_id = $1 "
      "AND dhcp_identifier_type = $2 "
index 646e0ee4629ed7079e7ee3479d22b752e453c34c..02a8e8512ed442e68ae6276f020d762873d5843a 100644 (file)
@@ -18,7 +18,6 @@
 #include <dhcpsrv/tests/generic_host_data_source_unittest.h>
 #include <dhcpsrv/tests/test_utils.h>
 #include <dhcpsrv/testutils/schema.h>
-
 #include <boost/foreach.hpp>
 #include <dhcpsrv/testutils/host_data_source_utils.h>
 #include <gtest/gtest.h>
@@ -258,6 +257,67 @@ GenericHostDataSourceTest::testBasic4(const Host::IdentifierType& id) {
     HostDataSourceUtils::compareHosts(host, from_hds);
 }
 
+void 
+GenericHostDataSourceTest::testMaxSubnetId4() {
+    std::vector<uint8_t> ident;
+
+    ident = HostDataSourceUtils::generateIdentifier();
+    SubnetID subnet_id4 = numeric_limits<uint32_t>::max();
+    HostPtr host(new Host(&ident[0], ident.size(), Host::IDENT_DUID, 
+                          subnet_id4, 0, IOAddress("0.0.0.0")));
+
+    ASSERT_NO_THROW(addTestOptions(host, true, DHCP4_ONLY));
+    ASSERT_NO_THROW(hdsptr_->add(host));
+
+    // get4(subnet_id, identifier_type, identifier, identifier_size)
+    ConstHostPtr host_by_id = hdsptr_->get4(subnet_id4,
+                                            host->getIdentifierType(),
+                                            &host->getIdentifier()[0],
+                                            host->getIdentifier().size());
+
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, host_by_id));
+
+    // Now try to delete it: del4(subnet4-id, identifier-type, identifier)
+    EXPECT_TRUE(hdsptr_->del4(subnet_id4, Host::IDENT_DUID, &ident[0], 
+                              ident.size()));
+
+    host_by_id = hdsptr_->get4(subnet_id4, host->getIdentifierType(),
+                               &host->getIdentifier()[0],
+                               host->getIdentifier().size());
+
+    EXPECT_FALSE(host_by_id);
+}
+
+void GenericHostDataSourceTest::testMaxSubnetId6() {
+    std::vector<uint8_t> ident;
+
+    ident = HostDataSourceUtils::generateIdentifier();
+    SubnetID subnet_id6 = numeric_limits<uint32_t>::max();
+    HostPtr host(new Host(&ident[0], ident.size(), Host::IDENT_DUID, 
+                          0, subnet_id6, IOAddress("0.0.0.0")));
+
+    ASSERT_NO_THROW(addTestOptions(host, true, DHCP6_ONLY));
+    ASSERT_NO_THROW(hdsptr_->add(host));
+
+    // get6(subnet_id, identifier_type, identifier, identifier_size)
+    ConstHostPtr host_by_id = hdsptr_->get6(subnet_id6,
+                                            host->getIdentifierType(),
+                                            &host->getIdentifier()[0],
+                                            host->getIdentifier().size());
+
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, host_by_id));
+
+    // Now try to delete it: del6(subnet6-id, identifier-type, identifier)
+    EXPECT_TRUE(hdsptr_->del6(subnet_id6, Host::IDENT_DUID, &ident[0], 
+                              ident.size()));
+
+    host_by_id = hdsptr_->get4(subnet_id6, host->getIdentifierType(),
+                               &host->getIdentifier()[0],
+                               host->getIdentifier().size());
+
+    EXPECT_FALSE(host_by_id);
+}
+
 void
 GenericHostDataSourceTest::testGetByIPv4(const Host::IdentifierType& id) {
     // Make sure we have a pointer to the host data source.
index 9a507cdc1b6f887fc00dc80bd92a0fb4aed20a49..250943f5f1d5b9b0114a0ada75f0d73f9bd12e47 100644 (file)
@@ -312,6 +312,19 @@ public:
     /// @param id Identifier type.
     void testBasic4(const Host::IdentifierType& id);
 
+
+    /// @brief Test that Verifies that an IPv4 host reservation with
+    /// options can have a max value for dhcp4_subnet id
+    ///
+    /// Uses gtest macros to report failures.
+    void testMaxSubnetId4();
+
+    /// @brief Test that Verifies that an IPv6 host reservation with
+    /// options can have a max value for dhcp6_subnet id
+    ///
+    /// Uses gtest macros to report failures.
+    void testMaxSubnetId6();
+
     /// @brief Test inserts several hosts with unique IPv4 address and
     ///        checks that they can be retrieved properly.
     ///
index e40d965c07cf2f7012aab9ed8c34ed6130938731..93014ffb68f87785ed38f7a4b2020b551ff845be 100644 (file)
@@ -273,6 +273,18 @@ TEST_F(MySqlHostDataSourceTest, basic4HWAddr) {
     testBasic4(Host::IDENT_HWADDR);
 }
 
+// Verifies that IPv4 host reservation with options can have a max value
+// for  dhcp4_subnet id
+TEST_F(MySqlHostDataSourceTest, maxSubnetId4) {
+    testMaxSubnetId4();
+}
+
+// Verifies that IPv6 host reservation with options can have a max value
+// for  dhcp6_subnet id
+TEST_F(MySqlHostDataSourceTest, maxSubnetId6) {
+    testMaxSubnetId6();
+}
+
 // Test verifies if a host reservation can be added and later retrieved by IPv4
 // address. Host uses client-id (DUID) as identifier.
 TEST_F(MySqlHostDataSourceTest, basic4ClientId) {
index f575f5f50cc6ab0bbd9096068c6f4d19831fe426..219c577950983a86752a1ca44553eab5d14ff56a 100644 (file)
@@ -229,6 +229,18 @@ TEST_F(PgSqlHostDataSourceTest, basic4HWAddr) {
     testBasic4(Host::IDENT_HWADDR);
 }
 
+// Verifies that IPv4 host reservation with options can have a max value
+// for  dhcp4_subnet id
+TEST_F(PgSqlHostDataSourceTest, maxSubnetId4) {
+    testMaxSubnetId4();
+}
+
+// Verifies that IPv6 host reservation with options can have a max value
+// for  dhcp6_subnet id
+TEST_F(PgSqlHostDataSourceTest, maxSubnetId6) {
+    testMaxSubnetId6();
+}
+
 // Test verifies if a host reservation can be added and later retrieved by IPv4
 // address. Host uses client-id (DUID) as identifier.
 TEST_F(PgSqlHostDataSourceTest, basic4ClientId) {
index b5670c182380cce0ed79cb2a56bd670051ef69aa..8f9f1ce2bc73b382506637a9613693769e6a0b79 100644 (file)
@@ -4,4 +4,5 @@
 /upgrade_4.0_to_4.1.sh
 /upgrade_4.1_to_5.0.sh
 /upgrade_5.0_to_5.1.sh
-/upgrade_5.1_to_6.0.sh
+/upgrade_5.1_to_5.2.sh
+/upgrade_5.2_to_6.0.sh
index cfc8134d96307a99d4012e50045cc13d5b1aef54..eff6631399f481509e7266df54316dace0126d7e 100644 (file)
@@ -9,7 +9,8 @@ sqlscripts_DATA += upgrade_3.0_to_4.0.sh
 sqlscripts_DATA += upgrade_4.0_to_4.1.sh
 sqlscripts_DATA += upgrade_4.1_to_5.0.sh
 sqlscripts_DATA += upgrade_5.0_to_5.1.sh
-sqlscripts_DATA += upgrade_5.1_to_6.0.sh
+sqlscripts_DATA += upgrade_5.1_to_5.2.sh
+sqlscripts_DATA += upgrade_5.2_to_6.0.sh
 
 DISTCLEANFILES = upgrade_1.0_to_2.0.sh
 DISTCLEANFILES += upgrade_2.0_to_3.0.sh
@@ -17,6 +18,7 @@ DISTCLEANFILES += upgrade_3.0_to_4.0.sh
 DISTCLEANFILES += upgrade_4.0_to_4.1.sh
 DISTCLEANFILES += upgrade_4.1_to_5.0.sh
 DISTCLEANFILES += upgrade_5.0_to_5.1.sh
-DISTCLEANFILES += upgrade_5.1_to_6.0.sh
+DISTCLEANFILES += upgrade_5.1_to_5.2.sh
+DISTCLEANFILES += upgrade_5.2_to_6.0.sh
 
 EXTRA_DIST = ${sqlscripts_DATA}
index b1cdd1d05883f60f2ee61d97db4bda20691afa3c..c531ac35bb354ee060ef1421335d4f972225d784 100644 (file)
@@ -503,6 +503,16 @@ UPDATE schema_version
 SET version = '5', minor = '1';
 # This line concludes database upgrade to version 5.1.
 
+# Make subnet_id column types consistent with lease table columns
+ALTER TABLE dhcp4_options MODIFY dhcp4_subnet_id INT UNSIGNED;
+ALTER TABLE dhcp6_options MODIFY dhcp6_subnet_id INT UNSIGNED;
+
+# Update the schema version number
+UPDATE schema_version
+SET version = '5', minor = '2';
+
+# This line concludes database upgrade to version 5.2.
+
 # Add user context into table holding hosts
 ALTER TABLE hosts ADD COLUMN user_context TEXT NULL;
 
diff --git a/src/share/database/scripts/mysql/upgrade_5.1_to_5.2.sh.in b/src/share/database/scripts/mysql/upgrade_5.1_to_5.2.sh.in
new file mode 100644 (file)
index 0000000..b692f69
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+# Include utilities. Use installed version if available and
+# use build version if it isn't.
+if [ -e @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh ]; then
+    . @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh
+else
+    . @abs_top_builddir@/src/bin/admin/admin-utils.sh
+fi
+
+VERSION=`mysql_version "$@"`
+
+if [ "$VERSION" != "5.1" ]; then
+    printf "This script upgrades 5.1 to 5.2. Reported version is $VERSION. Skipping upgrade.\n"
+    exit 0
+fi
+
+mysql "$@" <<EOF
+
+# Make subnet_id column types consistent with lease table columns
+ALTER TABLE dhcp4_options MODIFY dhcp4_subnet_id INT UNSIGNED;
+ALTER TABLE dhcp6_options MODIFY dhcp6_subnet_id INT UNSIGNED;
+
+# Update the schema version number
+UPDATE schema_version
+SET version = '5', minor = '2';
+# This line concludes database upgrade to version 5.2.
+
+EOF
+
+RESULT=$?
+
+exit $?
similarity index 91%
rename from src/share/database/scripts/mysql/upgrade_5.1_to_6.0.sh.in
rename to src/share/database/scripts/mysql/upgrade_5.2_to_6.0.sh.in
index c4e78091289abf4d3bffdbfb66c9e4f163fa5857..49cd4fa9218da060042172150d70acf78a67a9c5 100644 (file)
@@ -10,8 +10,8 @@ fi
 
 VERSION=`mysql_version "$@"`
 
-if [ "$VERSION" != "5.1" ]; then
-    printf "This script upgrades 5.1 to 6.0. Reported version is $VERSION. Skipping upgrade.\n"
+if [ "$VERSION" != "5.2" ]; then
+    printf "This script upgrades 5.2 to 6.0. Reported version is $VERSION. Skipping upgrade.\n"
     exit 0
 fi
 
index ba0110be81d41d91fa77f044101dfa88dc3e1703..f4359801071b94153ff3373a3cb500af01937fec 100644 (file)
@@ -2,4 +2,5 @@ upgrade_1.0_to_2.0.sh
 upgrade_2.0_to_3.0.sh
 upgrade_3.0_to_3.1.sh
 upgrade_3.1_to_3.2.sh
-upgrade_3.2_to_4.0.sh
+upgrade_3.2_to_3.3.sh
+upgrade_3.3_to_4.0.sh
index 5c23ba4f499859054ee8ddc81bd48cc338cfa7c0..7187d143973194b639cc00211e4e8f2f9824f5aa 100644 (file)
@@ -7,12 +7,14 @@ sqlscripts_DATA += upgrade_1.0_to_2.0.sh
 sqlscripts_DATA += upgrade_2.0_to_3.0.sh
 sqlscripts_DATA += upgrade_3.0_to_3.1.sh
 sqlscripts_DATA += upgrade_3.1_to_3.2.sh
-sqlscripts_DATA += upgrade_3.2_to_4.0.sh
+sqlscripts_DATA += upgrade_3.2_to_3.3.sh
+sqlscripts_DATA += upgrade_3.3_to_4.0.sh
 
 DISTCLEANFILES = upgrade_1.0_to_2.0.sh
 DISTCLEANFILES += upgrade_2.0_to_3.0.sh
 DISTCLEANFILES += upgrade_3.0_to_3.1.sh
 DISTCLEANFILES += upgrade_3.1_to_3.2.sh
-DISTCLEANFILES += upgrade_3.2_to_4.0.sh
+DISTCLEANFILES += upgrade_3.2_to_3.3.sh
+DISTCLEANFILES += upgrade_3.3_to_4.0.sh
 
 EXTRA_DIST = ${sqlscripts_DATA}
index 90d1aed7da55cc0eb40bc9b00fe514009d4d0213..d14e3753e89c3b82a684243635fead70c9cc60d1 100644 (file)
@@ -483,6 +483,8 @@ UPDATE schema_version
 
 -- Schema 3.0 specification ends here.
 
+-- Upgrade to schema 3.1 begins here:
+
 -- This is a placeholder for the changes between 3.0 and 3.1. We have added a
 -- missing 'client-id' host reservation type entry that had been accidentally
 -- omitted when the 2.0 -> 3.0 upgrade script was created.
@@ -493,7 +495,9 @@ INSERT INTO host_identifier_type VALUES (4, 'flex-id');
 UPDATE schema_version
     SET version = '3', minor = '1';
 
--- Set 3.2 schema version.
+-- Schema 3.1 specification ends here.
+
+-- Upgrade to schema 3.2 begins here:
 
 -- Remove constraints which perform too restrictive checks on the inserted
 -- host reservations. We want to be able to insert host reservations which
@@ -528,7 +532,24 @@ CREATE UNIQUE INDEX key_dhcp6_identifier_subnet_id ON hosts
 UPDATE schema_version
     SET version = '3', minor = '2';
 
--- Set 4.0 schema version.
+-- Schema 3.2 specification ends here.
+
+-- Upgrade to schema 3.3 begins here:
+
+-- Change subnet ID columns type to BIGINT to match lease4/6 tables 
+ALTER TABLE hosts ALTER COLUMN dhcp4_subnet_id TYPE BIGINT;
+ALTER TABLE hosts ALTER COLUMN dhcp6_subnet_id TYPE BIGINT;
+
+ALTER TABLE dhcp4_options ALTER COLUMN dhcp4_subnet_id TYPE BIGINT;
+ALTER TABLE dhcp6_options ALTER COLUMN dhcp6_subnet_id TYPE BIGINT;
+
+-- Set 3.3 schema version.
+UPDATE schema_version
+    SET version = '3', minor = '3';
+
+-- Schema 3.3 specification ends here.
+
+-- Upgrade to schema 4.0 begins here:
 
 -- Add a column holding hosts for user context.
 ALTER TABLE hosts ADD COLUMN user_context TEXT;
@@ -547,6 +568,8 @@ CREATE INDEX lease6_by_subnet_id_lease_type ON lease6 (subnet_id, lease_type);
 UPDATE schema_version
     SET version = '4', minor = '0';
 
+-- Schema 4.0 specification ends here.
+
 -- Commit the script transaction.
 COMMIT;
 
diff --git a/src/share/database/scripts/pgsql/upgrade_3.2_to_3.3.sh.in b/src/share/database/scripts/pgsql/upgrade_3.2_to_3.3.sh.in
new file mode 100644 (file)
index 0000000..b8c7248
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+# Include utilities. Use installed version if available and
+# use build version if it isn't.
+if [ -e @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh ]; then
+    . @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh
+else
+    . @abs_top_builddir@/src/bin/admin/admin-utils.sh
+fi
+
+VERSION=`pgsql_version "$@"`
+
+if [ "$VERSION" != "3.2" ]; then
+    printf "This script upgrades 3.2 to 3.3. Reported version is $VERSION. Skipping upgrade.\n"
+    exit 0
+fi
+
+psql "$@" >/dev/null <<EOF
+
+START TRANSACTION;
+
+-- Change subnet ID columns type to BIGINT to match lease4/6 tables 
+ALTER TABLE hosts ALTER COLUMN dhcp4_subnet_id TYPE BIGINT;
+ALTER TABLE hosts ALTER COLUMN dhcp6_subnet_id TYPE BIGINT;
+
+ALTER TABLE dhcp4_options ALTER COLUMN dhcp4_subnet_id TYPE BIGINT;
+ALTER TABLE dhcp6_options ALTER COLUMN dhcp6_subnet_id TYPE BIGINT;
+
+-- Set 3.3 schema version.
+UPDATE schema_version
+    SET version = '3', minor = '3';
+
+-- Schema 3.3 specification ends here.
+
+-- Commit the script transaction
+COMMIT;
+
+EOF
+
+exit $RESULT
similarity index 92%
rename from src/share/database/scripts/pgsql/upgrade_3.2_to_4.0.sh.in
rename to src/share/database/scripts/pgsql/upgrade_3.3_to_4.0.sh.in
index c20e114f2a344cef067ff9a27b80439c4557d793..b94ea081f64ec5653d6593fa11b0d0a17cb989e7 100644 (file)
@@ -10,8 +10,8 @@ fi
 
 VERSION=`pgsql_version "$@"`
 
-if [ "$VERSION" != "3.2" ]; then
-    printf "This script upgrades 3.2 to 4.0. Reported version is $VERSION. Skipping upgrade.\n"
+if [ "$VERSION" != "3.3" ]; then
+    printf "This script upgrades 3.3 to 4.0. Reported version is $VERSION. Skipping upgrade.\n"
     exit 0
 fi