是否可以在application_start中使用流畅的迁移器?
我正在使用流畅的迁移器来管理我的数据库迁移,但我想做的是在应用程序启动时运行迁移。我管理过的最接近的是:
public static void MigrateToLatest(string connectionString)
{
using (var announcer = new TextWriterAnnouncer(Console.Out)
{
ShowElapsedTime = true,
ShowSql = true
})
{
var assembly = typeof(Runner).Assembly.GetName().Name;
var migrationContext = new RunnerContext(announcer)
{
Connection = connectionString,
Database = "SqlServer2008",
Target = assembly
};
var executor = new TaskExecutor(migrationContext);
executor.Execute();
}
}
我确信我已经完成了这个工作,但我有一段时间没有查看它(业余爱好项目),现在当它到达执行 线。遗憾的是,没有这方面的文档,而且我多年来一直在努力解决这个问题。
有没有人设法让这种事情与 FluentMigrator 一起工作?
I'm using fluent migrator to manage my database migrations, but what I'd like to do is have the migrations run at app start. The closest I have managed is this:
public static void MigrateToLatest(string connectionString)
{
using (var announcer = new TextWriterAnnouncer(Console.Out)
{
ShowElapsedTime = true,
ShowSql = true
})
{
var assembly = typeof(Runner).Assembly.GetName().Name;
var migrationContext = new RunnerContext(announcer)
{
Connection = connectionString,
Database = "SqlServer2008",
Target = assembly
};
var executor = new TaskExecutor(migrationContext);
executor.Execute();
}
}
I'm sure I had this working, but I've not looked at it for sometime (hobby project) and it's now throwing null reference exceptions when it gets to the Execute
line. Sadly there are no docs for this and I've been banging my head on it for ages.
Has anyone managed to get this kind of thing working with FluentMigrator?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
手动添加对以下内容的引用:
注意该文件夹名称会因版本号而异,此插图使用当前的 1.6.1 版本。如果您需要 .NET 3.5 运行程序,请使用
\35\
目录。请注意,SqlServer2008ProcessorFactory 是可根据您的数据库进行配置的,支持:2000、2005、2008、2012 和 2014。
Manually add a reference to:
Note that the folder name will vary on version number, this illustration uses the current 1.6.1 release. If you need the .NET 3.5 runner use the
\35\
directory.Note the
SqlServer2008ProcessorFactory
this is configurable dependent upon your database, there is support for: 2000, 2005, 2008, 2012, and 2014.我实际上已经在 application_start 中完成了运行迁移,但是很难从该代码中判断出什么问题......由于它是开源的,我只需获取代码并将其拉入您的解决方案并构建它以找出问题所在执行方法正在抱怨。我发现 Fluent Migrator 的源代码组织得很好。
如果这是一个 Web 应用程序,您可能需要担心的一件事是确保在您迁移时没有人使用数据库。我使用的策略是建立连接,将数据库设置为单用户模式,运行迁移,将数据库设置为多用户模式,然后关闭连接。这还可以处理多台服务器上的负载平衡 Web 应用程序的情况,因此 2 台服务器不会尝试针对同一数据库运行迁移。
I have actually accomplished running migrations in the application_start however it is hard to tell from that code what could be wrong... Since it is open source I would just grab the code and pull it into your solution and build it to find out what the Execute method is complaining about. I found that the source code for Fluent Migrator is organized pretty well.
One thing that you might have to be concerned about if this is a web app is making sure that no one uses the database while you are migrating. I used a strategy of establishing a connection, setting the database to single user mode, running the migrations, setting the database to multi user mode, then closing the connection. This also handles the scenario of a load balanced web application on multiple servers so 2 servers don't try to run migrations against the same database.