From 498bb870f3202f641feb6355e2fd1f698ac98533 Mon Sep 17 00:00:00 2001 From: Arthur Hanson Date: Fri, 12 Jul 2024 14:18:44 +0700 Subject: [PATCH] 16625 fix as no ALTER IF NOT EXISTS --- .../migrations/0111_rename_content_types.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/netbox/extras/migrations/0111_rename_content_types.py b/netbox/extras/migrations/0111_rename_content_types.py index c723a58b1..32d8d547b 100644 --- a/netbox/extras/migrations/0111_rename_content_types.py +++ b/netbox/extras/migrations/0111_rename_content_types.py @@ -1,5 +1,16 @@ import django.db.models.deletion from django.db import migrations, models +from django.db.utils import ProgrammingError + + +def create_legacy_sequence(apps, schema_editor): + # Pre-v2.10 sequence name (see #15605) + try: + migrations.RunSQL( + "ALTER TABLE IF EXISTS extras_customfield_obj_type_id_seq RENAME TO extras_customfield_object_types_id_seq" + ) + except ProgrammingError as e: + pass class Migration(migrations.Migration): @@ -29,9 +40,9 @@ class Migration(migrations.Migration): migrations.RunSQL( "ALTER TABLE IF EXISTS extras_customfield_content_types_id_seq RENAME TO extras_customfield_object_types_id_seq" ), - # Pre-v2.10 sequence name (see #15605) - migrations.RunSQL( - "ALTER TABLE IF NOT EXISTS extras_customfield_object_types_id_seq AND EXISTS extras_customfield_obj_type_id_seq RENAME TO extras_customfield_object_types_id_seq" + migrations.RunPython( + code=create_legacy_sequence, + reverse_code=migrations.RunPython.noop ), # Custom links