riverqueue / river

Fast and reliable background jobs in Go
https://riverqueue.com
Mozilla Public License 2.0
3.22k stars 86 forks source link

Update `004_pending_and_more` migration to add `pending` value to river_job_state only if it does not exists #364

Closed umed closed 3 months ago

umed commented 3 months ago

Hi guys,

004_pending_and_more.down.sql migration does not remove river_job_state's pending value. It brings us to situation where we can't apply this migration after rollback.

Steps to reproduce:

  1. apply migration 004 to database
  2. rollback
  3. apply migration 004

Expected behavior:

All migrations applied without error

Actual:

failed: error applying version 004 [UP]: ERROR: enum label "pending" already exists (SQLSTATE 42710)
exit status 1

This PR is meant to fix this behavior by optionally adding pending value during migration application.

umed commented 3 months ago

I tested it just by executing queries on locally running postgres. I would gladly follow if you point out to how properly test it.