drop schema if exists darwin1 cascade;
truncate table specimens_flat cascade;
truncate table specimen_parts cascade;
truncate table specimen_individuals cascade;
truncate table specimens cascade;
truncate table collections cascade;
truncate table users_tracking cascade;
truncate table my_widgets cascade;
alter table codes disable trigger fct_cpy_trg_del_dict_codes;
alter table codes disable trigger trg_trk_log_table_codes;
alter table identifications disable trigger fct_cpy_trg_del_dict_identifications;
alter table identifications disable trigger trg_trk_log_table_identifications;
alter table identifications disable trigger trg_clr_identifiers_in_flat;
alter table identifications disable trigger trg_clr_referencerecord_identifications;
alter table collection_maintenance disable trigger fct_cpy_trg_del_dict_collection_maintenance;
alter table collection_maintenance disable trigger trg_trk_log_table_collection_maintenance;
alter table collection_maintenance disable trigger trg_clr_referencerecord_mysavedsearches;
alter table catalogue_properties disable trigger trg_trk_log_table_catalogue_properties;
alter table catalogue_properties disable trigger trg_clr_referencerecord_catalogueproperties;
alter table catalogue_people disable trigger trg_upd_people_in_flat;
alter table catalogue_people disable trigger trg_clr_referencerecord_cataloguepeople;
alter table ext_links disable trigger trg_trk_log_table_ext_links;
alter table insurances disable trigger fct_cpy_trg_del_dict_insurances;
alter table insurances disable trigger trg_trk_log_table_insurances;
alter table insurances disable trigger trg_clr_referencerecord_insurances;
delete from codes where referenced_relation in ('specimen_parts', 'specimen_individuals', 'specimens');
delete from identifications where referenced_relation in ('specimen_parts', 'specimen_individuals', 'specimens');
delete from catalogue_people where referenced_relation in ('specimen_parts', 'specimen_individuals', 'specimens');
delete from catalogue_properties where referenced_relation in ('specimen_parts', 'specimen_individuals', 'specimens');
delete from ext_links where referenced_relation in ('specimen_parts', 'specimen_individuals', 'specimens');
delete from insurances where referenced_relation in ('specimen_parts', 'specimen_individuals', 'specimens');
delete from my_saved_searches where is_only_id = true;
delete from collection_maintenance where referenced_relation in ('specimen_parts', 'specimen_individuals', 'specimens');
delete from users where id > 0;
alter table codes enable trigger fct_cpy_trg_del_dict_codes;
alter table codes enable trigger trg_trk_log_table_codes;
alter table identifications enable trigger fct_cpy_trg_del_dict_identifications;
alter table identifications enable trigger trg_trk_log_table_identifications;
alter table identifications enable trigger trg_clr_identifiers_in_flat;
alter table identifications enable trigger trg_clr_referencerecord_identifications;
alter table collection_maintenance enable trigger fct_cpy_trg_del_dict_collection_maintenance;
alter table collection_maintenance enable trigger trg_trk_log_table_collection_maintenance;
alter table collection_maintenance enable trigger trg_clr_referencerecord_mysavedsearches;
alter table catalogue_properties enable trigger trg_trk_log_table_catalogue_properties;
alter table catalogue_properties enable trigger trg_clr_referencerecord_catalogueproperties;
alter table catalogue_people enable trigger trg_upd_people_in_flat;
alter table catalogue_people enable trigger trg_clr_referencerecord_cataloguepeople;
alter table ext_links enable trigger trg_trk_log_table_ext_links;
alter table insurances enable trigger fct_cpy_trg_del_dict_insurances;
alter table insurances enable trigger trg_trk_log_table_insurances;
alter table insurances enable trigger trg_clr_referencerecord_insurances;
insert into users (id, is_physical, family_name, given_name, db_user_type) values (1, true, 'demo', 'manager', 4);
insert into users (id, is_physical, family_name, given_name, db_user_type) values (2, true, 'demo', 'encoder', 2);
insert into users (id, is_physical, family_name, given_name, db_user_type) values (3, true, 'demo', 'register', 1);
insert into collections (id, code, name, institution_ref, main_manager_ref) values (1, 'demo', 'demo', 47859, 1);
insert into collections_rights (collection_ref, user_ref, db_user_type) values (1, 2, 2);
insert into collections_rights (collection_ref, user_ref, db_user_type) values (1, 3, 1);
reindex table specimens_flat;
reindex table specimen_parts;
reindex table specimen_individuals;
reindex table specimen_parts;
reindex table codes;
reindex table identifications;
reindex table collection_maintenance;
reindex table catalogue_properties;
reindex table ext_links;
reindex table insurances;
reindex table collections;
reindex table users;