mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-19 10:07:55 +08:00
Work on automatic schema creation
--HG-- branch : dev
This commit is contained in:
@@ -4,7 +4,8 @@ using Orchard.DataMigration.Interpreters;
|
||||
using Orchard.DataMigration.Schema;
|
||||
|
||||
public class NullInterpreter : IDataMigrationInterpreter {
|
||||
public void Visit(SchemaCommand command) {
|
||||
|
||||
public void Visit(ISchemaBuilderCommand command) {
|
||||
}
|
||||
|
||||
public void Visit(CreateTableCommand command) {
|
||||
|
@@ -23,9 +23,7 @@ namespace Orchard.DataMigration {
|
||||
|
||||
public void Install(Feature feature) {
|
||||
var featureName = feature.Descriptor.Name;
|
||||
if ( !_dataMigrationManager.IsFeatureAlreadyInstalled(featureName) ) {
|
||||
_dataMigrationManager.Update(featureName);
|
||||
}
|
||||
_dataMigrationManager.Update(featureName);
|
||||
}
|
||||
|
||||
public void Enable(Feature feature) {
|
||||
|
@@ -9,6 +9,7 @@ using Orchard.DataMigration.Schema;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.State;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Environment.ShellBuilders.Models;
|
||||
|
||||
namespace Orchard.DataMigration {
|
||||
/// <summary>
|
||||
@@ -20,18 +21,21 @@ namespace Orchard.DataMigration {
|
||||
private readonly IDataMigrationGenerator _dataMigrationGenerator;
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
private readonly IDataMigrationInterpreter _interpreter;
|
||||
private readonly ShellBlueprint _shellBlueprint;
|
||||
|
||||
public DataMigrationManager(
|
||||
IEnumerable<IDataMigration> dataMigrations,
|
||||
IRepository<DataMigrationRecord> dataMigrationRepository,
|
||||
IDataMigrationGenerator dataMigrationGenerator,
|
||||
IExtensionManager extensionManager,
|
||||
IDataMigrationInterpreter interpreter) {
|
||||
IDataMigrationInterpreter interpreter,
|
||||
ShellBlueprint shellBlueprint) {
|
||||
_dataMigrations = dataMigrations;
|
||||
_dataMigrationRepository = dataMigrationRepository;
|
||||
_dataMigrationGenerator = dataMigrationGenerator;
|
||||
_extensionManager = extensionManager;
|
||||
_interpreter = interpreter;
|
||||
_shellBlueprint = shellBlueprint;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
@@ -116,8 +120,10 @@ namespace Orchard.DataMigration {
|
||||
current = (int)createMethod.Invoke(migration, new object[0]);
|
||||
}
|
||||
else {
|
||||
var commands = _dataMigrationGenerator.CreateCommands();
|
||||
/// TODO: Execute commands and define current version number
|
||||
var commands = _dataMigrationGenerator.CreateCommands(_shellBlueprint.Records.Where(record => record.Feature.Descriptor.Name == feature));
|
||||
foreach(var command in commands) {
|
||||
_interpreter.Visit(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,10 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentNHibernate.Cfg;
|
||||
using Orchard.Data.Builders;
|
||||
using Orchard.DataMigration.Schema;
|
||||
using Orchard.Environment.ShellBuilders.Models;
|
||||
|
||||
namespace Orchard.DataMigration {
|
||||
public class DefaultDataMigrationGenerator : IDataMigrationGenerator {
|
||||
public IEnumerable<IDataMigrationCommand> CreateCommands() {
|
||||
return Enumerable.Empty<IDataMigrationCommand>();
|
||||
public IEnumerable<ISchemaBuilderCommand> CreateCommands(IEnumerable<RecordBlueprint> records) {
|
||||
|
||||
// use FluentNhibernate generation for this module
|
||||
var persistenceModel = AbstractBuilder.CreatePersistenceModel(records);
|
||||
var configuration = Fluently.Configure().Mappings(m => m.AutoMappings.Add(persistenceModel));
|
||||
|
||||
return Enumerable.Empty<ISchemaBuilderCommand>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +0,0 @@
|
||||
namespace Orchard.DataMigration {
|
||||
public interface IDataMigrationCommand {
|
||||
}
|
||||
}
|
@@ -1,8 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using FluentNHibernate.Cfg;
|
||||
using Orchard.DataMigration.Schema;
|
||||
using Orchard.Environment.ShellBuilders.Models;
|
||||
|
||||
namespace Orchard.DataMigration {
|
||||
// Builds and runs the representative migration create calls
|
||||
public interface IDataMigrationGenerator : IDependency {
|
||||
IEnumerable<IDataMigrationCommand> CreateCommands();
|
||||
IEnumerable<ISchemaBuilderCommand> CreateCommands(IEnumerable<RecordBlueprint> records);
|
||||
}
|
||||
}
|
||||
|
@@ -35,25 +35,30 @@ namespace Orchard.DataMigration.Interpreters {
|
||||
get { return _sqlStatements; }
|
||||
}
|
||||
|
||||
public void Visit(SchemaCommand command) {
|
||||
switch (command.Type) {
|
||||
public void Visit(ISchemaBuilderCommand command) {
|
||||
var schemaCommand = command as SchemaCommand;
|
||||
if (schemaCommand == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ( schemaCommand.Type ) {
|
||||
case SchemaCommandType.CreateTable:
|
||||
Visit((CreateTableCommand)command);
|
||||
Visit((CreateTableCommand)schemaCommand);
|
||||
break;
|
||||
case SchemaCommandType.AlterTable:
|
||||
Visit((AlterTableCommand)command);
|
||||
Visit((AlterTableCommand)schemaCommand);
|
||||
break;
|
||||
case SchemaCommandType.DropTable:
|
||||
Visit((DropTableCommand)command);
|
||||
Visit((DropTableCommand)schemaCommand);
|
||||
break;
|
||||
case SchemaCommandType.SqlStatement:
|
||||
Visit((SqlStatementCommand)command);
|
||||
Visit((SqlStatementCommand)schemaCommand);
|
||||
break;
|
||||
case SchemaCommandType.CreateForeignKey:
|
||||
Visit((CreateForeignKeyCommand)command);
|
||||
Visit((CreateForeignKeyCommand)schemaCommand);
|
||||
break;
|
||||
case SchemaCommandType.DropForeignKey:
|
||||
Visit((DropForeignKeyCommand)command);
|
||||
Visit((DropForeignKeyCommand)schemaCommand);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Orchard.DataMigration.Interpreters {
|
||||
public interface IDataMigrationInterpreter : IDependency{
|
||||
void Visit(SchemaCommand command);
|
||||
void Visit(ISchemaBuilderCommand command);
|
||||
void Visit(CreateTableCommand command);
|
||||
void Visit(DropTableCommand command);
|
||||
void Visit(AlterTableCommand command);
|
||||
|
@@ -376,7 +376,6 @@
|
||||
<Compile Include="DataMigration\Commands\DataMigrationCommands.cs" />
|
||||
<Compile Include="DataMigration\Schema\SchemaBuilder.cs" />
|
||||
<Compile Include="DataMigration\DataMigrationCoordinator.cs" />
|
||||
<Compile Include="DataMigration\IDataMigrationCommand.cs" />
|
||||
<Compile Include="DataMigration\DefaultDataMigrationGenerator.cs" />
|
||||
<Compile Include="DataMigration\IDataMigrationGenerator.cs" />
|
||||
<Compile Include="DataMigration\DataMigration.cs" />
|
||||
|
Reference in New Issue
Block a user