Skip to content

Commit

Permalink
Merge pull request #1191 from Amsterdam/improvement/azure-db
Browse files Browse the repository at this point in the history
Updated query to remove tables
  • Loading branch information
NvdLaan authored Feb 12, 2024
2 parents 42c4e31 + 7eb88fd commit 09c4e4d
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions app/apps/cases/migrations/0025_remove_unused_tables_azure.py
Original file line number Diff line number Diff line change
@@ -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 $$;
"""
)
]

0 comments on commit 09c4e4d

Please sign in to comment.