Commit e65bdbe4 authored by Francis Dupont's avatar Francis Dupont

[#1196] Updated schema version

parent 732505e5
......@@ -1729,6 +1729,7 @@ AC_CONFIG_FILES([Makefile
src/share/database/scripts/mysql/upgrade_8.2_to_9.0.sh
src/share/database/scripts/mysql/upgrade_9.0_to_9.1.sh
src/share/database/scripts/mysql/upgrade_9.1_to_9.2.sh
src/share/database/scripts/mysql/upgrade_9.2_to_9.3.sh
src/share/database/scripts/mysql/wipe_data.sh
src/share/database/scripts/pgsql/Makefile
src/share/database/scripts/pgsql/upgrade_1.0_to_2.0.sh
......
......@@ -258,7 +258,7 @@ mysql_upgrade_test() {
assert_str_eq "1.0" ${version} "Expected kea-admin to return %s, returned value was %s"
# Ok, we have a 1.0 database. Let's upgrade it to 9.2
# Ok, we have a 1.0 database. Let's upgrade it to 9.3
${keaadmin} db-upgrade mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
ERRCODE=$?
......@@ -729,7 +729,7 @@ EOF
qry="select is_array from dhcp6_option_def"
run_statement "dhcp6_option_def verify is_array column" "$qry"
# Schema upgrade from 8.2 to 9.2
# Schema upgrade from 8.2 to 9.3
# New DDNS columns.
......@@ -749,9 +749,9 @@ EOF
qry="select ddns_send_updates, ddns_override_no_update, ddns_override_client_update, ddns_replace_client_name, ddns_generated_prefix, ddns_qualifying_suffix from dhcp6_subnet"
run_statement "dhcp6_subnet" "$qry"
# Verify upgraded schema reports version 9.2
# Verify upgraded schema reports version 9.3
version=$(${keaadmin} db-version mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir)
assert_str_eq "9.2" ${version} "Expected kea-admin to return %s, returned value was %s"
assert_str_eq "9.3" ${version} "Expected kea-admin to return %s, returned value was %s"
# Let's wipe the whole database
mysql_wipe
......
......@@ -53,7 +53,7 @@ const int MLM_MYSQL_FETCH_FAILURE = 0;
/// @name Current database schema version values.
//@{
const uint32_t MYSQL_SCHEMA_VERSION_MAJOR = 9;
const uint32_t MYSQL_SCHEMA_VERSION_MINOR = 2;
const uint32_t MYSQL_SCHEMA_VERSION_MINOR = 3;
//@}
......
......@@ -13,4 +13,5 @@
/upgrade_8.2_to_9.0.sh
/upgrade_9.0_to_9.1.sh
/upgrade_9.1_to_9.2.sh
/upgrade_9.2_to_9.3.sh
/wipe_data.sh
......@@ -18,6 +18,7 @@ sqlscripts_DATA += upgrade_8.1_to_8.2.sh
sqlscripts_DATA += upgrade_8.2_to_9.0.sh
sqlscripts_DATA += upgrade_9.0_to_9.1.sh
sqlscripts_DATA += upgrade_9.1_to_9.2.sh
sqlscripts_DATA += upgrade_9.2_to_9.3.sh
sqlscripts_DATA += wipe_data.sh
DISTCLEANFILES = upgrade_1.0_to_2.0.sh
......@@ -34,6 +35,7 @@ DISTCLEANFILES += upgrade_8.1_to_8.2.sh
DISTCLEANFILES += upgrade_8.2_to_9.0.sh
DISTCLEANFILES += upgrade_9.0_to_9.1.sh
DISTCLEANFILES += upgrade_9.1_to_9.2.sh
DISTCLEANFILES += upgrade_9.2_to_9.3.sh
DISTCLEANFILES += wipe_data.sh
EXTRA_DIST = ${sqlscripts_DATA}
......@@ -2873,6 +2873,12 @@ ALTER TABLE dhcp6_options ADD CONSTRAINT fk_dhcp6_options_pd_pool
REFERENCES dhcp6_pd_pool(id)
ON DELETE CASCADE ON UPDATE CASCADE;
# Update the schema version number
UPDATE schema_version
SET version = '9', minor = '2';
# This line concludes database upgrade to version 9.2.
# Fix stat_lease4_update trigger
DROP TRIGGER stat_lease4_update;
......@@ -2971,9 +2977,9 @@ DELIMITER ;
# Update the schema version number
UPDATE schema_version
SET version = '9', minor = '2';
SET version = '9', minor = '3';
# This line concludes database upgrade to version 9.2.
# This line concludes database upgrade to version 9.3.
# Notes:
......
#!/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=`mysql_version "$@"`
if [ "$VERSION" != "9.2" ]; then
printf "This script upgrades 9.2 to 9.3. Reported version is $VERSION. Skipping upgrade.\n"
exit 0
fi
mysql "$@" <<EOF
# Fix stat_lease4_update trigger
DROP TRIGGER stat_lease4_update;
DELIMITER $$
CREATE TRIGGER stat_lease4_update AFTER UPDATE ON lease4
FOR EACH ROW
BEGIN
IF OLD.subnet_id != NEW.subnet_id OR OLD.state != NEW.state THEN
IF OLD.state = 0 OR OLD.state = 1 THEN
# Decrement the old state count if record exists
UPDATE lease4_stat
SET leases = IF(leases > 0, leases - 1, 0)
WHERE subnet_id = OLD.subnet_id AND state = OLD.state;
END IF;
IF NEW.state = 0 OR NEW.state = 1 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 ROW_COUNT() <= 0 THEN
INSERT INTO lease4_stat VALUES (NEW.subnet_id, NEW.state, 1);
END IF;
END IF;
END IF;
END $$
DELIMITER ;
# Fix stat_lease4_delete trigger
DROP TRIGGER stat_lease4_delete;
DELIMITER $$
CREATE TRIGGER stat_lease4_delete AFTER DELETE ON lease4
FOR EACH ROW
BEGIN
IF OLD.state = 0 OR OLD.state = 1 THEN
# Decrement the state count if record exists
UPDATE lease4_stat
SET leases = IF(leases > 0, leases - 1, 0)
WHERE subnet_id = OLD.subnet_id AND OLD.state = state;
END IF;
END $$
DELIMITER ;
# Fix stat_lease6_update trigger
DROP TRIGGER stat_lease6_update;
DELIMITER $$
CREATE TRIGGER stat_lease6_update AFTER UPDATE ON lease6
FOR EACH ROW
BEGIN
IF OLD.subnet_id != NEW.subnet_id OR
OLD.lease_type != NEW.lease_type OR
OLD.state != NEW.state THEN
IF OLD.state = 0 OR OLD.state = 1 THEN
# Decrement the old state count if record exists
UPDATE lease6_stat
SET leases = IF(leases > 0, leases - 1, 0)
WHERE subnet_id = OLD.subnet_id AND lease_type = OLD.lease_type
AND state = OLD.state;
END IF;
IF NEW.state = 0 OR NEW.state = 1 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 ROW_COUNT() <= 0 THEN
INSERT INTO lease6_stat
VALUES (NEW.subnet_id, NEW.lease_type, NEW.state, 1);
END IF;
END IF;
END IF;
END $$
DELIMITER ;
# Fix stat_lease6_delete trigger
DROP TRIGGER stat_lease6_delete;
DELIMITER $$
CREATE TRIGGER stat_lease6_delete AFTER DELETE ON lease6
FOR EACH ROW
BEGIN
IF OLD.state = 0 OR OLD.state = 1 THEN
# Decrement the state count if record exists
UPDATE lease6_stat
SET leases = IF(leases > 0, leases - 1, 0)
WHERE subnet_id = OLD.subnet_id AND lease_type = OLD.lease_type
AND state = OLD.state;
END IF;
END $$
DELIMITER ;
# Update the schema version number
UPDATE schema_version
SET version = '9', minor = '3';
# This line concludes database upgrade to version 9.3.
EOF
RESULT=$?
exit $?
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment