Skip to content

feat: remove pg_cron dependency and related scheduling logic for improved flexibility#579

Merged
jirhiker merged 2 commits intostagingfrom
jir-remove-pg-cron
Mar 2, 2026
Merged

feat: remove pg_cron dependency and related scheduling logic for improved flexibility#579
jirhiker merged 2 commits intostagingfrom
jir-remove-pg-cron

Conversation

@jirhiker
Copy link
Member

@jirhiker jirhiker commented Mar 2, 2026

Why

This PR addresses the following problem / context:

  • Use bullet points here

How

Implementation summary - the following was changed / added / removed:

  • Use bullet points here

Notes

Any special considerations, workarounds, or follow-up work to note?

  • Use bullet points here

Copilot AI review requested due to automatic review settings March 2, 2026 21:02
@jirhiker jirhiker merged commit a18c1d8 into staging Mar 2, 2026
3 checks passed
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 98cb0add37

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

).scalar()
if pg_cron_available:
op.execute(text(_unschedule_refresh_job()))
op.execute(text(f"DROP FUNCTION IF EXISTS public.{REFRESH_FUNCTION_NAME}()"))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Unschedule legacy cron job before dropping refresh function

The updated downgrade() now drops public.refresh_pygeoapi_materialized_views() directly, but earlier versions of this same Alembic revision created a named pg_cron job to call that function nightly. In databases that already applied the old revision, downgrading with this new script leaves that cron entry in place, so pg_cron continues executing a function that no longer exists and generates recurring job failures. Please keep or reintroduce unscheduling logic (or a follow-up migration) for previously migrated environments.

Useful? React with 👍 / 👎.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the repository’s dependency on the PostgreSQL pg_cron extension by stripping it from the dev database image/config and removing the in-app / migration logic that conditionally created and scheduled pg_cron jobs.

Changes:

  • Removed postgresql-17-cron installation from the DB Docker image and removed shared_preload_libraries=pg_cron startup configuration in docker-compose.yml.
  • Removed conditional pg_cron extension creation during schema rebuild flows (db/initialization.py, core/initializers.py).
  • Removed pg_cron-based scheduling/unscheduling logic from the Alembic migration that creates pygeoapi supporting views.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
docker/db/Dockerfile Removes installation of the postgresql-17-cron package from the dev DB image.
docker-compose.yml Removes the custom Postgres command that preloaded pg_cron and set cron.database_name.
db/initialization.py Stops attempting to create the pg_cron extension during public schema recreation.
core/initializers.py Stops attempting to create the pg_cron extension during DB erase/rebuild.
alembic/versions/d5e6f7a8b9c0_create_pygeoapi_supporting_views.py Removes creation of the pg_cron extension and the cron job scheduling logic from the migration.
Comments suppressed due to low confidence (1)

docker-compose.yml:12

  • CI still assumes pg_cron is available. After removing the pg_cron preload/command override here, the GitHub Actions workflow still runs CREATE EXTENSION IF NOT EXISTS pg_cron (and labels the DB as "PostGIS + pg_cron"), which will fail now that the image no longer installs pg_cron. Update the workflow/docs to stop creating pg_cron (or provide an alternative DB image for CI).
  db:
    build:
      context: .
      dockerfile: ./docker/db/Dockerfile
    platform: linux/amd64
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DB}

Comment on lines 286 to 289
_create_matview_indexes()

op.execute(text(_create_refresh_function()))
if pg_cron_available:
op.execute(text(_schedule_refresh_job()))

Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This migration previously scheduled a pg_cron job. Editing an existing Alembic revision to remove that logic won’t clean up pg_cron jobs/extensions already present in databases where this revision has been applied, and it changes downgrade behavior for this revision. Prefer adding a new migration that (best-effort) unschedules the old job and drops pg_cron if present, handling privilege errors safely.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants