mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 03:25:23 +08:00
Added index management to data migration API
--HG-- branch : dev
This commit is contained in:
@@ -6,7 +6,6 @@ using System.Text.RegularExpressions;
|
||||
using Orchard.Data;
|
||||
using Orchard.DataMigration.Interpreters;
|
||||
using Orchard.DataMigration.Schema;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.State;
|
||||
using Orchard.Logging;
|
||||
@@ -20,7 +19,6 @@ namespace Orchard.DataMigration {
|
||||
private readonly IRepository<DataMigrationRecord> _dataMigrationRepository;
|
||||
private readonly IDataMigrationGenerator _dataMigrationGenerator;
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
private readonly ShellSettings _shellSettings;
|
||||
private readonly IDataMigrationInterpreter _interpreter;
|
||||
|
||||
public DataMigrationManager(
|
||||
@@ -28,13 +26,11 @@ namespace Orchard.DataMigration {
|
||||
IRepository<DataMigrationRecord> dataMigrationRepository,
|
||||
IDataMigrationGenerator dataMigrationGenerator,
|
||||
IExtensionManager extensionManager,
|
||||
ShellSettings shellSettings,
|
||||
IDataMigrationInterpreter interpreter) {
|
||||
_dataMigrations = dataMigrations;
|
||||
_dataMigrationRepository = dataMigrationRepository;
|
||||
_dataMigrationGenerator = dataMigrationGenerator;
|
||||
_extensionManager = extensionManager;
|
||||
_shellSettings = shellSettings;
|
||||
_interpreter = interpreter;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.DataMigration.Commands;
|
||||
|
||||
namespace Orchard.DataMigration {
|
||||
public class DefaultDataMigrationGenerator : IDataMigrationGenerator {
|
||||
|
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.DataMigration.Commands;
|
||||
|
||||
namespace Orchard.DataMigration {
|
||||
// Builds and runs the representative migration create calls
|
||||
|
@@ -129,6 +129,21 @@ namespace Orchard.DataMigration.Interpreters {
|
||||
Visit(builder, alterColumn);
|
||||
RunPendingStatements();
|
||||
}
|
||||
|
||||
// add index
|
||||
foreach ( var addIndex in command.TableCommands.OfType<AddIndexCommand>() ) {
|
||||
var builder = new StringBuilder();
|
||||
Visit(builder, addIndex);
|
||||
RunPendingStatements();
|
||||
}
|
||||
|
||||
// drop index
|
||||
foreach ( var dropIndex in command.TableCommands.OfType<DropIndexCommand>() ) {
|
||||
var builder = new StringBuilder();
|
||||
Visit(builder, dropIndex);
|
||||
RunPendingStatements();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Visit(StringBuilder builder, AddColumnCommand command) {
|
||||
@@ -149,7 +164,7 @@ namespace Orchard.DataMigration.Interpreters {
|
||||
|
||||
builder.AppendFormat("alter table {0} drop column {1}",
|
||||
_dialect.QuoteForTableName(_shellSettings.DataTablePrefix + command.TableName),
|
||||
_dialect.QuoteForColumnName(command.TableName));
|
||||
_dialect.QuoteForColumnName(command.ColumnName));
|
||||
_sqlStatements.Add(builder.ToString());
|
||||
}
|
||||
|
||||
@@ -174,6 +189,30 @@ namespace Orchard.DataMigration.Interpreters {
|
||||
_sqlStatements.Add(builder.ToString());
|
||||
}
|
||||
|
||||
|
||||
public void Visit(StringBuilder builder, AddIndexCommand command) {
|
||||
if ( ExecuteCustomInterpreter(command) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
builder.AppendFormat("alter table {0} add index {1} ({2}) ",
|
||||
_dialect.QuoteForTableName(_shellSettings.DataTablePrefix + command.TableName),
|
||||
_dialect.QuoteForColumnName(command.IndexName),
|
||||
String.Join(", ", command.ColumnNames));
|
||||
|
||||
_sqlStatements.Add(builder.ToString());
|
||||
}
|
||||
|
||||
public void Visit(StringBuilder builder, DropIndexCommand command) {
|
||||
if ( ExecuteCustomInterpreter(command) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
builder.AppendFormat("alter table {0} drop index {1}",
|
||||
_dialect.QuoteForTableName(_shellSettings.DataTablePrefix + command.TableName),
|
||||
_dialect.QuoteForColumnName(command.IndexName));
|
||||
_sqlStatements.Add(builder.ToString());
|
||||
}
|
||||
public void Visit(SqlStatementCommand command) {
|
||||
if (command.Providers.Count == 0 || command.Providers.Contains(_shellSettings.DataProvider) ) {
|
||||
if (ExecuteCustomInterpreter(command)) {
|
||||
|
@@ -1,15 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Orchard.DataMigration.Schema;
|
||||
using Orchard.DataMigration.Schema;
|
||||
|
||||
namespace Orchard.DataMigration.Interpreters {
|
||||
public class SqLiteCommandInterpreter :
|
||||
ICommandInterpreter<DropColumnCommand>,
|
||||
ICommandInterpreter<AlterColumnCommand>,
|
||||
ICommandInterpreter<CreateForeignKeyCommand>,
|
||||
ICommandInterpreter<DropForeignKeyCommand> {
|
||||
ICommandInterpreter<DropForeignKeyCommand>,
|
||||
ICommandInterpreter<AddIndexCommand>,
|
||||
ICommandInterpreter<DropIndexCommand> {
|
||||
|
||||
public string[] CreateStatements(DropColumnCommand command) {
|
||||
return new string[0];
|
||||
@@ -27,6 +25,14 @@ namespace Orchard.DataMigration.Interpreters {
|
||||
return new string[0];
|
||||
}
|
||||
|
||||
public string[] CreateStatements(AddIndexCommand command) {
|
||||
return new string[0];
|
||||
}
|
||||
|
||||
public string[] CreateStatements(DropIndexCommand command) {
|
||||
return new string[0];
|
||||
}
|
||||
|
||||
public string DataProvider {
|
||||
get { return "SQLite"; }
|
||||
}
|
||||
|
@@ -1,6 +1,4 @@
|
||||
using System.Data;
|
||||
|
||||
namespace Orchard.DataMigration.Schema {
|
||||
namespace Orchard.DataMigration.Schema {
|
||||
public class AddColumnCommand : CreateColumnCommand {
|
||||
public AddColumnCommand(string tableName, string name) : base(tableName, name) {
|
||||
}
|
||||
|
13
src/Orchard/DataMigration/Schema/AddIndexCommand.cs
Normal file
13
src/Orchard/DataMigration/Schema/AddIndexCommand.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace Orchard.DataMigration.Schema {
|
||||
public class AddIndexCommand : TableCommand {
|
||||
public string IndexName { get; set; }
|
||||
|
||||
public AddIndexCommand(string tableName, string indexName, params string[] columnNames)
|
||||
: base(tableName) {
|
||||
ColumnNames = columnNames;
|
||||
IndexName = indexName;
|
||||
}
|
||||
|
||||
public string[] ColumnNames { get; private set; }
|
||||
}
|
||||
}
|
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Orchard.DataMigration.Schema {
|
||||
public class AlterTableCommand : SchemaCommand {
|
||||
@@ -34,13 +33,13 @@ namespace Orchard.DataMigration.Schema {
|
||||
TableCommands.Add(command);
|
||||
}
|
||||
|
||||
public void CreateIndex(string name, params string[] columnNames) {
|
||||
var command = new CreateIndexCommand(name, columnNames);
|
||||
public void CreateIndex(string indexName, params string[] columnNames) {
|
||||
var command = new AddIndexCommand(Name, indexName, columnNames);
|
||||
TableCommands.Add(command);
|
||||
}
|
||||
|
||||
public void DropIndex(string name) {
|
||||
var command = new DropIndexCommand(name);
|
||||
public void DropIndex(string indexName) {
|
||||
var command = new DropIndexCommand(Name, indexName);
|
||||
TableCommands.Add(command);
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Orchard.DataMigration.Schema {
|
||||
namespace Orchard.DataMigration.Schema {
|
||||
public class CreateForeignKeyCommand : SchemaCommand {
|
||||
|
||||
public string[] DestColumns { get; private set; }
|
||||
|
@@ -1,10 +0,0 @@
|
||||
namespace Orchard.DataMigration.Schema {
|
||||
public class CreateIndexCommand : TableCommand {
|
||||
public CreateIndexCommand(string indexName, params string[] columnNames)
|
||||
: base(indexName) {
|
||||
ColumnNames = columnNames;
|
||||
}
|
||||
|
||||
public string[] ColumnNames { get; private set; }
|
||||
}
|
||||
}
|
@@ -1,8 +1,10 @@
|
||||
namespace Orchard.DataMigration.Schema {
|
||||
public class DropIndexCommand : TableCommand {
|
||||
public string IndexName { get; set; }
|
||||
|
||||
public DropIndexCommand(string name)
|
||||
: base(name) {
|
||||
public DropIndexCommand(string tableName, string indexName)
|
||||
: base(tableName) {
|
||||
IndexName = indexName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Orchard.DataMigration.Schema {
|
||||
namespace Orchard.DataMigration.Schema {
|
||||
public interface ISchemaBuilderCommand {
|
||||
}
|
||||
}
|
||||
|
@@ -367,7 +367,7 @@
|
||||
<Compile Include="DataMigration\Schema\CreateForeignKeyCommand.cs" />
|
||||
<Compile Include="DataMigration\Schema\DropForeignKeyCommand.cs" />
|
||||
<Compile Include="DataMigration\Schema\DropIndexCommand.cs" />
|
||||
<Compile Include="DataMigration\Schema\CreateIndexCommand.cs" />
|
||||
<Compile Include="DataMigration\Schema\AddIndexCommand.cs" />
|
||||
<Compile Include="DataMigration\Schema\DropColumnCommand.cs" />
|
||||
<Compile Include="DataMigration\Schema\AlterColumnCommand.cs" />
|
||||
<Compile Include="DataMigration\Schema\DropTableCommand.cs" />
|
||||
|
Reference in New Issue
Block a user