From 9bab7b4b49cf2643aa55b8f3f512287817396bc6 Mon Sep 17 00:00:00 2001 From: William Chu Date: Wed, 17 Jan 2024 13:06:18 +1100 Subject: [PATCH] feat(0.1.6): add migration to enable statements --- Makefile | 1 + .../migrations/0001_enable_extensions.py | 20 +++++++++++++++++++ django_pev/templates/django_pev/queries.html | 4 ++++ example/settings.py | 1 + pyproject.toml | 2 +- 5 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 django_pev/migrations/0001_enable_extensions.py diff --git a/Makefile b/Makefile index 14bec36..b08ec1b 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ test: postgres poetry run python manage.py test publish: ci + # poetry config pypi-token.pypi your-api-token poetry publish --build ci: test lint diff --git a/django_pev/migrations/0001_enable_extensions.py b/django_pev/migrations/0001_enable_extensions.py new file mode 100644 index 0000000..0b15453 --- /dev/null +++ b/django_pev/migrations/0001_enable_extensions.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2.9 on 2024-01-17 01:46 +import logging + +from django.db import OperationalError, connection, migrations + + +def create_extension(apps, schema_editor): + try: + with connection.cursor() as cursor: + cursor.execute("CREATE EXTENSION IF NOT EXISTS pg_stat_statements") + except OperationalError: + logging.error("Could not install extension `pg_stat_statements`.") + + +class Migration(migrations.Migration): + dependencies = [] + + operations = [ + migrations.RunPython(create_extension, migrations.RunPython.noop), + ] diff --git a/django_pev/templates/django_pev/queries.html b/django_pev/templates/django_pev/queries.html index 19d3ae9..bfb93b2 100644 --- a/django_pev/templates/django_pev/queries.html +++ b/django_pev/templates/django_pev/queries.html @@ -8,6 +8,10 @@

Slow Queries

This page shows queries that consumed the most time in the database. +

+ {% if not is_pg_stat_statements %} + PG Stat Statements extension is not enabled. + {% endif %}