-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
When generating multiple migrations at once, subsequent migrations that contain the same time stamp are not run. #3698
Comments
Thanks for reporting this issue. Diesel migration uses a Now I personally see not much what can done here to improve the default behavior to generate migrations with the same version by fast subsequent runs without breaking all existing migrations. If someone has concrete proposals on how to slightly tweak the existing behavior I'm open for suggestions, but please address my concerns around existing migrations. |
I can only think of also adding the name identifier for determining if a migration should be run, but I assume that there's something preventing that as it seems pretty obvious and I haven't peered at the actual src for where the migration version is checked. |
This would be a breaking change as it changes what is considered to be unique. I do not see how we could do that without a major diesel release, which is not planned anytime soon. |
@weiznich , if I correctly understand the situation, you should just ensure that the generated identifiers for the migrations have different timestamps. So if you generate several identifiers at once you just need one timestamp and increase second/millisecond part (I do not think that you expect some meaning from the timestamps rather than that they are unique enough). This is also not understand why you think that this will be a breaking change. It just generates some identifiers without actual meaning of a timestamp part rather than it is sorted and unique enough and so it is useful by that means. It is not even stored anywhere except the filename, no? |
The problem there is that we need to thing about existing migrations as well. Suppose that the user has a set of migrations using the current timestamp format as version. If we now change the version format it needs to guarantee the following things:
That might be done by adding a millisecond part, but again that might not necessarily help if you create the migrations too fast. Just incrementing the timestamp would be also an idea to try, but depending on the increment interval that might raise issues about the order of subsequent bursts about of generated migrations. Again as written above: I'm open for contributions here, I just do not want to spend a lot of time fixing that myself as there is way to control that version from user scripts. |
I guess what I would do here if I was writing a script like that would be to sleep for one second in between calls to Would it be reasonable for diesel_cli to check if there's an existing migration file with the same version number as the one you are abount to create, and then report an error if that is the case? That would at least catch the error earlier and loudly instead of silently. Also, on that note, maybe it would also be good to check for migration files with the same version when running migrations too. |
Happy to accept a PR for both suggestions. I would likely even accept a PR that just makes |
Setup
Versions
Feature Flags
Problem Description
When generating multiple migrations, they may be generated with the same timestamp in the folder name.
Despite having different names following the timestamp, subsequent migrations containing the same timestamp after the first migration are ignored and will not be run.
What are you trying to accomplish?
Creating multiple migrations by chaining commands and being able to run the migrations without having to manually edit the timestamp of subsequent migrations.
What is the expected output?
Migrations are all run even if they contain the same timestamp.
What is the actual output?
Only the first migration containing a specific timestamp is run.
Are you seeing any additional errors?
No errors were reported throughout the process.
Steps to reproduce
Generate two migrations at the same time by chaining commands to generate two migrations at the same timestamp.
One could also manually edit the timestamp of the migrations to make two that are equal.
After there are two migrations, delete your database and run
Only the first migration will be run and the following migration will be ignored with no error.
Checklist
closed if this is not the case)
The text was updated successfully, but these errors were encountered: