From c232faaa056c82f05bb6caddfe997805de617f0e Mon Sep 17 00:00:00 2001 From: William Chu Date: Wed, 17 Jan 2024 14:26:26 +1100 Subject: [PATCH] feat(1.7): update pg_stat_extension if it is not of the correct version --- README.md | 6 +++++ .../migrations/0002_update_extension.py | 24 +++++++++++++++++++ pyproject.toml | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 django_pev/migrations/0002_update_extension.py diff --git a/README.md b/README.md index 1b8e888..803ef10 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,12 @@ print(e.slowest.visualize(title=f"Fetching {url}")) ``` +# TODO +- [ ] Add migration to ensure pg_stats_statement_info is correct +- [ ] Do not crash when its not available +- [ ] Add explain tab += [ ] Add index suggester + # Disclaimer Credit goes to Pierre Giraud (@pgiraud) for PEV2 and Alex Tatiyants (@AlexTatiyants) for the original pev tool. diff --git a/django_pev/migrations/0002_update_extension.py b/django_pev/migrations/0002_update_extension.py new file mode 100644 index 0000000..861dc73 --- /dev/null +++ b/django_pev/migrations/0002_update_extension.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2.9 on 2024-01-17 03:19 +import logging + +from django.db import OperationalError, connection, migrations + + +def create_extension(apps, schema_editor): + try: + with connection.cursor() as cursor: + cursor.execute("select extversion from pg_extension where extname = 'pg_stat_statements'") + version = float(cursor.fetchone()[0]) + if version < 1.9: + cursor.execute("alter extension pg_stat_statements update to '1.9'") + cursor.execute("alter extension pg_stat_statements update to '1.10'") + except OperationalError: + logging.error("Could not update extension `pg_stat_statements`.") + + +class Migration(migrations.Migration): + dependencies = [ + ("django_pev", "0001_enable_extensions"), + ] + + operations = [] diff --git a/pyproject.toml b/pyproject.toml index 5f1df7b..9fbcb7c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "django-pev" -version = "0.1.6" +version = "0.1.7" description = "Context manager to upload explain plans to https://explain.dalibo.com/" authors = ["william chu "] readme = "README.md"