mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 05:55:28 +00:00
[#2244] Added missing columns to PostgreSQL schema
configure.ac added src/share/database/scripts/pgsql/upgrade_7.0_to_8.0.sh src/bin/admin/tests/pgsql_tests.sh.in Updated to test upgrading to 8.0 pgsql_upgrade_7_0_to_8_0() - new function src/lib/pgsql/pgsql_connection.h Updated schema version src/share/database/scripts/pgsql/Makefile.am added upgrade_7.0_to_8.0.sh.in src/share/database/scripts/pgsql/dhcpdb_create.pgsql Adds class_id column and constraints to dhcp4/6_option_def tables Adds preferred lifetime columns to dhcp6_client_class src/share/database/scripts/pgsql/upgrade_7.0_to_8.0.sh.in - new file Adds class_id column and constraints to dhcp4/6_option_def tables Adds preferred lifetime columns to dhcp6_client_class
This commit is contained in:
@@ -1838,6 +1838,8 @@ AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_6.1_to_6.2.sh],
|
||||
[chmod +x src/share/database/scripts/pgsql/upgrade_6.1_to_6.2.sh])
|
||||
AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_6.2_to_7.0.sh],
|
||||
[chmod +x src/share/database/scripts/pgsql/upgrade_6.2_to_7.0.sh])
|
||||
AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_7.0_to_8.0.sh],
|
||||
[chmod +x src/share/database/scripts/pgsql/upgrade_7.0_to_8.0.sh])
|
||||
AC_CONFIG_FILES([src/share/database/scripts/pgsql/wipe_data.sh],
|
||||
[chmod +x src/share/database/scripts/pgsql/wipe_data.sh])
|
||||
AC_CONFIG_FILES([src/share/yang/Makefile])
|
||||
|
@@ -143,7 +143,7 @@ pgsql_db_version_test() {
|
||||
run_command \
|
||||
"${kea_admin}" db-version pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}"
|
||||
version="${OUTPUT}"
|
||||
assert_str_eq "7.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
|
||||
assert_str_eq "8.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
|
||||
|
||||
# Let's wipe the whole database
|
||||
pgsql_wipe
|
||||
@@ -289,10 +289,6 @@ insert into hosts(dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, ipv4_a
|
||||
}
|
||||
|
||||
pgsql_upgrade_6_2_to_7_0() {
|
||||
# Verify upgraded schema reports version 7.0.
|
||||
version=$("${kea_admin}" db-version pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}")
|
||||
assert_str_eq "7.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
|
||||
|
||||
# dhcp4_server should have a single entry for 'all'
|
||||
select_sql="SELECT id, tag, description, modification_ts from dhcp4_server where id = 1 and tag = 'all';"
|
||||
run_command \
|
||||
@@ -300,10 +296,6 @@ pgsql_upgrade_6_2_to_7_0() {
|
||||
|
||||
assert_eq 0 "${EXIT_CODE}" "the dhcp4_server table is broken or missing. (expected status code %d, returned %d)"
|
||||
|
||||
# Verify upgraded schema reports version 7.0.
|
||||
version=$("${kea_admin}" db-version pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}")
|
||||
assert_str_eq "7.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
|
||||
|
||||
# dhcp6_server should have a single entry for 'all'
|
||||
select_sql="SELECT id, tag, description, modification_ts from dhcp6_server where id = 1 and tag = 'all';"
|
||||
run_command \
|
||||
@@ -331,6 +323,26 @@ select get_session_big_int('kea.bigint'); \
|
||||
assert_str_eq " booya f t 0 1984 " "${clean_out}" "session variable output incorrect"
|
||||
}
|
||||
|
||||
pgsql_upgrade_7_0_to_8_0() {
|
||||
run_command \
|
||||
pgsql_execute "$session_sql"
|
||||
|
||||
# Added class_id to dhcp4_option_def
|
||||
run_command \
|
||||
pgsql_execute "select class_id from dhcp4_option_def;"
|
||||
assert_eq 0 "${EXIT_CODE}" "dhcp4_option_def is missing class_id column. (expected status code %d, returned %d)"
|
||||
|
||||
# Added class_id to dhcp6_option_def
|
||||
run_command \
|
||||
pgsql_execute "select class_id from dhcp6_option_def;"
|
||||
assert_eq 0 "${EXIT_CODE}" "dhcp6_option_def is missing class_id column. (expected status code %d, returned %d)"
|
||||
|
||||
# Added preferred lifetime columns to dhcp6_client_class.
|
||||
run_command \
|
||||
pgsql_execute "select preferred_lifetime, min_preferred_lifetime, max_preferred_lifetime from dhcp6_client_class;"
|
||||
assert_eq 0 "${EXIT_CODE}" "dhcp6_client_class is missing preferred lifetime column(s). (expected status code %d, returned %d)"
|
||||
}
|
||||
|
||||
pgsql_upgrade_test() {
|
||||
test_start "pgsql.upgrade-test"
|
||||
|
||||
@@ -361,6 +373,13 @@ pgsql_upgrade_test() {
|
||||
# Check 6.2 to 7.0 upgrade
|
||||
pgsql_upgrade_6_2_to_7_0
|
||||
|
||||
# Check 7.0 to 8.0 upgrade
|
||||
pgsql_upgrade_7_0_to_8_0
|
||||
|
||||
# Verify upgraded schema reports version 8.0.
|
||||
version=$("${kea_admin}" db-version pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}")
|
||||
assert_str_eq "8.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
|
||||
|
||||
# Let's wipe the whole database
|
||||
pgsql_wipe
|
||||
|
||||
|
@@ -17,8 +17,8 @@
|
||||
namespace isc {
|
||||
namespace db {
|
||||
|
||||
/// @brief Define PostgreSQL backend version: 7.0
|
||||
const uint32_t PG_SCHEMA_VERSION_MAJOR = 7;
|
||||
/// @brief Define PostgreSQL backend version: 8.0
|
||||
const uint32_t PG_SCHEMA_VERSION_MAJOR = 8;
|
||||
const uint32_t PG_SCHEMA_VERSION_MINOR = 0;
|
||||
|
||||
// Maximum number of parameters that can be used a statement
|
||||
|
@@ -21,6 +21,7 @@ pgsql_SCRIPTS += upgrade_5.1_to_6.0.sh
|
||||
pgsql_SCRIPTS += upgrade_6.0_to_6.1.sh
|
||||
pgsql_SCRIPTS += upgrade_6.1_to_6.2.sh
|
||||
pgsql_SCRIPTS += upgrade_6.2_to_7.0.sh
|
||||
pgsql_SCRIPTS += upgrade_7.0_to_8.0.sh
|
||||
pgsql_SCRIPTS += wipe_data.sh
|
||||
|
||||
DISTCLEANFILES = ${pgsql_SCRIPTS}
|
||||
|
@@ -3795,6 +3795,48 @@ UPDATE schema_version
|
||||
|
||||
-- Schema 7.0 specification ends here.
|
||||
|
||||
-- -----------------------------------------------------------------------
|
||||
-- Extend the table holding DHCPv4 option definitions with a nullable
|
||||
-- column matching option defintions with client classes.
|
||||
-- -----------------------------------------------------------------------
|
||||
ALTER TABLE dhcp4_option_def
|
||||
ADD COLUMN class_id BIGINT NULL DEFAULT NULL;
|
||||
|
||||
ALTER TABLE dhcp4_option_def
|
||||
ADD CONSTRAINT fk_dhcp4_option_def_client_class_id
|
||||
FOREIGN KEY (class_id)
|
||||
REFERENCES dhcp4_client_class (id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE;
|
||||
|
||||
-- -----------------------------------------------------------------------
|
||||
-- Extend the table holding DHCPv6 option definitions with a nullable
|
||||
-- column matching option defintions with client classes.
|
||||
-- -----------------------------------------------------------------------
|
||||
ALTER TABLE dhcp6_option_def
|
||||
ADD COLUMN class_id BIGINT NULL DEFAULT NULL;
|
||||
|
||||
ALTER TABLE dhcp6_option_def
|
||||
ADD CONSTRAINT fk_dhcp6_option_def_client_class_id
|
||||
FOREIGN KEY (class_id)
|
||||
REFERENCES dhcp6_client_class (id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE;
|
||||
|
||||
-- -----------------------------------------------------------------------
|
||||
-- Add missing preferred_lifetime columns to dhcp6_client_class table.
|
||||
-- -----------------------------------------------------------------------
|
||||
ALTER TABLE dhcp6_client_class
|
||||
ADD COLUMN preferred_lifetime BIGINT DEFAULT NULL,
|
||||
ADD COLUMN min_preferred_lifetime BIGINT DEFAULT NULL,
|
||||
ADD COLUMN max_preferred_lifetime BIGINT DEFAULT NULL;
|
||||
|
||||
-- Update the schema version number
|
||||
UPDATE schema_version
|
||||
SET version = '8', minor = '0';
|
||||
|
||||
-- Schema 8.0 specification ends here.
|
||||
|
||||
-- Commit the script transaction
|
||||
COMMIT;
|
||||
|
||||
|
Reference in New Issue
Block a user