PgFlow.Queries.Pgmq (PgFlow v0.1.0)

Copy Markdown View Source

SQL query interface for pgmq-specific operations.

Provides functions for managing pgmq NOTIFY triggers and querying pgmq extension metadata.

Summary

Functions

Disables NOTIFY triggers for a pgmq queue.

Enables NOTIFY triggers for a pgmq queue.

Gets the installed pgmq version.

Functions

disable_notify_insert(repo, queue_name)

@spec disable_notify_insert(module(), String.t()) :: :ok | {:error, term()}

Disables NOTIFY triggers for a pgmq queue.

Calls pgmq.disable_notify_insert/1 to remove the INSERT trigger that fires NOTIFY events when messages are added to the queue.

enable_notify_insert(repo, queue_name, throttle_ms)

@spec enable_notify_insert(module(), String.t(), non_neg_integer()) ::
  :ok | {:error, term()}

Enables NOTIFY triggers for a pgmq queue.

Calls pgmq.enable_notify_insert/2 to add an INSERT trigger that fires NOTIFY events when messages are added to the queue. The throttle_ms parameter controls how frequently notifications fire.

get_pgmq_version(repo)

@spec get_pgmq_version(module()) ::
  {:ok, String.t()} | {:error, :not_installed | term()}

Gets the installed pgmq version.

Checks two sources in order:

  1. pg_extension catalog — works when pgmq is installed via CREATE EXTENSION pgmq
  2. Feature detection — checks for the enable_notify_insert function in the pgmq schema, which indicates pgmq >= 1.8.0 installed from a SQL dump (e.g., on Neon or other managed Postgres)

Returns {:ok, version} if pgmq is detected, or {:error, :not_installed} if not.