-- delete-org.sql
BEGIN;
	DELETE FROM public.oauth_token WHERE user_id IN (SELECT id FROM public.user_ WHERE organization_id = :org_id);
	DELETE FROM public.notification WHERE user_id IN (SELECT id FROM public.user_ WHERE organization_id = :org_id);
	DELETE FROM public.note_audio WHERE creator_id IN (SELECT id FROM public.user_ WHERE organization_id = :org_id);
	DELETE FROM public.note_audio WHERE deletor_id IN (SELECT id FROM public.user_ WHERE organization_id = :org_id);
	DELETE FROM public.note_image WHERE creator_id IN (SELECT id FROM public.user_ WHERE organization_id = :org_id);
	DELETE FROM public.note_image WHERE deletor_id IN (SELECT id FROM public.user_ WHERE organization_id = :org_id);
	DELETE FROM public.user_ WHERE organization_id = :org_id;
	DELETE FROM public.fieldseeker_sync WHERE organization_id = :org_id;
	DELETE FROM public.h3_aggregation WHERE organization_id = :org_id;
	DELETE FROM public.note_audio WHERE organization_id = :org_id;
	DELETE FROM public.note_image WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.containerrelate WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.fieldscoutinglog WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.habitatrelate WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.inspectionsample WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.inspectionsampledetail WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.linelocation WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.locationtracking WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.mosquitoinspection WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.pointlocation WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.polygonlocation WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.pool WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.pooldetail WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.proposedtreatmentarea WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.qamosquitoinspection WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.rodentlocation WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.samplecollection WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.samplelocation WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.servicerequest WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.speciesabundance WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.stormdrain WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.timecard WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.trapdata WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.traplocation WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.treatment WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.treatmentarea WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.zones WHERE organization_id = :org_id;
	DELETE FROM fieldseeker.zones2 WHERE organization_id = :org_id;
	DELETE FROM organization WHERE id = :org_id;
COMMIT;
