mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Better data migration scaffolding and some unit tests for it
--HG-- branch : dev
This commit is contained in:
@@ -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()");
|
||||
}
|
||||
|
Reference in New Issue
Block a user