Skip to content
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

Mark migrations as idempotent #237

Open
fdw opened this issue Sep 13, 2021 · 5 comments
Open

Mark migrations as idempotent #237

fdw opened this issue Sep 13, 2021 · 5 comments
Labels

Comments

@fdw
Copy link

fdw commented Sep 13, 2021

Hi, we are using Evolve for our product, so first some thanks is in order!

Unfortunately, we are in a situation where we have to support multiple versions of our product. Thus, we might be expected to hotfix an older version (f.e. v1.7), and of course we want to include the same hotfix also for the next release (f.e. v2.2). Just having the script in there is not enough, as it will not be executed for anyone that is already on v2.0.
However, duplicating it as v2.3 will lead to conflicts when the hotfix has been applied beforehand if the scripts haven't been written in way to make them idempotent.

We did think about using OutOfOrder, but as we already don't really know the version of the database, this will introduce many more possible migration paths and increase the overall complexity there. So we'd rather not use it.

Instead, as one possible solution, we could imagine to somehow mark "identical" scripts as such, even if they have different versions, so that Evolve will only execute them if the appropriate sibling script hasn't been executed before.

I know this is a very specific use-case, but I still wanted to ask if you have any ideas for our problem or if such an explicit marking would be helpful for others, too.

Thank you!

@lecaillon
Copy link
Owner

Hi @fdw
Indeed this is a very specific issue. I don't think a new special instruction can help anyone but you :)
Do you use Evolve as a NuGet package ? (or the Tool or the CLI) ?

@fdw
Copy link
Author

fdw commented Oct 1, 2021

Thanks for answering, @lecaillon!

We're using Evolve as a NuGet package in a slightly larger application.

@lecaillon
Copy link
Owner

I was thinking about the new feature i'm adding : use its own custom IMigrationLoader. It could do the trick in your case maybe.

But in fact, you could just add a V2_3 migration script that checks if the V1_7 hotfix has already been applied. Query the Evolve metadatatable in order to do that. Something like:

IF NOT EXISTS (SELECT * FROM changelog WHERE version = '1.7') THEN
    -- apply the hotfix
END IF;

Something to test I guess

@fdw
Copy link
Author

fdw commented Oct 1, 2021

That would be quite a nice solution, thank you very much :)

@lecaillon lecaillon changed the title [Feature] Mark migrations as idempotent Mark migrations as idempotent Oct 1, 2021
@lecaillon
Copy link
Owner

Keep me in touch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants