.NET迁移:安装和迁移在运行多个数据库 [英] .NET migrations: Setup and migrate multiple databases at runtime

查看:114
本文介绍了.NET迁移:安装和迁移在运行多个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简介:
我有该ASP.NET Web表单与特殊性站点,它不仅具有1个数据库,它有许多。
为什么?因为您可以创建新的网站实例上的动态。每个实例共享同一个codeBase的,而是有其自己的数据库。这些所有数据库具有相同的架构(结构),但当然不同的数据。不要问你为什么不把一切都在一个数据库中,并使用INSTANCEID知道这是因为它是一个商业政策的事情。

Brief introduction: I have this ASP.NET Webforms site with the particularity that it doesn't have only 1 database, it has many. Why? Because you can create new "instances" of the site on-the-fly. Every "instance" share the same codebase, but has its own database. These all databases have the same schema (structure) but of course different data. Don't ask 'why don't you put everything in one database and use InstanceId to know which is" because it's a business policy thing.

应用程序知道被请求,因为URL的哪个实例。有一个额外的数据库来完成这个(我知道在设计时的连接字符串)。该数据库只有2表和同事的URL为应用程序实例。然后,当然,每个应用程序实例'具有其关联的连接字符串。

The application knows which instance is being requested because of the url. There is one extra database to accomplish this (I do know its connection string in design time). This database has only 2 tables and associates urls to 'application instances'. Then, of course, each 'application instance' has its associated connection string.

现状:没有什么,现在被用来帮助我们mantaining同步每个实例数据库(传播模式更改为每一位)的工作。所以我们用手工,这当然是一塌糊涂这样做。

Current situation: There is nothing being used right now to help us with the job of mantaining every instance database in sync (propagating schema changes to every one). So we are doing it by hand, which of course it's a total mess.

问:我想用钢轨迁移的方式来处理架构更改,preferably的 migratordotnet 的,但可以使用任何其他的,如果它更容易设置。

Question: I'd like to use a rails-migration way to handle schema changes, preferably migratordotnet, but could use any other if it's easier to setup.

问题是, migratordotnet 的需要连接系统,字符串中的 proj.build 的文件中声明,我不知道,直到运行时。

The problem is that migratordotnet needs the connnection string to be declare in the proj.build file and I don't know them until runtime.

什么这将是真正有用的是某种方法上运行* *的Application_Start应用于最新的移植到每个数据库。

What it would be REALLY useful is some kind of method running on *Application_Start* that applies the latest migration to every database.

这怎么可能用做的 migratordotnet 的或任何类似的?任何其他的建议是thanksfully欢迎。

How could this be done with migratordotnet or any similar? Any other suggestion is thanksfully welcomed.

感谢您!

推荐答案

由于这是一个老问题,我假设你已经以某种方式或其他解决了这个问题,但无论如何,我会发布解决方案的好处其他人碰到这个问题的绊脚石。它可以从code调用MigratorDotNet,而不是作为一个MSBuild目标:

Since this is an old question, I assume that you have solved the problem in some manner or another, but I'll post a solution anyway for the benefit of other people stumbling across this question. It is possible to invoke MigratorDotNet from code, rather than having it as an MSBuild target:

public static void MigrateToLastVersion(string provider, string connectionString)
{
    var silentLogger = new Logger(false, new ILogWriter[0]);
    var migrator = new Migrator.Migrator(provider, connectionString, 
                   typeof(YourMigrationAssembly).Assembly, false, silentLogger);
    migrator.MigrateToLastVersion();
}

这篇关于.NET迁移:安装和迁移在运行多个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆