diff --git a/app/apps/cases/migrations/0025_remove_unused_tables_azure.py b/app/apps/cases/migrations/0025_remove_unused_tables_azure.py new file mode 100644 index 000000000..b25dc9475 --- /dev/null +++ b/app/apps/cases/migrations/0025_remove_unused_tables_azure.py @@ -0,0 +1,65 @@ +# Generated by Django 3.2.13 on 2024-02-12 10:14 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("cases", "0024_alter_default_column_ids_azure"), + ] + + operations = [ + migrations.RunSQL( + sql=""" + DO $$ + BEGIN + -- Delete individual tables if they exist + IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'auth_user') THEN + DROP TABLE public.auth_user CASCADE; + END IF; + + IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'auth_user_groups') THEN + DROP TABLE public.auth_user_groups CASCADE; + END IF; + + IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'auth_user_user_permissions') THEN + DROP TABLE public.auth_user_user_permissions CASCADE; + END IF; + + -- Delete sequences if they exist + IF EXISTS (SELECT 1 FROM information_schema.sequences WHERE sequence_schema = 'public' AND sequence_name = 'auth_user_groups_id_seq') THEN + DROP SEQUENCE public.auth_user_groups_id_seq CASCADE; + END IF; + + IF EXISTS (SELECT 1 FROM information_schema.sequences WHERE sequence_schema = 'public' AND sequence_name = 'auth_user_id_seq') THEN + DROP SEQUENCE public.auth_user_id_seq CASCADE; + END IF; + + IF EXISTS (SELECT 1 FROM information_schema.sequences WHERE sequence_schema = 'public' AND sequence_name = 'auth_user_user_permissions_id_seq') THEN + DROP SEQUENCE public.auth_user_user_permissions_id_seq CASCADE; + END IF; + + IF EXISTS (SELECT 1 FROM information_schema.sequences WHERE sequence_schema = 'public' AND sequence_name = 'events_event_id_seq') THEN + DROP SEQUENCE public.events_event_id_seq CASCADE; + END IF; + + IF EXISTS (SELECT 1 FROM information_schema.sequences WHERE sequence_schema = 'public' AND sequence_name = 'cases_caseteam_id_seq') THEN + DROP SEQUENCE public.cases_caseteam_id_seq CASCADE; + END IF; + + IF EXISTS (SELECT 1 FROM information_schema.sequences WHERE sequence_schema = 'public' AND sequence_name = 'schedules_scheduletype_id_seq') THEN + DROP SEQUENCE public.schedules_scheduletype_id_seq CASCADE; + END IF; + + IF EXISTS (SELECT 1 FROM information_schema.sequences WHERE sequence_schema = 'public' AND sequence_name = 'workflow_task_id_seq') THEN + DROP SEQUENCE public.workflow_task_id_seq CASCADE; + END IF; + + IF EXISTS (SELECT 1 FROM information_schema.sequences WHERE sequence_schema = 'public' AND sequence_name = 'workflow_workflow_id_seq') THEN + DROP SEQUENCE public.workflow_workflow_id_seq CASCADE; + END IF; + END $$; + """ + ) + ]