Corrected foreign key management in data migrations

- Remove the SQLite specific overloads which had been converted to SqlCe by mistake
- Keep the SQLite class as an example implementation
- Updated the unit tests

--HG--
branch : dev
This commit is contained in:
Sebastien Ros
2010-08-19 12:37:41 -07:00
parent 8b2065579b
commit a767494f9f
5 changed files with 11 additions and 10 deletions

View File

@@ -50,7 +50,6 @@ namespace Orchard.Tests.DataMigration {
builder.RegisterInstance(new DefaultContentManagerTests.TestSessionLocator(session)).As<ISessionLocator>();
builder.RegisterInstance(new ShellBlueprint { Records = Enumerable.Empty<RecordBlueprint>() }).As<ShellBlueprint>();
builder.RegisterInstance(new ShellSettings { Name = "temp", DataProvider = "SqlCe", DataTablePrefix = "TEST_" }).As<ShellSettings>();
builder.RegisterType<SqlCeCommandInterpreter>().As<ICommandInterpreter>();
builder.RegisterModule(new DataModule());
_container = builder.Build();
@@ -153,8 +152,8 @@ namespace Orchard.Tests.DataMigration {
.Column("City", DbType.String)
.Column("ZIP", DbType.Int32, column => column.Unique())
.Column("UserId", DbType.Int32, column => column.NotNull()))
.CreateForeignKey("User_Address", "User", new[] { "UserId" }, "User", new[] { "Id" })
.DropForeignKey("User", "User_Address");
.CreateForeignKey("FK_User", "Address", new[] { "UserId" }, "User", new[] { "Id" })
.DropForeignKey("Address", "FK_User");
}
}

View File

@@ -25,6 +25,8 @@ namespace Orchard.Blogs.DataMigrations {
.Column<int>("PostCount")
);
SchemaBuilder.CreateForeignKey()
return 1;
}

View File

@@ -186,7 +186,7 @@ namespace Orchard.Data.Migration.Interpreters {
builder.AppendFormat("alter table {0} alter column {1} ",
_dialect.QuoteForTableName(PrefixTableName(command.TableName)),
_dialect.QuoteForColumnName(command.TableName));
_dialect.QuoteForColumnName(command.ColumnName));
// type
if (command.DbType != DbType.Object) {
@@ -195,7 +195,7 @@ namespace Orchard.Data.Migration.Interpreters {
// [default value]
if (!string.IsNullOrEmpty(command.Default)) {
builder.Append(" default ").Append(command.Default).Append(Space);
builder.Append(" set default ").Append(command.Default).Append(Space);
}
_sqlStatements.Add(builder.ToString());
}
@@ -250,7 +250,7 @@ namespace Orchard.Data.Migration.Interpreters {
builder.Append(_dialect.GetAddForeignKeyConstraintString(command.Name,
command.SrcColumns,
command.DestTable,
_dialect.QuoteForTableName(PrefixTableName(command.DestTable)),
command.DestColumns,
false));
@@ -266,7 +266,7 @@ namespace Orchard.Data.Migration.Interpreters {
var builder = new StringBuilder();
builder.AppendFormat("alter table {0} drop constraint {1}", command.SrcTable, command.Name);
builder.AppendFormat("alter table {0} drop constraint {1}", _dialect.QuoteForTableName(PrefixTableName(command.SrcTable)), command.Name);
_sqlStatements.Add(builder.ToString());
RunPendingStatements();

View File

@@ -1,7 +1,7 @@
using Orchard.Data.Migration.Schema;
namespace Orchard.Data.Migration.Interpreters {
public class SqlCeCommandInterpreter :
public class SQLiteCommandInterpreter :
ICommandInterpreter<DropColumnCommand>,
ICommandInterpreter<AlterColumnCommand>,
ICommandInterpreter<CreateForeignKeyCommand>,
@@ -34,7 +34,7 @@ namespace Orchard.Data.Migration.Interpreters {
}
public string DataProvider {
get { return "SqlCe"; }
get { return "SQLite"; }
}
}
}

View File

@@ -379,7 +379,7 @@
<Compile Include="Data\Migration\Interpreters\ICommandInterpreter.cs" />
<Compile Include="Data\Migration\Interpreters\DefaultDataMigrationInterpreter.cs" />
<Compile Include="Data\Migration\Interpreters\IDataMigrationInterpreter.cs" />
<Compile Include="Data\Migration\Interpreters\SqlCeCommandInterpreter.cs" />
<Compile Include="Data\Migration\Interpreters\SQLiteCommandInterpreter.cs" />
<Compile Include="Data\Migration\Interpreters\StringCommandInterpreter.cs" />
<Compile Include="Data\Migration\Schema\AddColumnCommand.cs" />
<Compile Include="Data\Migration\Schema\ISchemaBuilderCommand.cs" />