src/share/database/scripts/pgsql/upgrade_4.0_to_5.0.sh
src/share/database/scripts/pgsql/upgrade_5.0_to_5.1.sh
src/share/database/scripts/pgsql/upgrade_5.1_to_6.0.sh
+ src/share/database/scripts/pgsql/upgrade_6.0_to_6.1.sh
src/share/database/scripts/pgsql/wipe_data.sh
src/share/yang/Makefile
src/share/yang/modules/Makefile
#!/bin/sh
-# Copyright (C) 2015-2019 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2015-2020 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# Verify that kea-admin db-version returns the correct version
version=$(${keaadmin} db-version pgsql -u $db_user -p $db_password -n $db_name)
- assert_str_eq "6.0" ${version} "Expected kea-admin to return %s, returned value was %s"
+ assert_str_eq "6.1" ${version} "Expected kea-admin to return %s, returned value was %s"
# Let's wipe the whole database
pgsql_wipe
assert_eq 1 "$output" "lease_hwaddr_source does not contain entry for HWADDR_SOURCE_UNKNOWN. (record count %d, expected %d)"
}
-pgsql_upgrade_3_0_to_6_0() {
- # Verify upgraded schema reports version 6.0.
+pgsql_upgrade_3_0_to_6_1() {
+ # Verify upgraded schema reports version 6.1.
version=$(${keaadmin} db-version pgsql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir)
- assert_str_eq "6.0" ${version} "Expected kea-admin to return %s, returned value was %s"
+ assert_str_eq "6.1" ${version} "Expected kea-admin to return %s, returned value was %s"
# Added user_context to lease4
output=`pgsql_execute "select user_context from lease4;"`
# Check 2.0 to 3.0 upgrade
pgsql_upgrade_2_0_to_3_0
- # Check 3.0 to 6.0 upgrade
- pgsql_upgrade_3_0_to_6_0
+ # Check 3.0 to 6.1 upgrade
+ pgsql_upgrade_3_0_to_6_1
# Let's wipe the whole database
pgsql_wipe
namespace isc {
namespace db {
-/// @brief Define PostgreSQL backend version: 6.0
+/// @brief Define PostgreSQL backend version: 6.1
const uint32_t PG_SCHEMA_VERSION_MAJOR = 6;
-const uint32_t PG_SCHEMA_VERSION_MINOR = 0;
+const uint32_t PG_SCHEMA_VERSION_MINOR = 1;
// Maximum number of parameters that can be used a statement
// @todo This allows us to use an initializer list (since we can't
/upgrade_4.0_to_5.0.sh
/upgrade_5.0_to_5.1.sh
/upgrade_5.1_to_6.0.sh
+/upgrade_6.0_to_6.1.sh
/wipe_data.sh
sqlscripts_DATA += upgrade_4.0_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_6.0_to_6.1.sh
sqlscripts_DATA += wipe_data.sh
DISTCLEANFILES = upgrade_1.0_to_2.0.sh
DISTCLEANFILES += upgrade_4.0_to_5.0.sh
DISTCLEANFILES += upgrade_5.0_to_5.1.sh
DISTCLEANFILES += upgrade_5.1_to_6.0.sh
+DISTCLEANFILES += upgrade_6.0_to_6.1.sh
DISTCLEANFILES += wipe_data.sh
EXTRA_DIST = ${sqlscripts_DATA}
UPDATE schema_version
SET version = '6', minor = '0';
--- Schema 5.1a specification ends here.
+-- Schema 6.0 specification ends here.
+
+-- Commit the script transaction
+COMMIT;
+
+-- Upgrade to schema 6.1 begins here:
+
+START TRANSACTION;
+
+-- Fix v4 update trigger procedure
+CREATE OR REPLACE FUNCTION proc_stat_lease4_update () RETURNS trigger AS $stat_lease4_update$
+BEGIN
+ IF OLD.subnet_id != NEW.subnet_id OR OLD.state != NEW.state THEN
+ IF OLD.state < 2 THEN
+ -- Decrement the old state count if record exists
+ UPDATE lease4_stat SET leases = GREATEST(leases - 1, 0)
+ WHERE subnet_id = OLD.subnet_id AND state = OLD.state;
+ END IF;
+
+ IF NEW.state < 2 THEN
+ -- Increment the new state count if record exists
+ UPDATE lease4_stat SET leases = leases + 1
+ WHERE subnet_id = NEW.subnet_id AND state = NEW.state;
+
+ -- Insert new state record if it does not exist
+ IF NOT FOUND THEN
+ INSERT INTO lease4_stat VALUES (NEW.subnet_id, NEW.state, 1);
+ END IF;
+ END IF;
+ END IF;
+
+ -- Return is ignored since this is an after insert
+ RETURN NULL;
+END;
+$stat_lease4_update$ LANGUAGE plpgsql;
+
+--
+-- Fix the v4 delete trigger procedure
+CREATE OR REPLACE FUNCTION proc_stat_lease4_delete () RETURNS trigger AS $stat_lease4_delete$
+BEGIN
+ IF OLD.state < 2 THEN
+ -- Decrement the state count if record exists
+ UPDATE lease4_stat SET leases = GREATEST(leases - 1, 0)
+ WHERE subnet_id = OLD.subnet_id AND OLD.state = state;
+ END IF;
+
+ -- Return is ignored since this is an after insert
+ RETURN NULL;
+END;
+$stat_lease4_delete$ LANGUAGE plpgsql;
+
+--
+-- Fix v6 update trigger procedure
+CREATE OR REPLACE FUNCTION proc_stat_lease6_update () RETURNS trigger AS $stat_lease6_update$
+BEGIN
+ IF OLD.subnet_id != NEW.subnet_id OR
+ OLD.lease_type != NEW.lease_type OR
+ OLD.state != NEW.state THEN
+ IF OLD.state < 2 THEN
+ -- Decrement the old state count if record exists
+ UPDATE lease6_stat SET leases = GREATEST(leases - 1, 0)
+ WHERE subnet_id = OLD.subnet_id AND lease_type = OLD.lease_type
+ AND state = OLD.state;
+ END IF;
+
+ IF NEW.state < 2 THEN
+ -- Increment the new state count if record exists
+ UPDATE lease6_stat SET leases = leases + 1
+ WHERE subnet_id = NEW.subnet_id AND lease_type = NEW.lease_type
+ AND state = NEW.state;
+
+ -- Insert new state record if it does not exist
+ IF NOT FOUND THEN
+ INSERT INTO lease6_stat VALUES (NEW.subnet_id, NEW.lease_type, NEW.state, 1);
+ END IF;
+ END IF;
+ END IF;
+
+ -- Return is ignored since this is an after insert
+ RETURN NULL;
+END;
+$stat_lease6_update$ LANGUAGE plpgsql;
+
+--
+-- Fix the v6 delete trigger procedure
+CREATE OR REPLACE FUNCTION proc_stat_lease6_delete() RETURNS trigger AS $stat_lease6_delete$
+BEGIN
+ IF OLD.state < 2 THEN
+ -- Decrement the state count if record exists
+ UPDATE lease6_stat SET leases = GREATEST(leases - 1, 0)
+ WHERE subnet_id = OLD.subnet_id AND lease_type = OLD.lease_type
+ AND OLD.state = state;
+ END IF;
+
+ -- Return is ignored since this is an after insert
+ RETURN NULL;
+END;
+$stat_lease6_delete$ LANGUAGE plpgsql;
+
+-- Set 6.1 schema version.
+UPDATE schema_version
+ SET version = '6', minor = '1';
+
+-- Schema 6.1 specification ends here.
-- Commit the script transaction
COMMIT;
--- /dev/null
+#!/bin/sh
+
+prefix=@prefix@
+# 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" != "6.0" ]; then
+ printf "This script upgrades 6.0 to 6.1. Reported version is $VERSION. Skipping upgrade.\n"
+ exit 0
+fi
+
+psql "$@" >/dev/null <<EOF
+
+START TRANSACTION;
+
+-- Fix v4 update trigger procedure
+CREATE OR REPLACE FUNCTION proc_stat_lease4_update () RETURNS trigger AS $stat_lease4_update$
+BEGIN
+ IF OLD.subnet_id != NEW.subnet_id OR OLD.state != NEW.state THEN
+ IF OLD.state < 2 THEN
+ -- Decrement the old state count if record exists
+ UPDATE lease4_stat SET leases = GREATEST(leases - 1, 0)
+ WHERE subnet_id = OLD.subnet_id AND state = OLD.state;
+ END IF;
+
+ IF NEW.state < 2 THEN
+ -- Increment the new state count if record exists
+ UPDATE lease4_stat SET leases = leases + 1
+ WHERE subnet_id = NEW.subnet_id AND state = NEW.state;
+
+ -- Insert new state record if it does not exist
+ IF NOT FOUND THEN
+ INSERT INTO lease4_stat VALUES (NEW.subnet_id, NEW.state, 1);
+ END IF;
+ END IF;
+ END IF;
+
+ -- Return is ignored since this is an after insert
+ RETURN NULL;
+END;
+$stat_lease4_update$ LANGUAGE plpgsql;
+
+--
+-- Fix the v4 delete trigger procedure
+CREATE OR REPLACE FUNCTION proc_stat_lease4_delete () RETURNS trigger AS $stat_lease4_delete$
+BEGIN
+ IF OLD.state < 2 THEN
+ -- Decrement the state count if record exists
+ UPDATE lease4_stat SET leases = GREATEST(leases - 1, 0)
+ WHERE subnet_id = OLD.subnet_id AND OLD.state = state;
+ END IF;
+
+ -- Return is ignored since this is an after insert
+ RETURN NULL;
+END;
+$stat_lease4_delete$ LANGUAGE plpgsql;
+
+--
+-- Fix v6 update trigger procedure
+CREATE OR REPLACE FUNCTION proc_stat_lease6_update () RETURNS trigger AS $stat_lease6_update$
+BEGIN
+ IF OLD.subnet_id != NEW.subnet_id OR
+ OLD.lease_type != NEW.lease_type OR
+ OLD.state != NEW.state THEN
+ IF OLD.state < 2 THEN
+ -- Decrement the old state count if record exists
+ UPDATE lease6_stat SET leases = GREATEST(leases - 1, 0)
+ WHERE subnet_id = OLD.subnet_id AND lease_type = OLD.lease_type
+ AND state = OLD.state;
+ END IF;
+
+ IF NEW.state < 2 THEN
+ -- Increment the new state count if record exists
+ UPDATE lease6_stat SET leases = leases + 1
+ WHERE subnet_id = NEW.subnet_id AND lease_type = NEW.lease_type
+ AND state = NEW.state;
+
+ -- Insert new state record if it does not exist
+ IF NOT FOUND THEN
+ INSERT INTO lease6_stat VALUES (NEW.subnet_id, NEW.lease_type, NEW.state, 1);
+ END IF;
+ END IF;
+ END IF;
+
+ -- Return is ignored since this is an after insert
+ RETURN NULL;
+END;
+$stat_lease6_update$ LANGUAGE plpgsql;
+
+--
+-- Fix the v6 delete trigger procedure
+CREATE OR REPLACE FUNCTION proc_stat_lease6_delete() RETURNS trigger AS $stat_lease6_delete$
+BEGIN
+ IF OLD.state < 2 THEN
+ -- Decrement the state count if record exists
+ UPDATE lease6_stat SET leases = GREATEST(leases - 1, 0)
+ WHERE subnet_id = OLD.subnet_id AND lease_type = OLD.lease_type
+ AND OLD.state = state;
+ END IF;
+
+ -- Return is ignored since this is an after insert
+ RETURN NULL;
+END;
+$stat_lease6_delete$ LANGUAGE plpgsql;
+
+-- Set 6.1 schema version.
+UPDATE schema_version
+ SET version = '6', minor = '1';
+
+-- Schema 6.1 specification ends here.
+
+-- Commit the script transaction
+COMMIT;
+
+EOF
+
+exit $RESULT
+