From 6600580c3e433f5b8b4efeed99b58bb89f8ad190 Mon Sep 17 00:00:00 2001 From: remyvdwereld <86827854+remyvdwereld@users.noreply.github.com> Date: Thu, 15 Feb 2024 11:26:30 +0100 Subject: [PATCH] Updated pk_sequence DB --- README.md | 5 ++- .../migrations/0026_update_sequence_pk.py | 30 +++++++++++++ .../0005_alter_debriefing_violation.py | 39 ++++++++++++++++ .../migrations/0003_update_sequence_pk.py | 30 +++++++++++++ .../migrations/0006_update_sequence_pk.py | 30 +++++++++++++ .../migrations/0010_update_sequence_pk.py | 45 +++++++++++++++++++ 6 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 app/apps/cases/migrations/0026_update_sequence_pk.py create mode 100644 app/apps/debriefings/migrations/0005_alter_debriefing_violation.py create mode 100644 app/apps/events/migrations/0003_update_sequence_pk.py create mode 100644 app/apps/schedules/migrations/0006_update_sequence_pk.py create mode 100644 app/apps/workflow/migrations/0010_update_sequence_pk.py diff --git a/README.md b/README.md index eea33fded..b675d66ff 100644 --- a/README.md +++ b/README.md @@ -171,11 +171,14 @@ Note that the apps and models should be updated whenever applications and models For changes to the model you have to migrate the DB. ```python -python manage.py makemigrations --name name_of_your_migration +python manage.py makemigrations --name python manage.py migrate ``` +name_of_apps is the model you would like to change like: cases, events, workflow or schedules. +You can use the `---empty` flag to create a custom migration. + # FAQ _Error: Account locked: too many login attempts. Contact an admin to unlock your account._ diff --git a/app/apps/cases/migrations/0026_update_sequence_pk.py b/app/apps/cases/migrations/0026_update_sequence_pk.py new file mode 100644 index 000000000..cc8b0b239 --- /dev/null +++ b/app/apps/cases/migrations/0026_update_sequence_pk.py @@ -0,0 +1,30 @@ +# Generated by Django 3.2.13 on 2024-02-15 09:30 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("cases", "0025_remove_unused_tables_azure"), + ] + + operations = [ + migrations.RunSQL( + sql=""" + DO $$ + DECLARE + max_id BIGINT; + BEGIN + -- Find the maximum id value in the table + SELECT MAX(id) INTO max_id FROM public.cases_casetheme; + + -- If there are no records, set max_id to 0 + IF max_id IS NULL THEN + max_id := 0; + END IF; + EXECUTE FORMAT('ALTER SEQUENCE public.cases_casetheme_id_seq RESTART WITH %s;', max_id + 1); + END $$; + """ + ) + ] diff --git a/app/apps/debriefings/migrations/0005_alter_debriefing_violation.py b/app/apps/debriefings/migrations/0005_alter_debriefing_violation.py new file mode 100644 index 000000000..62f4a634d --- /dev/null +++ b/app/apps/debriefings/migrations/0005_alter_debriefing_violation.py @@ -0,0 +1,39 @@ +# Generated by Django 3.2.13 on 2024-02-15 10:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("debriefings", "0004_added_tag_to_case_model"), + ] + + operations = [ + migrations.AlterField( + model_name="debriefing", + name="violation", + field=models.CharField( + choices=[ + ("NO", "Geen overtreding"), + ("YES", "Overtreding"), + ("ADDITIONAL_RESEARCH_REQUIRED", "Nader intern onderzoek nodig"), + ("ADDITIONAL_VISIT_REQUIRED", "Aanvullend bezoek nodig"), + ("ADDITIONAL_VISIT_WITH_AUTHORIZATION", "Machtiging benodigd"), + ("SEND_TO_OTHER_THEME", "Naar ander thema"), + ("LIKELY_INHABITED", "Vermoeden bewoning/leegstand"), + ("SERVICE_COSTS", "Narekenen onredelijke servicekosten"), + ("SCHEDULE_CONVERSATION", "Inplannen gesprek"), + ("ADVICE_OTHER_DISCIPLINE", "Afwachten advies andere discipline"), + ("REQUEST_DOCUMENTS", "Opvragen stukken"), + ("SEND_TO_WOON", "Doorsturen naar !Woon"), + ( + "SEND_TO_ANOTHER_EXTERNAL_PARTY", + "Doorsturen naar andere externe partij", + ), + ], + default="NO", + max_length=255, + ), + ), + ] diff --git a/app/apps/events/migrations/0003_update_sequence_pk.py b/app/apps/events/migrations/0003_update_sequence_pk.py new file mode 100644 index 000000000..a3cf25dfd --- /dev/null +++ b/app/apps/events/migrations/0003_update_sequence_pk.py @@ -0,0 +1,30 @@ +# Generated by Django 3.2.13 on 2024-02-15 09:30 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("events", "0002_alter_default_column_ids_azure"), + ] + + operations = [ + migrations.RunSQL( + sql=""" + DO $$ + DECLARE + max_id BIGINT; + BEGIN + -- Find the maximum id value in the table + SELECT MAX(id) INTO max_id FROM public.events_caseevent; + + -- If there are no records, set max_id to 0 + IF max_id IS NULL THEN + max_id := 0; + END IF; + EXECUTE FORMAT('ALTER SEQUENCE public.events_caseevent_id_seq RESTART WITH %s;', max_id + 1); + END $$; + """ + ) + ] diff --git a/app/apps/schedules/migrations/0006_update_sequence_pk.py b/app/apps/schedules/migrations/0006_update_sequence_pk.py new file mode 100644 index 000000000..7174ba1df --- /dev/null +++ b/app/apps/schedules/migrations/0006_update_sequence_pk.py @@ -0,0 +1,30 @@ +# Generated by Django 3.2.13 on 2024-02-15 09:30 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("schedules", "0005_alter_default_column_ids_azure"), + ] + + operations = [ + migrations.RunSQL( + sql=""" + DO $$ + DECLARE + max_id BIGINT; + BEGIN + -- Find the maximum id value in the table + SELECT MAX(id) INTO max_id FROM public.schedules_action; + + -- If there are no records, set max_id to 0 + IF max_id IS NULL THEN + max_id := 0; + END IF; + EXECUTE FORMAT('ALTER SEQUENCE public.schedules_action_id_seq RESTART WITH %s;', max_id + 1); + END $$; + """ + ) + ] diff --git a/app/apps/workflow/migrations/0010_update_sequence_pk.py b/app/apps/workflow/migrations/0010_update_sequence_pk.py new file mode 100644 index 000000000..b949d4e11 --- /dev/null +++ b/app/apps/workflow/migrations/0010_update_sequence_pk.py @@ -0,0 +1,45 @@ +# Generated by Django 3.2.13 on 2024-02-15 09:30 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("workflow", "0009_alter_default_column_ids_azure"), + ] + + operations = [ + migrations.RunSQL( + sql=""" + DO $$ + DECLARE + max_id BIGINT; + BEGIN + -- workflow_caseusertask + -- Find the maximum id value in the table + SELECT MAX(id) INTO max_id FROM public.workflow_caseusertask; + + -- If there are no records, set max_id to 0 + IF max_id IS NULL THEN + max_id := 0; + END IF; + EXECUTE FORMAT('ALTER SEQUENCE public.workflow_caseusertask_id_seq RESTART WITH %s;', max_id + 1); + END $$; + DO $$ + DECLARE + max_id BIGINT; + BEGIN + -- workflow_caseworkflow + -- Find the maximum id value in the table + SELECT MAX(id) INTO max_id FROM public.workflow_caseworkflow; + + -- If there are no records, set max_id to 0 + IF max_id IS NULL THEN + max_id := 0; + END IF; + EXECUTE FORMAT('ALTER SEQUENCE public.workflow_caseworkflow_id_seq RESTART WITH %s;', max_id + 1); + END $$; + """ + ) + ]