-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update 004_pending_and_more
migration to add pending
value to river_job_state only if it does not exists
#364
Conversation
…e.up.sql migration
I tested it just by executing queries on locally running postgres. I would gladly follow if you point out to how properly test it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts @brandur ?
@@ -12,7 +12,7 @@ UPDATE river_job SET metadata = '{}' WHERE metadata IS NULL; | |||
ALTER TABLE river_job ALTER COLUMN metadata SET NOT NULL; | |||
|
|||
-- The 'pending' job state will be used for upcoming functionality: | |||
ALTER TYPE river_job_state ADD VALUE 'pending' AFTER 'discarded'; | |||
ALTER TYPE river_job_state ADD VALUE IF NOT EXISTS 'pending' AFTER 'discarded'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally we don’t want to use IF NOT EXISTS
in these migrations because they indicate a bug or something has been manually manipulated. But, in this case I’m reminded that you can’t safely remove an enum value in Postgres once it’s been added, which is why it was skipped in the down migration.
Maybe this is this best we can do in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I don't see any other viable options.
The migration in its current form isn't right because it makes the rollback unusable given it can't be used to roll forward again.
A possibility is to to an enum swap by creating a whole new enum without pending
, then swap it into place on state
, and remove the old enum. I'm sure that'd need a full table scan to check the type though.
So yep, looks like this is the path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add a changelog separately.
Hi guys,
004_pending_and_more.down.sql
migration does not removeriver_job_state
'spending
value. It brings us to situation where we can't apply this migration after rollback.Steps to reproduce:
Expected behavior:
All migrations applied without error
Actual:
This PR is meant to fix this behavior by optionally adding
pending
value during migration application.