本文介绍了FluentMigrator迁移成功,但没有改变DB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一定是失去了一些东西pretty的基础。

I must be missing something pretty basic.

我工作的一个传统项目,我试图把FluentMigrator混进去,因为我已经得到了一些有趣的资料库变化和数据迁移上来,我认为将是多发通过使用这个工具更容易。

I'm working on a legacy project, and I'm trying to bringFluentMigrator into the mix cause I've got some interesting databasechanges and data migrations coming up that I think will be made mucheasier by using this tool.

对于初始迁移,我只是想使数据库的目前的量产版,原样。为了简化初始迁移,我的脚本我的SQL Server 2008数据库,并迁移执行时该脚本的命令为一系列的SQL命令。

For the initial migration, I just want to bring the database up to thecurrent production version, as-is. To simplify the initial migration,I scripted out my SQL Server 2008 database, and the migration executesthe scripted commands as a series of SQL commands.

要测试它,我创建了一个完全空的数据库,并尝试运行它从命令行中使用这样的:

To test it out, I create an entirely empty database, and try to run itfrom command line using this:

> migrate -a "C:\My\Project\Path\bin\debug\Rds.MyProjName.DBMigrations.dll" 
-db SqlServer2008 -conn "Data Source=.\SQLEXPRESS2008;Initial Catalog=myNewDbName;
Integrated Security=SSPI" -version=20100901000000

指定的版本是在第一迁移类的时间戳迁移属性。

The version specified is the timestamp on the first migration class'sMigration attribute.

在命令行,一切似乎运行良好 - 在整剧本由放大,并与结束:

At the command line, everything appears to run fine - the the entirescript zooms by, and it ends with:

-- CreateProductionDbCircaSep2010: migrated

然而,当我看看数据库,它仍然是空的。绝对没有在那里。我最多的方法是这样的:

However, when I take a look at the database, it is still empty.Absolutely nothing is in there. My Up method looks like this:

public override void Up()
{
    var cmds = LoadEmbeddedResources
        .GetEmbeddedResource("scripted_db_2010-09-01.sql")
        .AsString()
        .ParseCommands();

    foreach (var c in cmds) {
        Execute.Sql(c);
    }

    CreateReferenceData();
}

(仅供参考,我解析运行它,是因为我的脚本,而不是通过使用Migrator.Net开始发现它死之前,这已经成立了。)

(FYI, I'm parsing the script instead of running it as-is because Istarted by using Migrator.Net before discovering it was dead, and thiswas already set up.)

谁能给我个忙吗?它几乎看起来像一个交易不提交,或一些命令行选项,迁移做了干法运行已打开,但我没有看到它...

Can anyone give me a hand? It almost appears like a transaction isn'tcommitting, or some command-line option to have the migration do a dry-run is turned on, but I don't see it...

编辑:其他的事情我已经试过

要确认连接字符串使用我希望它的数​​据库,我改名为数据库,之后得到了一个登录错误,符合市场预期。

To confirm that the connection string was using the database I expect it to, I renamed the database and afterwards got a login error, as expected.

有关进一步的测试,我砍剧本的长度,并试图利用它执行

For further tests, I cut down the length of the script, and tried executing it using

public override void Up()
{
    Execute.Script(@"..\Resources\test.sql"); 
}

而不是命令由命令

,但我得到了相同的结果。下面是该测试的输出(请注意,我编辑了pathes等等):

instead of command-by-command, but I get the same results. Here is the output on that test (note, I edited the pathes and such):

C:\My\Project\Path\FluentMigrator.Net\ >migrate -a "C:\My\Project\Path\bin\debug
\My.Project.DBMigrations.dll" -db SqlServer2008 -conn "Data Source=.\SQLEXPRESS2
008;Initial Catalog=myNewDbName;Integrated Security=SSPI" -version=2010090100000
0
Using Database SqlServer2008 and Connection String Data Source=.\SQLEXPRESS2008;
Initial Catalog=myNewDbName;Integrated Security=SSPI
-- VersionMigration: migrating ===============================================

-- CreateTable VersionInfo
-- VersionMigration: migrated
-- CreateProductionDbCircaSep2010: migrating =================================

-- ExecuteSqlScript C:\My\Project\Path\FluentMigrator.Net\..\Resources\test.sql
-- CreateProductionDbCircaSep2010: migrated

然而,没有数据库中的表 - 竟然没有预期的VERSIONINFO表

Yet no tables in the database - there isn't even the expected VersionInfo table.

推荐答案

经过一番调查和测试包含版本0.8和1.0,看来这是关系到移民亚军的事务管理中FluentMigrator.Net错误 - 如果你运行具有特定版本号的迁移,事务提交不会被调用;如果你不指定版本号,这很好。

After some investigation and testing with both version 0.8 and 1.0, it appears this is a bug in FluentMigrator.Net related to the migration runner's transaction management - if you run a migration with a specific version number, the transaction's commit never gets called; if you don't specify a version number, it's fine.

编辑:

因为我已经提交了一个补丁,这是公认的该项目。这已经不再是一个问题。

I have since submitted a patch to the project which was accepted. This is no longer a problem.

这篇关于FluentMigrator迁移成功,但没有改变DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 06:57