-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
create_if_not_exists cannot run concurrently #2703
Comments
It is not a compile time error, but a regular error when running migrations. The Ecto.Migration docs cover this too: https://hexdocs.pm/ecto/Ecto.Migration.html#module-transactions |
@josevalim sorry, I mistyped the report. it is indeed a runtime error. brainfart on a late night bug report. Maybe I didn't do a good enough job of pointing out I did specify |
That was my fault. :) I should have noticed it. I will investigate. Btw, can you reproduce it in our suite? |
#2706 =) |
@novaugust thanks for the reproduction mechanism. I have taken a look at this and the reason is that, in order to support earlier PG versions, we are emulating create if not exists with transactions and error handling. However, once I changed the code to emit a proper "CREATE INDEX IF NOT EXISTS CONCURRENTLY", then the test would never finish. It seems it has to wait until any on going transaction finishes, which conflicts with our new lock that avoids multiple migrations from running at the same time. The only way I can see for this to work is to have a mechanism to disable the migration lock... but then you are putting yourself at risk of running the migration multiple times at once, while at the same time requiring us to drop support for the operation in more recent PG versions. For all of those reasons, I am more inclined to raise an error for now. You can bypass the error by doing a |
Or maybe you can simulate this by doing a query checking for the index before emitting the command. |
Closing this as we at at least raise a better error message now thanks to 5f73f43. |
not a big deal, I didn't need the migration to work that way, so I just sidestepped it and thought i'd report it =) |
Environment
Current behavior
Using
create_if_not_exists
to create an index concurrently erroneously raises a compiletime error.Example migration:
mix ecto.migrate
raises:Expected behavior
No error should be raised and the migration should happen, identically to using
create
The text was updated successfully, but these errors were encountered: