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

Feature/idempotent migrations #664

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

kamil-mrzyglod
Copy link

There is one thing which FluentMigrator lacks in my opinion - idempotent migrations(or rather idempotent generated SQL output). This is the only thing which prevents me from using it on production environment in my work(we have to prepare SQL scripts for DBA team because we haven't been given permission to perform automatic migrations yet).

Because it would be easier to use original package than the one from our private NuGet gallery, I would like to ask whether it would be possible to introduce those change into FM :)

@kamil-mrzyglod
Copy link
Author

Ok, I see that not using Quoter breaks some tests, will come back with a fix in a day :)

@DustinVenegas
Copy link

Two things stand out to me in this change. First, database changes that are migrated shouldn't require idempotent checks since they, by definition, will be migrated. That said, it appears useful.

I'm not a core maintainer, but I believe a fluent expression syntax for Preconditions might be useful here instead. That chaining methodology might be less invasive and more flexible in the long-run since it would be easy to extend to arbitrary preconditions. Something to the effect of:

Create.Table("foo")
    .WithPrecondition(Preconditions.MustNotExist)
    .WithIdColumn();

Alter.Table("bar")
    .AddColumn("someCol")
    .Precondition(Preconditions.MustNotExist);

Delete.Table("foo")
    .WithPrecondition(Preconditions.MustExist);

@fubar-coder fubar-coder added this to To consider in .NET Core / 2.0.0 Mar 28, 2018
@fubar-coder
Copy link
Member

This is a huge change that's in its current implementation SQL Server specific and too intrusive. The time until the upcoming 2.0.0 release is too short to include/rework this implementation.

A rework that's based off 2.0.0 would be fine and I'd suggest a DB agnostic framework that allows the creation of "SQL script wrappers" that is able to make the SQL scripts idempotent.

I also saw that you introduced migration dependencies and it seems that they are only required to guard a migration from being run when a version in a version table is missing. There is some work underway to make the migration pluggable and the VersionInfo table might not exist at all, because the versions are stored differently, and the current implementation is SQL Server specific too.

My suggestion is, that the new version of this PR should only contain the "SQL script wrappers", but not the migration version guard, as this might be a candidate for a different PR.

@fubar-coder fubar-coder removed this from To consider in .NET Core / 2.0.0 Mar 31, 2018
@fubar-coder fubar-coder self-assigned this Mar 31, 2018
@fubar-coder fubar-coder added the feature A new feature (we all like those) label Mar 31, 2018
@fubar-coder fubar-coder added this to the Backlog milestone Mar 31, 2018
@fubar-coder fubar-coder modified the milestones: Backlog, 3.0.0 Apr 10, 2018
@fubar-coder fubar-coder added the feature:idempotent-migrations Idempotent Migrations label Apr 30, 2018
@fubar-coder fubar-coder removed this from the 3.0.0 milestone Apr 30, 2018
@jzabroski jzabroski mentioned this pull request Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:idempotent-migrations Idempotent Migrations feature A new feature (we all like those)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants