Better data migration scaffolding and some unit tests for it

--HG--
branch : dev
This commit is contained in:
Sebastien Ros
2010-07-15 17:46:25 -07:00
parent 4fb3c51dff
commit 6ba6892e39
4 changed files with 250 additions and 11 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using Orchard.Data.Migration.Interpreters;
@@ -16,7 +17,35 @@ namespace Orchard.DevTools.Services {
_output.WriteLine("\t\t\t// Creating table {0}", command.Name);
_output.WriteLine("\t\t\tSchemaBuilder.CreateTable(\"{0}\", table => table", command.Name);
var matchContentPartRecord = command.TableCommands.OfType<CreateColumnCommand>().Any(
c =>
c.IsPrimaryKey
&& c.ColumnName == "Id"
&& !c.IsIdentity
&& c.DbType == DbType.Int32);
var matchContentPartVersionRecord = matchContentPartRecord && command.TableCommands.OfType<CreateColumnCommand>().Any(
c =>
c.ColumnName == "ContentItemRecord_id"
&& c.DbType == DbType.Int32);
if ( matchContentPartVersionRecord ) {
_output.WriteLine("\t\t\t\t.ContentPartVersionRecord()");
}
else if ( matchContentPartRecord ) {
_output.WriteLine("\t\t\t\t.ContentPartRecord()");
}
foreach ( var createColumn in command.TableCommands.OfType<CreateColumnCommand>() ) {
if(createColumn.ColumnName == "Id" && matchContentPartRecord) {
continue;
}
if(createColumn.ColumnName == "ContentItemRecord_id" && matchContentPartVersionRecord) {
continue;
}
var type = createColumn.DbType.ToString();
var field = createColumn.ColumnName;
var options = new List<string>();
@@ -25,6 +54,10 @@ namespace Orchard.DevTools.Services {
options.Add("PrimaryKey()");
}
if ( createColumn.IsIdentity ) {
options.Add("Identity()");
}
if ( createColumn.IsUnique ) {
options.Add("Unique()");
}