Skip to content

Commit

Permalink
Update delete survey procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
NickPhura committed Dec 12, 2024
1 parent 606a535 commit 39765ab
Showing 1 changed file with 102 additions and 2 deletions.
104 changes: 102 additions & 2 deletions database/src/procedures/delete_survey_procedure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export async function seed(knex: Knex): Promise<void> {
BEGIN
-------- delete basic survey data --------
WITH
occurrence_submissions AS
(
Expand Down Expand Up @@ -152,17 +154,81 @@ export async function seed(knex: Knex): Promise<void> {
DELETE FROM survey_location
WHERE survey_id = p_survey_id;
DELETE FROM survey_intended_outcome
WHERE survey_id = p_survey_id;
-------- delete device, deployment, credential, telemetry data --------
DELETE FROM telemetry_manual
WHERE deployment2_id IN (SELECT deployment2_id FROM deployment2 WHERE survey_id = p_survey_id);
DELETE FROM survey_telemetry_vendor_credential
WHERE survey_telemetry_credential_attachment_id IN (SELECT survey_telemetry_credential_attachment_id from survey_telemetry_credential_attachment WHERE survey_id = p_survey_id);
DELETE FROM survey_telemetry_credential_attachment
WHERE survey_id = p_survey_id;
DELETE FROM deployment
WHERE critter_id IN (SELECT critter_id FROM critter WHERE survey_id = p_survey_id);
DELETE FROM critter
DELETE FROM deployment2
WHERE survey_id = p_survey_id;
DELETE FROM survey_intended_outcome
DELETE FROM device
WHERE survey_id = p_survey_id;
-------- delete animal data --------
DELETE FROM subcount_critter
WHERE critter_id IN (SELECT critter_id FROM critter WHERE survey_id = p_survey_id);
DELETE FROM critter_mortality_attachment
WHERE critter_id IN (SELECT critter_id FROM critter WHERE survey_id = p_survey_id);
DELETE FROM critter_capture_attachment
WHERE critter_id IN (SELECT critter_id FROM critter WHERE survey_id = p_survey_id);
DELETE FROM critter
WHERE survey_id = p_survey_id;
-------- delete observation data --------
DELETE FROM observation_subcount_qualitative_environment
WHERE observation_subcount_id IN (
SELECT observation_subcount_id FROM observation_subcount
WHERE survey_observation_id IN (
SELECT survey_observation_id FROM survey_observation
WHERE survey_id = p_survey_id
)
);
DELETE FROM observation_subcount_quantitative_environment
WHERE observation_subcount_id IN (
SELECT observation_subcount_id FROM observation_subcount
WHERE survey_observation_id IN (
SELECT survey_observation_id FROM survey_observation
WHERE survey_id = p_survey_id
)
);
DELETE FROM observation_subcount_qualitative_measurement
WHERE observation_subcount_id IN (
SELECT observation_subcount_id FROM observation_subcount
WHERE survey_observation_id IN (
SELECT survey_observation_id FROM survey_observation
WHERE survey_id = p_survey_id
)
);
DELETE FROM observation_subcount_quantitative_measurement
WHERE observation_subcount_id IN (
SELECT observation_subcount_id FROM observation_subcount
WHERE survey_observation_id IN (
SELECT survey_observation_id FROM survey_observation
WHERE survey_id = p_survey_id
)
);
DELETE FROM observation_subcount
WHERE survey_observation_id IN (
SELECT survey_observation_id FROM survey_observation
Expand Down Expand Up @@ -195,6 +261,7 @@ export async function seed(knex: Knex): Promise<void> {
WHERE survey_id = p_survey_id;
-------- delete sampling data --------
DELETE FROM survey_sample_period
WHERE survey_sample_method_id IN (
SELECT survey_sample_method_id
Expand All @@ -220,8 +287,41 @@ export async function seed(knex: Knex): Promise<void> {
DELETE FROM survey_sample_site
WHERE survey_id = p_survey_id;
-------- delete technique data --------
DELETE FROM method_technique_attractant
WHERE method_technique_id IN (
SELECT method_technique_id
FROM method_technique
WHERE survey_id = p_survey_id
);
DELETE FROM method_technique_attribute_qualitative
WHERE method_technique_id IN (
SELECT method_technique_id
FROM method_technique
WHERE survey_id = p_survey_id
);
DELETE FROM method_technique_attribute_quantitative
WHERE method_technique_id IN (
SELECT method_technique_id
FROM method_technique
WHERE survey_id = p_survey_id
);
DELETE FROM method_technique_vantage_mode
WHERE method_technique_id IN (
SELECT method_technique_id
FROM method_technique
WHERE survey_id = p_survey_id
);
DELETE FROM method_technique
WHERE survey_id = p_survey_id;
-------- delete the survey --------
DELETE FROM survey
WHERE survey_id = p_survey_id;
Expand Down

0 comments on commit 39765ab

Please sign in to comment.