asimeonov/DbUp.Downgrade

Clarification on detected difference

wtjones opened this issue ยท 11 comments

What does "detected difference" mean in this context?

The boolean parameter indicates will on detected difference an automated downgrade will be executed.

Hey, I am not a native English speaker but I will try to explain. If you pass the parameter as true, when older version is deployed downgrade will be performed automatically without the need to explicitly call PerformDowngrade function.

@wtjones is this additional info answers your question? I'll make changes in the read me to avoid confusion.

An example might help. The sample application calls PerformDowngradeForScripts(), passing in script 5. This is explicit. In what scenario would script 5 be downgraded via calling BuildWithDowngrade(true)?

I see what is the issue now. So this was latest functionality introduced I have to update the sample to showcase all possible usages. This that you are referring is manual revert of specific script by name.
In order to use the default build in downgrader you can use it like this

var upgrader = upgradeEngineBuilder.BuildWithDowngrade(true);

var result = upgrader.PerformUpgrade();

I'll update the samples and documentation in the next few days, thanks for pointing this out I'll update Program.cs with different methods to showcase.

Trying to make sure I follow:

If the app was upgraded to script 5, then script 5 was deleted from source and redeployed, it would downgrade script 5?

Yes, this is a showcase application. Normally you will not do this, this line shows the ability to manually revert a script by name. I am preparing showcase assembles to be referred by the main sample app.

That makes sense. I'm trying to work through this scenario:

  1. I deploy migrations 4-5.
  2. Ten minutes later I decide to downgrade this deployment to put me back at migration 3.
  3. Using the same build's migration tool, I instruct the migration tool to downgrade.

It seems that I would have the migration tool take an array of script names to pass scripts 4 and 5 so that this can happen:

 var result = upgrader.PerformDowngradeForScripts(new[] {
                "SampleApplication.Scripts.Script0004 - Redirects.sql",                                   // but from the array
                "SampleApplication.Scripts.Script0005 - Redirects add time to travel.sql" });  // but from the array

Is this how you see it as well?

In general the idea is that you have described. This with the script by name was introduced to mimic the functionality of EntityFramework in a separate application not related to the main one. The general idea that I was after is:

  1. You deploy version with migration 4 and 5.
  2. Something goes wrong with your service and you need to revert to previews version
  3. You depoy the older version, then the package will kick in and downgrade the DB because you may have incompatibility with the ORM models and database models for example.

This is generally supported by the library simply by using var upgrader = upgradeEngineBuilder.BuildWithDowngrade(true); and then calling var result = upgrader.PerformUpgrade(); and the library will autodetect the downgrade DB to previews version. The manual script revert was created with the idea to be used from a separate application build explicitly for reverting DB scripts by name.

I hope that this bring more clarification, I'll try to finish the samples this weekend.

You deploy the older version

I was missing this piece. I deploy the binary with migration 3, so it uses the DowngradeScript column as it won't have it in source.

I was wondering how to revert views/procs as they run outside of migrations via NullJournal, however using the prior binary would solve this as well.

Yes exactly, the idea of the library is to plug into the DbUp pipeline and to provide auto functionality for downgrading. I'll have really hard time to create samples because I can't simulate 2 versions of the same assembly into 1 solution. Maybe I'll go with 2 sample console apps with the same assembly name. But then I'll have to create readme explicitly for samples in order to showcase the functionality.

I'll try to do this in the next few days depends of my availability.

I have create PR, please have a look and check will this samples makes more sense and clarification of the functionality.