-- tables
DROP TABLE IF EXISTS core_account CASCADE;
DROP TABLE IF EXISTS core_adhoc_group CASCADE;
DROP TABLE IF EXISTS core_change_request CASCADE;
DROP TABLE IF EXISTS core_change_request_vote CASCADE;
DROP TABLE IF EXISTS core_closed_data_category CASCADE;
DROP TABLE IF EXISTS core_closed_linguistic_section CASCADE;
DROP TABLE IF EXISTS core_complex_data_category CASCADE;
DROP TABLE IF EXISTS core_conceptual_domain CASCADE;
DROP TABLE IF EXISTS core_conceptual_domain_rule CASCADE;
DROP TABLE IF EXISTS core_constrained_data_category CASCADE;
DROP TABLE IF EXISTS core_constrained_linguistic_section CASCADE;
DROP TABLE IF EXISTS core_container_data_category CASCADE;
DROP TABLE IF EXISTS core_data_category CASCADE;
DROP TABLE IF EXISTS core_data_category_selection CASCADE;
DROP TABLE IF EXISTS core_data_type CASCADE;
DROP TABLE IF EXISTS core_dc_status_log CASCADE;
DROP TABLE IF EXISTS core_dcr_board CASCADE;
DROP TABLE IF EXISTS core_decision_group CASCADE;
DROP TABLE IF EXISTS core_group CASCADE;
DROP TABLE IF EXISTS core_language CASCADE;
DROP TABLE IF EXISTS core_language_section CASCADE;
DROP TABLE IF EXISTS core_linguistic_section CASCADE;
DROP TABLE IF EXISTS core_message CASCADE;
DROP TABLE IF EXISTS core_open_conceptual_domain CASCADE;
DROP TABLE IF EXISTS core_open_data_category CASCADE;
DROP TABLE IF EXISTS core_owner CASCADE;
DROP TABLE IF EXISTS core_profile CASCADE;
DROP TABLE IF EXISTS core_profile_value_domain CASCADE;
DROP TABLE IF EXISTS core_recommendation CASCADE;
DROP TABLE IF EXISTS core_registration_authority CASCADE;
DROP TABLE IF EXISTS core_registration_group CASCADE;
DROP TABLE IF EXISTS core_rule CASCADE;
DROP TABLE IF EXISTS core_rule_type CASCADE;
DROP TABLE IF EXISTS core_selected_complex_data_category CASCADE;
DROP TABLE IF EXISTS core_selected_container_data_category CASCADE;
DROP TABLE IF EXISTS core_selected_data_category CASCADE;
DROP TABLE IF EXISTS core_selected_simple_data_category CASCADE;
DROP TABLE IF EXISTS core_session CASCADE;
DROP TABLE IF EXISTS core_simple_data_category CASCADE;
DROP TABLE IF EXISTS core_submission_group CASCADE;
DROP TABLE IF EXISTS core_thematic_domain_group CASCADE;
DROP TABLE IF EXISTS core_user CASCADE;
DROP TABLE IF EXISTS core_value_domain CASCADE;
DROP TABLE IF EXISTS generic_lock CASCADE;
DROP TABLE IF EXISTS generic_name CASCADE;
DROP TABLE IF EXISTS generic_text CASCADE;
DROP TABLE IF EXISTS link_dc_access CASCADE;
DROP TABLE IF EXISTS link_dcs_access CASCADE;
DROP TABLE IF EXISTS link_open_data_category_conceptual_domain CASCADE;
DROP TABLE IF EXISTS link_closed_data_category_conceptual_domains CASCADE;
DROP TABLE IF EXISTS link_constrained_data_category_conceptual_domains CASCADE;
DROP TABLE IF EXISTS link_constrained_linguistic_section_conceptual_domains CASCADE;
DROP TABLE IF EXISTS link_data_category_selection_users CASCADE;
DROP TABLE IF EXISTS link_group_members CASCADE;
DROP TABLE IF EXISTS link_profile_members CASCADE;
DROP TABLE IF EXISTS link_selected_data_category_picklist CASCADE;
DROP TABLE IF EXISTS link_selected_data_category_profiles CASCADE;
DROP TABLE IF EXISTS link_simple_data_category_super CASCADE;
DROP TABLE IF EXISTS link_value_domain_values CASCADE;
DROP TABLE IF EXISTS link_dc_access CASCADE;
DROP TABLE IF EXISTS link_dcs_access CASCADE;

-- views
DROP VIEW IF EXISTS view_dc_name;
DROP VIEW IF EXISTS view_dcs;
DROP VIEW IF EXISTS view_dcs_dc;
DROP VIEW IF EXISTS view_profile;
DROP VIEW IF EXISTS view_data_category;
DROP VIEW IF EXISTS view_text;
DROP VIEW IF EXISTS view_name;
DROP VIEW IF EXISTS view_owner;
DROP VIEW IF EXISTS view_user;
DROP VIEW IF EXISTS view_dc_type;
DROP VIEW IF EXISTS view_message;
DROP VIEW IF EXISTS view_link_dcs_access;
DROP VIEW IF EXISTS view_dcs_access;
DROP VIEW IF EXISTS view_dc_access;
DROP VIEW IF EXISTS view_cr_submission_group;
DROP VIEW IF EXISTS view_cr_decision_group_tdg;
DROP VIEW IF EXISTS view_cr_decision_group_dcrb;

-- functions

DROP FUNCTION IF EXISTS get_dc_identifier(id integer);
DROP FUNCTION IF EXISTS get_dc_name_status_language(id integer,name varchar,status varchar);
DROP FUNCTION IF EXISTS get_dc_name_status(id integer,status varchar);
DROP FUNCTION IF EXISTS get_dc_name(id integer) CASCADE;
DROP FUNCTION IF EXISTS get_dc_type(dc integer) CASCADE;
DROP FUNCTION IF EXISTS pid(dcif integer) CASCADE;
DROP FUNCTION IF EXISTS profile_path(prof integer) CASCADE;
DROP FUNCTION IF EXISTS profile_self_or_descendants(prof integer) CASCADE;
DROP FUNCTION IF EXISTS profile_ancestors(integer) CASCADE;
DROP FUNCTION IF EXISTS dc_profiles(dc integer) CASCADE;
DROP FUNCTION IF EXISTS dcs_self_or_descendants(dcs integer) CASCADE;
DROP FUNCTION IF EXISTS user_name(uid integer) CASCADE;
DROP FUNCTION IF EXISTS concat(text, text) CASCADE;
DROP FUNCTION IF EXISTS merge_accounts(keep integer, remove integer) CASCADE;
DROP FUNCTION IF EXISTS dc_super_cycle(path integer[],super integer) CASCADE;

DROP AGGREGATE IF EXISTS concat(text) CASCADE;

-- triggers and trigger functions

--DROP TRIGGER IF EXISTS core_data_category_delete_generic_text ON core_data_category;
--DROP TRIGGER IF EXISTS core_language_section_delete_generic_text ON core_language_section;
--DROP TRIGGER IF EXISTS core_linguistic_section_delete_generic_text ON core_linguistic_section;
--DROP TRIGGER IF EXISTS generic_text_delete_generic_text ON generic_text;

DROP FUNCTION IF EXISTS delete_generic_text();

--DROP TRIGGER IF EXISTS core_data_category_delete_generic_name ON core_data_category;
--DROP TRIGGER IF EXISTS core_language_section_delete_generic_name ON core_language_section;

DROP FUNCTION IF EXISTS delete_generic_name();

DROP FUNCTION IF EXISTS update_search_identifier();
DROP FUNCTION IF EXISTS update_search_name();
DROP FUNCTION IF EXISTS update_search_text();
DROP FUNCTION IF EXISTS prevent_super_cycle();