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