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

Prefix of MitrationVersion Collection #12

Closed
lprada opened this issue Oct 3, 2019 · 1 comment
Closed

Prefix of MitrationVersion Collection #12

lprada opened this issue Oct 3, 2019 · 1 comment

Comments

@lprada
Copy link

lprada commented Oct 3, 2019

HI, what we need is the posibility to shared the same dabatase between differents microservicies. For this I need that a prefix can be add to the MigrationVersion Collection or have another parameter so I can migrate diferentes schemas in the database.

@VladimirRybalko
Copy link
Owner

VladimirRybalko commented Jan 7, 2020

Hello @lprada.
Thank you for your feedback.

The version 2.2.0 is what you need.
I've added the collection specific migrations there. So, now you have much more control how to apply different migrations.

In your particular case, please review the following example.
Here, I create a specific migration for the Animals migration.

   [Migration("Animals", 0)]
    public sealed class AddAnimalMigration : Migration
    {
        public override void Up()
        {
            var collection = GetCollection("Animals");
            var document = new BsonDocument();

            document.AddUniqueIdentifier(new Guid("2A7B73A8-3C4A-422D-90B4-C73BCF48EBD4"));
            document.AddProperty("Kind", "Cat");

            collection.InsertOne(document);
        }

        public override void Down()
        {
            var collection = GetCollection("Animals");
            var idFilter = Builders<BsonDocument>.Filter.Eq("_id", new Guid("2A7B73A8-3C4A-422D-90B4-C73BCF48EBD4"));
            collection.DeleteOne(idFilter);
        }
    }

Then, what you need is just initiate the runner class and apply all migrations for the specific collection.

   var runner = new MigrationRunner("mongodb://localhost:27017/TestMigrations", Assembly.GetExecutingAssembly().FullName, new MigrationFactory());
    runner.Up("Animals");

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

No branches or pull requests

2 participants