mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-03 20:13:52 +08:00
New command to launch migration on all features; Moved the update command to DatabaseUpdate feature
--HG-- branch : dev
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Orchard.Commands;
|
using Orchard.Commands;
|
||||||
using Orchard.Data.Migration;
|
using Orchard.Data.Migration;
|
||||||
@@ -11,27 +12,29 @@ namespace Orchard.Migrations.Commands {
|
|||||||
[OrchardFeature("Orchard.Migrations")]
|
[OrchardFeature("Orchard.Migrations")]
|
||||||
public class DataMigrationCommands : DefaultOrchardCommandHandler {
|
public class DataMigrationCommands : DefaultOrchardCommandHandler {
|
||||||
private readonly IDataMigrationManager _dataMigrationManager;
|
private readonly IDataMigrationManager _dataMigrationManager;
|
||||||
private readonly IDataMigrationInterpreter _dataMigrationInterpreter;
|
private readonly IExtensionManager _extensionManager;
|
||||||
private readonly ISchemaCommandGenerator _schemaCommandGenerator;
|
|
||||||
|
|
||||||
public DataMigrationCommands(
|
public DataMigrationCommands(
|
||||||
IDataMigrationManager dataMigrationManager,
|
IDataMigrationManager dataMigrationManager,
|
||||||
IDataMigrationInterpreter dataMigrationInterpreter,
|
IExtensionManager extensionManager
|
||||||
ISchemaCommandGenerator schemaCommandGenerator
|
|
||||||
) {
|
) {
|
||||||
_dataMigrationManager = dataMigrationManager;
|
_dataMigrationManager = dataMigrationManager;
|
||||||
_dataMigrationInterpreter = dataMigrationInterpreter;
|
_extensionManager = extensionManager;
|
||||||
_schemaCommandGenerator = schemaCommandGenerator;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[OrchardSwitch]
|
|
||||||
public bool Drop { get; set; }
|
|
||||||
|
|
||||||
[CommandName("upgrade database")]
|
[CommandName("upgrade database")]
|
||||||
[CommandHelp("upgrade database <feature-name> \r\n\t" + "Upgrades or create the database tables for the <feature-name>")]
|
[CommandHelp("upgrade database <feature-name-1> ... <feature-name-n> \r\n\t" + "Upgrades or create the database tables for the <feature-name> or all features if not available")]
|
||||||
public string UpgradeDatabase(string featureName) {
|
public string UpgradeDatabase(params string[] featureNames) {
|
||||||
try {
|
try {
|
||||||
_dataMigrationManager.Update(featureName);
|
IEnumerable<string> features = featureNames.Any()
|
||||||
|
? featureNames
|
||||||
|
: _extensionManager.AvailableExtensions()
|
||||||
|
.SelectMany(ext => ext.Features)
|
||||||
|
.Select(f => f.Name);
|
||||||
|
|
||||||
|
foreach(var feature in features) {
|
||||||
|
_dataMigrationManager.Update(feature);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch ( Exception ex ) {
|
catch ( Exception ex ) {
|
||||||
Context.Output.WriteLine(T("An error occured while upgrading the database: " + ex.Message));
|
Context.Output.WriteLine(T("An error occured while upgrading the database: " + ex.Message));
|
||||||
@@ -40,6 +43,22 @@ namespace Orchard.Migrations.Commands {
|
|||||||
|
|
||||||
return "Database upgraded";
|
return "Database upgraded";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
[OrchardFeature("DatabaseUpdate")]
|
||||||
|
public class DatabaseUpdateCommands : DefaultOrchardCommandHandler {
|
||||||
|
private readonly IDataMigrationInterpreter _dataMigrationInterpreter;
|
||||||
|
private readonly ISchemaCommandGenerator _schemaCommandGenerator;
|
||||||
|
|
||||||
|
[OrchardSwitch]
|
||||||
|
public bool Drop { get; set; }
|
||||||
|
|
||||||
|
public DatabaseUpdateCommands(
|
||||||
|
IDataMigrationInterpreter dataMigrationInterpreter,
|
||||||
|
ISchemaCommandGenerator schemaCommandGenerator
|
||||||
|
) {
|
||||||
|
_dataMigrationInterpreter = dataMigrationInterpreter;
|
||||||
|
_schemaCommandGenerator = schemaCommandGenerator;
|
||||||
|
}
|
||||||
|
|
||||||
[CommandName("update database")]
|
[CommandName("update database")]
|
||||||
[CommandHelp("update database \r\n\t" + "Automatically updates the database schema for the enabled features")]
|
[CommandHelp("update database \r\n\t" + "Automatically updates the database schema for the enabled features")]
|
||||||
|
|||||||
Reference in New Issue
Block a user