#17445 - Fixing index management in data migrations

--HG--
branch : dev
extra : transplant_source : %C08yTv%40%C4%BERtb%5DL%5B%BA%81%3B%DA%DD%F9
This commit is contained in:
Sebastien Ros
2011-03-07 15:25:28 -08:00
parent 7c05a99dd2
commit 8a110c692d
5 changed files with 24 additions and 24 deletions

View File

@@ -28,6 +28,7 @@ using Orchard.FileSystems.AppData;
using Orchard.FileSystems.Dependencies; using Orchard.FileSystems.Dependencies;
using Orchard.Tests.ContentManagement; using Orchard.Tests.ContentManagement;
using Orchard.Data.Providers; using Orchard.Data.Providers;
using Orchard.Tests.DataMigration.Utilities;
using Orchard.Tests.FileSystems.AppData; using Orchard.Tests.FileSystems.AppData;
using Orchard.Tests.Modules.Migrations.Orchard.Tests.DataMigration.Records; using Orchard.Tests.Modules.Migrations.Orchard.Tests.DataMigration.Records;
using Path = Bleroy.FluentPath.Path; using Path = Bleroy.FluentPath.Path;

View File

@@ -19,6 +19,7 @@ using Orchard.Environment.Extensions.Folders;
using Orchard.Environment.Extensions.Models; using Orchard.Environment.Extensions.Models;
using Orchard.Tests.ContentManagement; using Orchard.Tests.ContentManagement;
using Orchard.Data.Providers; using Orchard.Data.Providers;
using Orchard.Tests.DataMigration.Utilities;
using Orchard.Tests.Stubs; using Orchard.Tests.Stubs;
namespace Orchard.Tests.DataMigration { namespace Orchard.Tests.DataMigration {

View File

@@ -21,7 +21,7 @@ using Orchard.Tests.Stubs;
namespace Orchard.Tests.DataMigration { namespace Orchard.Tests.DataMigration {
[TestFixture] [TestFixture]
public class SchemaBuilderTests { public class SchemaBuilderTestsBase {
private IContainer _container; private IContainer _container;
private ISessionFactory _sessionFactory; private ISessionFactory _sessionFactory;
private string _databaseFileName; private string _databaseFileName;
@@ -63,8 +63,6 @@ namespace Orchard.Tests.DataMigration {
[Test] [Test]
public void AllMethodsShouldBeCalledSuccessfully() { public void AllMethodsShouldBeCalledSuccessfully() {
_schemaBuilder = new SchemaBuilder(new NullInterpreter());
_schemaBuilder _schemaBuilder
.CreateTable("User", table => table .CreateTable("User", table => table
.ContentPartRecord() .ContentPartRecord()
@@ -75,19 +73,17 @@ namespace Orchard.Tests.DataMigration {
.Column("City", DbType.String) .Column("City", DbType.String)
.Column("ZIP", DbType.Int32, column => column.Unique()) .Column("ZIP", DbType.Int32, column => column.Unique())
.Column("UserId", DbType.Int32, column => column.NotNull())) .Column("UserId", DbType.Int32, column => column.NotNull()))
.CreateForeignKey("User_Address", "User", new[] { "UserId" }, "User", new[] { "Id" }) .CreateForeignKey("User_Address", "Address", new[] { "UserId" }, "User", new[] { "Id" })
.AlterTable("User", table => table .AlterTable("User", table => table
.AddColumn("Age", DbType.Int32)) .AddColumn("Age", DbType.Int32))
.AlterTable("User", table => table .AlterTable("User", table => table
.DropColumn("Lastname")) .DropColumn("Lastname"))
.AlterTable("User", table => table .AlterTable("User", table => table
.CreateIndex("IDX_XYZ", "NickName")) .CreateIndex("IDX_XYZ", "Firstname"))
.AlterTable("User", table => table .AlterTable("User", table => table
.DropIndex("IDX_XYZ")) .DropIndex("IDX_XYZ"))
.DropForeignKey("Address", "User_Address") .DropForeignKey("Address", "User_Address")
.DropTable("Address") .DropTable("Address");
.ExecuteSql("drop database", statement => statement.ForProvider("SqlCe"))
.ExecuteSql("DROP DATABASE", statement => statement.ForProvider("SQLServer"));
} }
[Test] [Test]

View File

@@ -1,26 +1,28 @@
using Orchard.Data.Migration.Interpreters; using Orchard.Data.Migration.Interpreters;
using Orchard.Data.Migration.Schema; using Orchard.Data.Migration.Schema;
public class NullInterpreter : IDataMigrationInterpreter { namespace Orchard.Tests.DataMigration.Utilities {
public class NullInterpreter : IDataMigrationInterpreter {
public void Visit(ISchemaBuilderCommand command) { public void Visit(ISchemaBuilderCommand command) {
} }
public void Visit(CreateTableCommand command) { public void Visit(CreateTableCommand command) {
} }
public void Visit(DropTableCommand command) { public void Visit(DropTableCommand command) {
} }
public void Visit(AlterTableCommand command) { public void Visit(AlterTableCommand command) {
} }
public void Visit(SqlStatementCommand command) { public void Visit(SqlStatementCommand command) {
} }
public void Visit(CreateForeignKeyCommand command) { public void Visit(CreateForeignKeyCommand command) {
} }
public void Visit(DropForeignKeyCommand command) { public void Visit(DropForeignKeyCommand command) {
}
} }
} }

View File

@@ -211,7 +211,7 @@ namespace Orchard.Data.Migration.Interpreters {
return; return;
} }
builder.AppendFormat("alter table {0} add index {1} ({2}) ", builder.AppendFormat("create index {1} on {0} ({2}) ",
_dialect.QuoteForTableName(PrefixTableName(command.TableName)), _dialect.QuoteForTableName(PrefixTableName(command.TableName)),
_dialect.QuoteForColumnName(command.IndexName), _dialect.QuoteForColumnName(command.IndexName),
String.Join(", ", command.ColumnNames)); String.Join(", ", command.ColumnNames));
@@ -224,7 +224,7 @@ namespace Orchard.Data.Migration.Interpreters {
return; return;
} }
builder.AppendFormat("alter table {0} drop index {1}", builder.AppendFormat("drop index {0}.{1}",
_dialect.QuoteForTableName(PrefixTableName(command.TableName)), _dialect.QuoteForTableName(PrefixTableName(command.TableName)),
_dialect.QuoteForColumnName(command.IndexName)); _dialect.QuoteForColumnName(command.IndexName));
_sqlStatements.Add(builder.ToString()); _sqlStatements.Add(builder.ToString());