feat: remove pg_cron dependency and related scheduling logic for improved flexibility#579
feat: remove pg_cron dependency and related scheduling logic for improved flexibility#579
Conversation
There was a problem hiding this comment.
💡 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}()")) |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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-croninstallation from the DB Docker image and removedshared_preload_libraries=pg_cronstartup configuration indocker-compose.yml. - Removed conditional
pg_cronextension 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}
| _create_matview_indexes() | ||
|
|
||
| op.execute(text(_create_refresh_function())) | ||
| if pg_cron_available: | ||
| op.execute(text(_schedule_refresh_job())) | ||
|
|
There was a problem hiding this comment.
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.
Why
This PR addresses the following problem / context:
How
Implementation summary - the following was changed / added / removed:
Notes
Any special considerations, workarounds, or follow-up work to note?