question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Apply migration to every database in a shard using Elastic Database?

See original GitHub issue

I have a project which uses the Elastic Database client library to work with a multi-tenant application. Each database belongs to a single tenant.

I would like to use FluentMigrator to manage the schema of every database in the shard.

Ideally, I’d like to configure a runner with multiple connection strings (which I get from the Elastic Database client).

    private static IServiceProvider CreateServices()
        {
            return new ServiceCollection()
                // Add common FluentMigrator services
                .AddFluentMigratorCore()
                .ConfigureRunner(rb => rb
                    // Add SQLite support to FluentMigrator
                    .AddSQLite()
                    // Set the connection string
                    .WithGlobalConnectionString("Data Source=test.db") // add multiple?
                    // Define the assembly containing the migrations
                    .ScanIn(typeof(AddLogTable).Assembly).For.Migrations())
                // Enable logging to console in the FluentMigrator way
                .AddLogging(lb => lb.AddFluentMigratorConsole())
                // Build the service provider
                .BuildServiceProvider(false);
        }

Is there a supported way to do this? Or do I need to explicitly create and execute one runner per database?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fubar-codercommented, Jun 25, 2019

You have two options:

  1. Create services per-database
  2. Provide your own IConnectionStringAccessor implementation and run the migrator multiple times where your IConnectionStringAccessor implementation returns a different connection string on each run (static variable?)
0reactions
jzabroskicommented, Aug 18, 2020

@c17r Thanks for the detailed use case layout. Very helpful.

WithGlobalConnectionString is per service provider. So, if you’re only referencing FluentMigrator objects within your DI scope, you can just create multiple service providers and dispose of them when you’re done. The “Global” is really per ServiceCollection at the point you call BuildServiceProvider();

It’s when you want to mix in outside objects not native to FluentMigrator that things get hairy, because then you’re mixing type universes and potentially lifetime scopes, and an “external” object you’re injecting might not exist at run-time because it’s been disposed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrate existing databases to scale out - Azure SQL ...
To migrate an existing sharded database: Prepare the shard map manager database. Create the shard map. Prepare the individual shards.
Read more >
Migrate data between shards
The database I'm working on works with Guids, so we can't use the example code. I've created a Move/Merge management tool myself, but...
Read more >
Migrating data | Elasticsearch Service Documentation
Use the steps on this page to reindex the internal indices from a remote cluster. The steps for reindexing internal indices and regular,...
Read more >
Using Oracle Sharding
You can migrate data from a non-sharded database to an Oracle Sharding sharded database using the methods described here.
Read more >
What is Database Sharding? - Shard DB Explained
Database sharding overcomes this limitation by splitting data into smaller chunks, called shards, and storing them across several database servers. All database ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found