mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Adding data migration overloads to do updates based on other module's tables
- e.g. creating a foreign key between tables from two distinct modules, was using the same module prefix --HG-- branch : dev
This commit is contained in:
@@ -189,7 +189,7 @@ namespace Orchard.Data.Migration {
|
||||
.ToList();
|
||||
|
||||
foreach (var migration in migrations.OfType<DataMigrationImpl>()) {
|
||||
migration.SchemaBuilder = new SchemaBuilder(_interpreter, migration.Feature.Descriptor.Name.Replace(".", "_") + "_");
|
||||
migration.SchemaBuilder = new SchemaBuilder(_interpreter, migration.Feature.Descriptor.Name, (s) => s.Replace(".", "_") + "_");
|
||||
migration.ContentDefinitionManager = _contentDefinitionManager;
|
||||
}
|
||||
|
||||
|
@@ -5,28 +5,30 @@ namespace Orchard.Data.Migration.Schema {
|
||||
public class SchemaBuilder {
|
||||
private readonly IDataMigrationInterpreter _interpreter;
|
||||
private readonly string _featurePrefix;
|
||||
private readonly Func<string, string> _formatPrefix;
|
||||
|
||||
public SchemaBuilder(IDataMigrationInterpreter interpreter, string featurePrefix = null) {
|
||||
public SchemaBuilder(IDataMigrationInterpreter interpreter, string featurePrefix = null, Func<string, string> formatPrefix = null) {
|
||||
_interpreter = interpreter;
|
||||
_featurePrefix = featurePrefix;
|
||||
_featurePrefix = featurePrefix ?? String.Empty;
|
||||
_formatPrefix = formatPrefix ?? (s => s ?? String.Empty);
|
||||
}
|
||||
|
||||
public SchemaBuilder CreateTable(string name, Action<CreateTableCommand> table) {
|
||||
var createTable = new CreateTableCommand(String.Concat(_featurePrefix, name));
|
||||
var createTable = new CreateTableCommand(String.Concat(_formatPrefix(_featurePrefix), name));
|
||||
table(createTable);
|
||||
Run(createTable);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SchemaBuilder AlterTable(string name, Action<AlterTableCommand> table) {
|
||||
var alterTable = new AlterTableCommand(String.Concat(_featurePrefix, name));
|
||||
var alterTable = new AlterTableCommand(String.Concat(_formatPrefix(_featurePrefix), name));
|
||||
table(alterTable);
|
||||
Run(alterTable);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SchemaBuilder DropTable(string name) {
|
||||
var deleteTable = new DropTableCommand(String.Concat(_featurePrefix, name));
|
||||
var deleteTable = new DropTableCommand(String.Concat(_formatPrefix(_featurePrefix), name));
|
||||
Run(deleteTable);
|
||||
return this;
|
||||
}
|
||||
@@ -45,13 +47,37 @@ namespace Orchard.Data.Migration.Schema {
|
||||
}
|
||||
|
||||
public SchemaBuilder CreateForeignKey(string name, string srcTable, string[] srcColumns, string destTable, string[] destColumns) {
|
||||
var command = new CreateForeignKeyCommand(name, String.Concat(_featurePrefix, srcTable), srcColumns, String.Concat(_featurePrefix, destTable), destColumns);
|
||||
var command = new CreateForeignKeyCommand(name, String.Concat(_formatPrefix(_featurePrefix), srcTable), srcColumns, String.Concat(_formatPrefix(_featurePrefix), destTable), destColumns);
|
||||
Run(command);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SchemaBuilder CreateForeignKey(string name, string srcModule, string srcTable, string[] srcColumns, string destTable, string[] destColumns) {
|
||||
var command = new CreateForeignKeyCommand(name, String.Concat(_formatPrefix(srcModule), srcTable), srcColumns, String.Concat(_formatPrefix(_featurePrefix), destTable), destColumns);
|
||||
Run(command);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SchemaBuilder CreateForeignKey(string name, string srcTable, string[] srcColumns, string destModule, string destTable, string[] destColumns) {
|
||||
var command = new CreateForeignKeyCommand(name, String.Concat(_formatPrefix(_featurePrefix), srcTable), srcColumns, String.Concat(_formatPrefix(destModule), destTable), destColumns);
|
||||
Run(command);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SchemaBuilder CreateForeignKey(string name, string srcModule, string srcTable, string[] srcColumns, string destModule, string destTable, string[] destColumns) {
|
||||
var command = new CreateForeignKeyCommand(name, String.Concat(_formatPrefix(srcModule), srcTable), srcColumns, String.Concat(_formatPrefix(destModule), destTable), destColumns);
|
||||
Run(command);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SchemaBuilder DropForeignKey(string srcTable, string name) {
|
||||
var command = new DropForeignKeyCommand(String.Concat(_featurePrefix, srcTable), name);
|
||||
var command = new DropForeignKeyCommand(String.Concat(_formatPrefix(_featurePrefix), srcTable), name);
|
||||
Run(command);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SchemaBuilder DropForeignKey(string srcModule, string srcTable, string name) {
|
||||
var command = new DropForeignKeyCommand(String.Concat(_formatPrefix(srcModule), srcTable), name);
|
||||
Run(command);
|
||||
return this;
|
||||
}
|
||||
|
Reference in New Issue
Block a user