Commit e765d501 authored by Open Science Conservation Fund's avatar Open Science Conservation Fund
Browse files

fix for storage migration 0035

parent fc92a7b9
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -34,16 +34,20 @@ def disable_triggers_safely(apps, schema_editor):
def enable_triggers_safely(apps, schema_editor):
    """
    Re-enable triggers on storage_resource. Try ALL first, then USER.
    If both attempts fail, raise an error to stop the migration and alert operators.
    """
    if getattr(schema_editor.connection, "vendor", None) != "postgresql":
        return
    try:
        schema_editor.execute("ALTER TABLE storage_resource ENABLE TRIGGER ALL;")
    except Exception:
    except Exception as all_exc:
        try:
            schema_editor.execute("ALTER TABLE storage_resource ENABLE TRIGGER USER;")
        except Exception:
            pass
        except Exception as user_exc:
            raise RuntimeError(
                "Failed to re-enable triggers on storage_resource using both ALL and USER. "
                "Manual intervention is required to re-enable triggers."
            ) from user_exc


class Migration(migrations.Migration):