
SELECT setval('gwt_custom_property_used_id_seq', 1);
DELETE FROM gwt_soapui_messages;
DELETE FROM gwt_test_step_result_gwt_validation_result;
DELETE FROM gwt_validation_result;
SELECT setval('gwt_validation_result_id_seq', 1);
DELETE FROM gwt_test_step_result_attachment_response;
DELETE FROM gwt_test_step_result_attachment_request;
DELETE FROM gwt_test_step_result;
SELECT setval('gwt_test_step_result_id_seq', 1);
DELETE FROM gwt_mock_validation_result;
SELECT setval('gwt_mock_validation_result_id_seq', 1);

alter table gwt_execution DROP CONSTRAINT fk_8nus684yiech8v4yypm29nqys;
alter table gwt_test_instance_result DROP CONSTRAINT fk_tdnm9dlf6e38lgc7okaywpq7b;

DELETE FROM gwt_test_instance_result;
SELECT setval('gwt_test_instance_result_id_seq', 1);
DELETE FROM gwt_execution;
SELECT setval('gwt_execution_id_seq', 1);
DELETE FROM cmn_transaction_instance;
SELECT setval('cmn_transaction_instance_id_seq', 1);
DELETE FROM cmn_message_instance;
SELECT setval('cmn_message_instance_id_seq', 1);

alter table gwt_execution ADD CONSTRAINT fk_8nus684yiech8v4yypm29nqys FOREIGN KEY (execution) REFERENCES gwt_test_instance_result(id);
alter table gwt_test_instance_result ADD CONSTRAINT fk_tdnm9dlf6e38lgc7okaywpq7b FOREIGN KEY (test_execution_id) REFERENCES gwt_execution(id);


-- Delete custom properties
DELETE FROM gwt_custom_property where test_component_id in (SELECT id from gwt_test_component where test_case_id in (SELECT id from gwt_test_component where test_suite_id in (SELECT id FROM gwt_test_component where project_id in (SELECT id FROM gwt_test_component where soapui_project in (SELECT id FROM gwt_soapui_project where active = false)))));
DELETE FROM gwt_custom_property where test_component_id in (SELECT id from gwt_test_component where test_suite_id in (SELECT id FROM gwt_test_component where project_id in (SELECT id FROM gwt_test_component where soapui_project in (SELECT id FROM gwt_soapui_project where active = false))));
DELETE FROM gwt_custom_property where test_component_id in (SELECT id FROM gwt_test_component where project_id in (SELECT id FROM gwt_test_component where soapui_project in (SELECT id FROM gwt_soapui_project where active = false)));
DELETE FROM gwt_custom_property where test_component_id in (SELECT id FROM gwt_test_component where soapui_project in (SELECT id FROM gwt_soapui_project where active = false));

-- Delete test step from inactive project
DELETE FROM gwt_test_component where test_case_id in (SELECT id from gwt_test_component where test_suite_id in (SELECT id FROM gwt_test_component where project_id in (SELECT id FROM gwt_test_component where soapui_project in (SELECT id FROM gwt_soapui_project where active = false))));
-- Delete test case from inactive project
DELETE FROM gwt_test_component where test_suite_id in (SELECT id FROM gwt_test_component where project_id IN (SELECT id FROM gwt_test_component where soapui_project in (SELECT id FROM gwt_soapui_project where active = false)));
-- Delete test suite from inactive project
DELETE FROM gwt_test_component where project_id in (SELECT id FROM gwt_test_component where soapui_project in (SELECT id FROM gwt_soapui_project where active = false));
-- Delete project (from soapui) from inactive project
DELETE FROM gwt_test_component where soapui_project in (SELECT id FROM gwt_soapui_project where active = false);
-- Delete inactive project
DELETE FROM gwt_soapui_project where active = false;
