Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated pk_sequence DB #1192

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name_of_your_migration> <name_of_apps>

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._
Expand Down
30 changes: 30 additions & 0 deletions app/apps/cases/migrations/0026_update_sequence_pk.py
Original file line number Diff line number Diff line change
@@ -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 $$;
"""
)
]
39 changes: 39 additions & 0 deletions app/apps/debriefings/migrations/0005_alter_debriefing_violation.py
Original file line number Diff line number Diff line change
@@ -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,
),
),
]
30 changes: 30 additions & 0 deletions app/apps/events/migrations/0003_update_sequence_pk.py
Original file line number Diff line number Diff line change
@@ -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 $$;
"""
)
]
30 changes: 30 additions & 0 deletions app/apps/schedules/migrations/0006_update_sequence_pk.py
Original file line number Diff line number Diff line change
@@ -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 $$;
"""
)
]
45 changes: 45 additions & 0 deletions app/apps/workflow/migrations/0010_update_sequence_pk.py
Original file line number Diff line number Diff line change
@@ -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 $$;
"""
)
]
Loading