Handle insufficient privileges in pg_stat_statements migration

Wrap CREATE EXTENSION in a PL/pgSQL DO block that catches
insufficient_privilege so the migration completes successfully
even when the DB user is not a superuser.
This commit is contained in:
Graham McIntire 2026-02-18 12:09:55 -06:00
parent 95c009db0d
commit bd265564a2
No known key found for this signature in database

View file

@ -1,7 +1,19 @@
defmodule Aprsme.Repo.Migrations.EnablePgStatStatements do
use Ecto.Migration
def change do
execute "CREATE EXTENSION IF NOT EXISTS pg_stat_statements"
def up do
execute """
DO $$
BEGIN
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
EXCEPTION WHEN insufficient_privilege THEN
RAISE NOTICE 'Skipping pg_stat_statements: insufficient privileges (requires superuser)';
END;
$$
"""
end
def down do
execute "DROP EXTENSION IF EXISTS pg_stat_statements"
end
end