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
move migration table updating SQL into a migration transaction #6727
Conversation
Signed-off-by: Rui Yang <ruiya@vmware.com>
It seems like it could be pretty easy to make mistakes if we need to put the What if we just enforced all migrations to run in a transaction? In This is more restrictive in that we can no longer choose to run a migration outside of a transaction, but I'm not too sure what use-cases there are for doing so anyway - looks like all our migrations (besides empty ones) use a transaction. Does that make sense? |
it now creates the transaction first and pass it to go/sql migration instead of creating a transaction in their own Co-authored-by: Bohan Chen <bochen@pivotal.io> Signed-off-by: Rui Yang <ruiya@vmware.com>
Co-authored-by: Bohan Chen <bochen@pivotal.io> Signed-off-by: Rui Yang <ruiya@vmware.com>
delete "BEGIN;" "COMMIT;" and remove indent Co-authored-by: Bohan Chen <bochen@pivotal.io> Signed-off-by: Rui Yang <ruiya@vmware.com>
Co-authored-by: Bohan Chen <bochen@pivotal.io> Signed-off-by: Rui Yang <ruiya@vmware.com>
Co-authored-by: Bohan Chen <bochen@pivotal.io> Signed-off-by: Rui Yang <ruiya@vmware.com>
@aoldershaw we have updated the PR so that migrator use a |
This came up in retro and I brought up needing to be able to do this, but I don't think we need to anymore. The migration that needed it before has since been squashed into the new initial schema. There was a time when we had to do an
But as of Postgres 12, it can!
I actually looked into this recently and I'm fairly certain this was the only type of query that could not be run in a transaction. Given that we don't do this often (last time we did it was to add another volume/container state iirc), if/when it does come up again I'd rather take that as an opportunity to raise the minimum version to 12 so we can leverage more shiny new features. So I'm good with just forcing transactions everywhere. 👍 |
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.
LGTM
#6727 wraps all migrations in a transaction, and we can't start a transaction within another Signed-off-by: Aidan Oldershaw <aoldershaw@pivotal.io> Co-authored-by: Esteban Foronda <eforonda@vmware.com>
What does this PR accomplish?
Bug Fix | Feature | Documentation
Fix #6695
Changes proposed by this PR:
we should not rely on Go to execute the SQL to update
migrations_history
table as the process could be killed before it could run the query, which will make Concourse lost track of migration state (it relies on the entry in migrations_history table).Instead, we could put the SQL into each migration itself. In this way if the migration is done, the migrations_history table is guaranteed to be updated.
Notes to reviewer:
we have tried to intercept the os kill signal so Go could run a clean up but it seems Go could only catch syscall.SIGTERM (gracefully shutdown with draining). It can't catch syscall.SIGKILL, unfortunatelly.
Release Note
Fix a bug where a completed migration was not recorded in
migrations_history
tableContributor Checklist
Reviewer Checklist