Work on automatic schema creation

--HG--
branch : dev
This commit is contained in:
Sebastien Ros
2010-06-25 15:35:52 -07:00
parent c35369fabc
commit 092fcc869a
9 changed files with 41 additions and 24 deletions

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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);
}
}
}

View File

@@ -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>();
}
}
}

View File

@@ -1,4 +0,0 @@
namespace Orchard.DataMigration {
public interface IDataMigrationCommand {
}
}

View File

@@ -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);
}
}

View File

@@ -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;
}
}

View File

@@ -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);

View File

@@ -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" />