migrating-ravens / RavenMigrations

A small migrations framework to help you manage your RavenDB Instance.
MIT License
53 stars 24 forks source link

Migration profile behaviour #1

Closed seankearon closed 10 years ago

seankearon commented 10 years ago

Am I right that migrations with no profile are always called? Seems to be the case from Can_call_migrations_ignore_migrations_with_profile().

So, if that's true, how would you like tests that won't pick up your default migrations?

khalidabuhakmeh commented 10 years ago

Yes migrations without a profile are still called. Essentially they are your base line migrations.

 So, if that's true, how would you like tests that won't pick up your default migrations?

Sorry I don't understand. Are you asking how would you write a test that ignores the default migrations?

seankearon commented 10 years ago

Yes, how do I write a test that ignores the default migrations?

khalidabuhakmeh commented 10 years ago

Currently there isn't a way, but there are a couple of options.

  1. We can enhance the core of the runner to allow you to create a scanner along side a resolver. That way you can scan for the migrations your self.
  2. If you only need to run one migration just new it up, set the document store, and execute the up or down.
  3. modify the default behavior to allow you to include or exclude migrations without a profile.

2 is your easiest option, but I'd accept a pull request for 1 or 3 :)

what do you think?

seankearon commented 10 years ago

Okay, thanks. I'll take a look at 3 - sounds the easiest route for tests.

The reason I'm asking is I'm working up a change that adds a bit of sugar around migrating collections at the JObject level. Looks like this:

[Migration(1, "CollectionDocumentMigration")]
public class CollectionDocumentMigration : Migration
{
    public override void Down()
    {
        MigrateCollection("People", JoinFirstNameAndLastNameIntoName);
    }

    public override void Up()
    {
        MigrateCollection("People", SplitNameToFirstNameAndLastName);
    }

    private void JoinFirstNameAndLastNameIntoName(RavenJObject obj)         { ... }

    private void SplitNameToFirstNameAndLastName(RavenJObject obj)        { ... }
}

You can see it here:

https://github.com/seankearon/RavenMigrations/blob/master/RavenMigrations.Tests/CollectionMigrationTests.cs

If you like it, I'll take route 2 above and send a pull request.

khalidabuhakmeh commented 10 years ago

Looks awesome I would just reconsider the naming of it. Rather MigrateCollection how about using verbs like Alter, Update, and Delete.

So in the case above, we would have something like

    Alter.Collection("People", SplitNameToFirstNameAndLastName);

or even

  Alter.Collection("People", jobject => {  /* some code */ });

What are your thoughts?

seankearon commented 10 years ago

Sounds good. Will check in changes soon.

I'm getting a test failure in the existing tests from Can_call_up_then_down_on_migrations(): Bulk operation cancelled because the index is stale and allowStale is false. Updating the test to add WaitForIndexing(store); doesn't seem to fix it.

Are you seeing the same thing?

I'm using 2013 and I had to add a redirect for xunit as I was getting this:

System.IO.FileLoadException Could not load file or assembly 'xunit, Version=1.9.1.1600, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

seankearon commented 10 years ago

Err, cancel the last comment. That's gone away for some reason!

khalidabuhakmeh commented 10 years ago

I get that when running the tests in ReSharper, but when running in NCrunch tests work fine. ReSharper's test runner is not best of bread anymore (imho).

seankearon commented 10 years ago

Aha - I was in R#. Will look at NCrunch then. Thanks for the tip.

seankearon commented 10 years ago

Pull sent!