diff --git a/src/share/database/scripts/pgsql/upgrade_6.2_to_7.0.sh.in b/src/share/database/scripts/pgsql/upgrade_6.2_to_7.0.sh.in index 0b26cb4e92..b48154740b 100644 --- a/src/share/database/scripts/pgsql/upgrade_6.2_to_7.0.sh.in +++ b/src/share/database/scripts/pgsql/upgrade_6.2_to_7.0.sh.in @@ -95,6 +95,7 @@ INSERT INTO ddns_replace_client_name_types (type, name) VALUES (3, 'RCM_WHEN_NOT_PRESENT'); + -- Create table for DHCPv6 servers CREATE TABLE dhcp6_server ( id SERIAL PRIMARY KEY NOT NULL, @@ -147,8 +148,8 @@ CREATE TABLE dhcp6_shared_network ( reservations_out_of_pool BOOLEAN DEFAULT NULL, cache_threshold float DEFAULT NULL, cache_max_age BIGINT DEFAULT NULL, - - CONSTRAINT fk_ddns_replace_client_name FOREIGN KEY (ddns_replace_client_name) REFERENCES ddns_replace_client_name_types (type) + CONSTRAINT fk_ddns_replace_client_name FOREIGN KEY (ddns_replace_client_name) + REFERENCES ddns_replace_client_name_types (type) ); CREATE INDEX dhcp6_shared_network_idx1 ON dhcp6_shared_network (name); @@ -164,13 +165,16 @@ CREATE TABLE dhcp6_shared_network_server ( server_id BIGINT NOT NULL, modification_ts timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (shared_network_id, server_id), - CONSTRAINT fk_dhcp6_shared_network_server_server_id FOREIGN KEY (server_id) REFERENCES dhcp6_server (id) ON DELETE CASCADE ON UPDATE NO ACTION, - CONSTRAINT fk_dhcp6_shared_network_server_shared_network_id FOREIGN KEY (shared_network_id) REFERENCES dhcp6_shared_network (id) ON DELETE CASCADE ON UPDATE NO ACTION + CONSTRAINT fk_dhcp6_shared_network_server_server_id FOREIGN KEY (server_id) + REFERENCES dhcp6_server (id) ON DELETE CASCADE ON UPDATE NO ACTION, + CONSTRAINT fk_dhcp6_shared_network_server_shared_network_id FOREIGN KEY (shared_network_id) + REFERENCES dhcp6_shared_network (id) ON DELETE CASCADE ON UPDATE NO ACTION ); CREATE INDEX dhcp6_shared_network_server_idx1 ON dhcp6_shared_network_server (modification_ts); CREATE INDEX dhcp6_shared_network_server_idx2 ON dhcp6_shared_network_server (server_id); + -- Create a list of IPv6 subnets CREATE TABLE dhcp6_subnet ( subnet_id SERIAL PRIMARY KEY NOT NULL, @@ -311,8 +315,10 @@ CREATE TABLE dhcp6_global_parameter_server ( server_id BIGINT NOT NULL, modification_ts timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (parameter_id, server_id), - CONSTRAINT fk_dhcp6_global_parameter_server_parameter_id FOREIGN KEY (parameter_id) REFERENCES dhcp6_global_parameter(id) ON DELETE CASCADE ON UPDATE NO ACTION, - CONSTRAINT fk_dhcp6_global_parameter_server_server_id FOREIGN KEY (server_id) REFERENCES dhcp6_server(id) ON DELETE CASCADE ON UPDATE NO ACTION + CONSTRAINT fk_dhcp6_global_parameter_server_parameter_id FOREIGN KEY (parameter_id) + REFERENCES dhcp6_global_parameter(id) ON DELETE CASCADE ON UPDATE NO ACTION, + CONSTRAINT fk_dhcp6_global_parameter_server_server_id FOREIGN KEY (server_id) + REFERENCES dhcp6_server(id) ON DELETE CASCADE ON UPDATE NO ACTION ); CREATE INDEX key_dhcp6_global_parameter_server_idx1 on dhcp6_global_parameter_server(modification_ts); CREATE TRIGGER dhcp6_global_parameter_server_modification_ts_update @@ -325,9 +331,12 @@ ALTER TABLE dhcp6_options ADD COLUMN shared_network_name VARCHAR(128) DEFAULT NULL, ADD COLUMN pool_id BIGINT DEFAULT NULL, ADD COLUMN pd_pool_id BIGINT DEFAULT NULL, - ADD CONSTRAINT fk_dhcp6_options_pd_pool FOREIGN KEY (pd_pool_id) REFERENCES dhcp6_pd_pool(id) ON DELETE CASCADE ON UPDATE CASCADE, - ADD CONSTRAINT fk_dhcp6_options_pool FOREIGN KEY (pool_id) REFERENCES dhcp6_pool (id) ON DELETE CASCADE ON UPDATE CASCADE, - ADD CONSTRAINT fk_dhcp6_options_shared_network FOREIGN KEY (shared_network_name) REFERENCES dhcp6_shared_network (name) ON DELETE CASCADE ON UPDATE CASCADE; + ADD CONSTRAINT fk_dhcp6_options_pd_pool FOREIGN KEY (pd_pool_id) + REFERENCES dhcp6_pd_pool(id) ON DELETE CASCADE ON UPDATE CASCADE, + ADD CONSTRAINT fk_dhcp6_options_pool FOREIGN KEY (pool_id) + REFERENCES dhcp6_pool (id) ON DELETE CASCADE ON UPDATE CASCADE, + ADD CONSTRAINT fk_dhcp6_options_shared_network FOREIGN KEY (shared_network_name) + REFERENCES dhcp6_shared_network (name) ON DELETE CASCADE ON UPDATE CASCADE; CREATE TRIGGER dhcp6_options_modification_ts_update AFTER UPDATE ON dhcp6_options @@ -339,8 +348,10 @@ CREATE TABLE dhcp6_options_server ( server_id BIGINT NOT NULL, modification_ts timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (option_id, server_id), - CONSTRAINT fk_dhcp6_options_server_option_id FOREIGN KEY (option_id) REFERENCES dhcp6_options (option_id) ON DELETE CASCADE ON UPDATE NO ACTION, - CONSTRAINT fk_dhcp6_options_server_server_id FOREIGN KEY (server_id) REFERENCES dhcp6_server (id) ON DELETE CASCADE ON UPDATE NO ACTION + CONSTRAINT fk_dhcp6_options_server_option_id FOREIGN KEY (option_id) + REFERENCES dhcp6_options (option_id) ON DELETE CASCADE ON UPDATE NO ACTION, + CONSTRAINT fk_dhcp6_options_server_server_id FOREIGN KEY (server_id) + REFERENCES dhcp6_server (id) ON DELETE CASCADE ON UPDATE NO ACTION ); CREATE INDEX dhcp6_options_server_idx1 on dhcp6_options_server(server_id); CREATE INDEX dhcp6_options_server_idx2 on dhcp6_options_server(modification_ts); @@ -401,8 +412,10 @@ CREATE TABLE dhcp6_audit ( object_id BIGINT NOT NULL, modification_type SMALLINT NOT NULL, revision_id BIGINT NOT NULL, - CONSTRAINT fk_dhcp6_audit_modification_type FOREIGN KEY (modification_type) REFERENCES modification (id) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT fk_dhcp6_audit_revision FOREIGN KEY (revision_id) REFERENCES dhcp6_audit_revision (id) ON DELETE NO ACTION ON UPDATE CASCADE + CONSTRAINT fk_dhcp6_audit_modification_type FOREIGN KEY (modification_type) + REFERENCES modification (id) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT fk_dhcp6_audit_revision FOREIGN KEY (revision_id) + REFERENCES dhcp6_audit_revision (id) ON DELETE NO ACTION ON UPDATE CASCADE ); CREATE TRIGGER dhcp6_audit_modification_ts_update AFTER UPDATE ON dhcp6_audit @@ -448,8 +461,10 @@ CREATE TABLE dhcp4_global_parameter_server ( server_id BIGINT NOT NULL, modification_ts timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (parameter_id, server_id), - CONSTRAINT fk_dhcp4_global_parameter_server_parameter_id FOREIGN KEY (parameter_id) REFERENCES dhcp4_global_parameter(id) ON DELETE CASCADE ON UPDATE NO ACTION, - CONSTRAINT fk_dhcp4_global_parameter_server_server_id FOREIGN KEY (server_id) REFERENCES dhcp4_server(id) ON DELETE CASCADE ON UPDATE NO ACTION + CONSTRAINT fk_dhcp4_global_parameter_server_parameter_id FOREIGN KEY (parameter_id) + REFERENCES dhcp4_global_parameter(id) ON DELETE CASCADE ON UPDATE NO ACTION, + CONSTRAINT fk_dhcp4_global_parameter_server_server_id FOREIGN KEY (server_id) + REFERENCES dhcp4_server(id) ON DELETE CASCADE ON UPDATE NO ACTION ); CREATE INDEX key_dhcp4_global_parameter_idx1 ON dhcp4_global_parameter_server(modification_ts); CREATE TRIGGER dhcp4_global_parameter_server_modification_ts_update @@ -491,8 +506,8 @@ CREATE TABLE dhcp4_shared_network ( reservations_out_of_pool BOOLEAN DEFAULT NULL, cache_threshold float DEFAULT NULL, cache_max_age BIGINT DEFAULT NULL, - - CONSTRAINT fk_ddns_replace_client_name FOREIGN KEY (ddns_replace_client_name) REFERENCES ddns_replace_client_name_types (type) + CONSTRAINT fk_ddns_replace_client_name FOREIGN KEY (ddns_replace_client_name) + REFERENCES ddns_replace_client_name_types (type) ); CREATE UNIQUE INDEX dhcp4_shared_network_idx1 ON dhcp4_shared_network (name); @@ -580,8 +595,10 @@ ALTER TABLE dhcp4_options ADD COLUMN shared_network_name VARCHAR(128) DEFAULT NULL, ADD COLUMN pool_id BIGINT DEFAULT NULL, ADD COLUMN modification_ts timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, - ADD CONSTRAINT fk_dhcp4_options_pool FOREIGN KEY (pool_id) REFERENCES dhcp4_pool (id) ON DELETE CASCADE ON UPDATE CASCADE, - ADD CONSTRAINT fk_dhcp4_options_shared_network FOREIGN KEY (shared_network_name) REFERENCES dhcp4_shared_network (name) ON DELETE CASCADE ON UPDATE CASCADE; + ADD CONSTRAINT fk_dhcp4_options_pool FOREIGN KEY (pool_id) + REFERENCES dhcp4_pool (id) ON DELETE CASCADE ON UPDATE CASCADE, + ADD CONSTRAINT fk_dhcp4_options_shared_network FOREIGN KEY (shared_network_name) + REFERENCES dhcp4_shared_network (name) ON DELETE CASCADE ON UPDATE CASCADE; CREATE TRIGGER dhcp4_options_modification_ts_update AFTER UPDATE ON dhcp4_options @@ -595,8 +612,10 @@ CREATE TABLE dhcp4_options_server ( server_id BIGINT NOT NULL, modification_ts timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (option_id, server_id), - CONSTRAINT fk_dhcp4_options_server_option_id FOREIGN KEY (option_id) REFERENCES dhcp4_options (option_id) ON DELETE CASCADE ON UPDATE NO ACTION, - CONSTRAINT fk_dhcp4_options_server_server_id FOREIGN KEY (server_id) REFERENCES dhcp4_server (id) ON DELETE CASCADE ON UPDATE NO ACTION + CONSTRAINT fk_dhcp4_options_server_option_id FOREIGN KEY (option_id) + REFERENCES dhcp4_options (option_id) ON DELETE CASCADE ON UPDATE NO ACTION, + CONSTRAINT fk_dhcp4_options_server_server_id FOREIGN KEY (server_id) + REFERENCES dhcp4_server (id) ON DELETE CASCADE ON UPDATE NO ACTION ); CREATE INDEX dhcp4_options_server_idx1 on dhcp4_options_server(server_id); CREATE INDEX dhcp4_options_server_idx2 on dhcp4_options_server(modification_ts); @@ -644,8 +663,10 @@ CREATE TABLE dhcp4_options_server ( server_id BIGINT NOT NULL, modification_ts timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (option_id, server_id), - CONSTRAINT fk_dhcp6_options_server_option_id FOREIGN KEY (option_id) REFERENCES dhcp4_options (option_id) ON DELETE CASCADE ON UPDATE NO ACTION, - CONSTRAINT fk_dhcp6_options_server_server_id FOREIGN KEY (server_id) REFERENCES dhcp4_server (id) ON DELETE CASCADE ON UPDATE NO ACTION + CONSTRAINT fk_dhcp6_options_server_option_id FOREIGN KEY (option_id) + REFERENCES dhcp4_options (option_id) ON DELETE CASCADE ON UPDATE NO ACTION, + CONSTRAINT fk_dhcp6_options_server_server_id FOREIGN KEY (server_id) + REFERENCES dhcp4_server (id) ON DELETE CASCADE ON UPDATE NO ACTION ); CREATE INDEX dhcp4_options_server_idx1 on dhcp4_options_server(server_id); CREATE INDEX dhcp4_options_server_idx2 on dhcp4_options_server(modification_ts); @@ -673,8 +694,10 @@ CREATE TABLE dhcp4_audit ( object_id BIGINT NOT NULL, modification_type SMALLINT NOT NULL, revision_id BIGINT NOT NULL, - CONSTRAINT fk_dhcp4_audit_modification_type FOREIGN KEY (modification_type) REFERENCES modification (id) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT fk_dhcp4_audit_revision FOREIGN KEY (revision_id) REFERENCES dhcp4_audit_revision (id) ON DELETE NO ACTION ON UPDATE CASCADE + CONSTRAINT fk_dhcp4_audit_modification_type FOREIGN KEY (modification_type) + REFERENCES modification (id) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT fk_dhcp4_audit_revision FOREIGN KEY (revision_id) + REFERENCES dhcp4_audit_revision (id) ON DELETE NO ACTION ON UPDATE CASCADE ); CREATE TRIGGER dhcp4_audit_modification_ts_update AFTER UPDATE ON dhcp6_audit