From 6e94264df235803669774d096a03de95f83c0297 Mon Sep 17 00:00:00 2001 From: qt1 Date: Mon, 1 Jun 2015 02:07:42 +0300 Subject: [PATCH 1/2] Provide full table name prefix for migrations --- .../Utilities/NullInterpreter.cs | 5 +++++ .../DefaultDataMigrationInterpreter.cs | 20 ++++++++++++++++++- .../Interpreters/IDataMigrationInterpreter.cs | 1 + .../Data/Migration/Schema/SchemaBuilder.cs | 7 +++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Orchard.Tests/DataMigration/Utilities/NullInterpreter.cs b/src/Orchard.Tests/DataMigration/Utilities/NullInterpreter.cs index a89772b80..025970a55 100644 --- a/src/Orchard.Tests/DataMigration/Utilities/NullInterpreter.cs +++ b/src/Orchard.Tests/DataMigration/Utilities/NullInterpreter.cs @@ -24,5 +24,10 @@ namespace Orchard.Tests.DataMigration.Utilities { public void Visit(DropForeignKeyCommand command) { } + + public string PrefixTableName(string tableName) { + return tableName; + } + } } \ No newline at end of file diff --git a/src/Orchard/Data/Migration/Interpreters/DefaultDataMigrationInterpreter.cs b/src/Orchard/Data/Migration/Interpreters/DefaultDataMigrationInterpreter.cs index 72f634421..566ef04a8 100644 --- a/src/Orchard/Data/Migration/Interpreters/DefaultDataMigrationInterpreter.cs +++ b/src/Orchard/Data/Migration/Interpreters/DefaultDataMigrationInterpreter.cs @@ -91,7 +91,7 @@ namespace Orchard.Data.Migration.Interpreters { RunPendingStatements(); } - private string PrefixTableName(string tableName) { + public string PrefixTableName(string tableName) { if (string.IsNullOrEmpty(_shellSettings.DataTablePrefix)) return tableName; return _shellSettings.DataTablePrefix + "_" + tableName; @@ -285,6 +285,8 @@ namespace Orchard.Data.Migration.Interpreters { } private void Visit(StringBuilder builder, CreateColumnCommand command) { + bool emitNull = true; + if (ExecuteCustomInterpreter(command)) { return; } @@ -297,8 +299,14 @@ namespace Orchard.Data.Migration.Interpreters { } // append identity if handled +<<<<<<< HEAD if (command.IsIdentity && _dialectLazy.Value.SupportsIdentityColumns) { builder.Append(Space).Append(_dialectLazy.Value.IdentityColumnString); +======= + if (command.IsIdentity && _dialect.SupportsIdentityColumns) { + builder.Append(Space).Append(_dialect.IdentityColumnString); + emitNull = !_dialect.IdentityColumnString.ToLower().Contains("null"); // already defined by identity string +>>>>>>> orchard4ibn/IBN-Labs/SchemaBuilder.TableDbName } // [default value] @@ -307,11 +315,21 @@ namespace Orchard.Data.Migration.Interpreters { } // nullable +<<<<<<< HEAD builder.Append(command.IsNotNull ? " not null" : !command.IsPrimaryKey && !command.IsUnique ? _dialectLazy.Value.NullColumnString : string.Empty); +======= + if (emitNull) { + builder.Append(command.IsNotNull + ? " not null" + : !command.IsPrimaryKey && !command.IsUnique + ? _dialect.NullColumnString + : string.Empty); + } +>>>>>>> orchard4ibn/IBN-Labs/SchemaBuilder.TableDbName // append unique if handled, otherwise at the end of the satement if (command.IsUnique && _dialectLazy.Value.SupportsUnique) { diff --git a/src/Orchard/Data/Migration/Interpreters/IDataMigrationInterpreter.cs b/src/Orchard/Data/Migration/Interpreters/IDataMigrationInterpreter.cs index a2225b12f..81ed48590 100644 --- a/src/Orchard/Data/Migration/Interpreters/IDataMigrationInterpreter.cs +++ b/src/Orchard/Data/Migration/Interpreters/IDataMigrationInterpreter.cs @@ -9,5 +9,6 @@ namespace Orchard.Data.Migration.Interpreters { void Visit(SqlStatementCommand command); void Visit(CreateForeignKeyCommand command); void Visit(DropForeignKeyCommand command); + string PrefixTableName(string tableName); } } diff --git a/src/Orchard/Data/Migration/Schema/SchemaBuilder.cs b/src/Orchard/Data/Migration/Schema/SchemaBuilder.cs index 66dc64287..de5291a61 100644 --- a/src/Orchard/Data/Migration/Schema/SchemaBuilder.cs +++ b/src/Orchard/Data/Migration/Schema/SchemaBuilder.cs @@ -28,6 +28,13 @@ namespace Orchard.Data.Migration.Schema { public Func FormatPrefix { get { return _formatPrefix; } } + + /// + /// Translate Table name into database table name - including prefixes + /// + public virtual string TableDbName(string srcTable) { + return _interpreter.PrefixTableName(String.Concat(FormatPrefix(FeaturePrefix), srcTable)); + } public SchemaBuilder CreateTable(string name, Action table) { var createTable = new CreateTableCommand(String.Concat(_formatPrefix(_featurePrefix), name)); From 5b468b0ce064c63801d6e43580dc3c076772e924 Mon Sep 17 00:00:00 2001 From: qt1 Date: Mon, 1 Jun 2015 03:33:14 +0300 Subject: [PATCH 2/2] remove fix for automatic addition of is null (maybe a different PR) --- .../DefaultDataMigrationInterpreter.cs | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/Orchard/Data/Migration/Interpreters/DefaultDataMigrationInterpreter.cs b/src/Orchard/Data/Migration/Interpreters/DefaultDataMigrationInterpreter.cs index 566ef04a8..bb0da3d20 100644 --- a/src/Orchard/Data/Migration/Interpreters/DefaultDataMigrationInterpreter.cs +++ b/src/Orchard/Data/Migration/Interpreters/DefaultDataMigrationInterpreter.cs @@ -285,8 +285,6 @@ namespace Orchard.Data.Migration.Interpreters { } private void Visit(StringBuilder builder, CreateColumnCommand command) { - bool emitNull = true; - if (ExecuteCustomInterpreter(command)) { return; } @@ -299,14 +297,8 @@ namespace Orchard.Data.Migration.Interpreters { } // append identity if handled -<<<<<<< HEAD if (command.IsIdentity && _dialectLazy.Value.SupportsIdentityColumns) { builder.Append(Space).Append(_dialectLazy.Value.IdentityColumnString); -======= - if (command.IsIdentity && _dialect.SupportsIdentityColumns) { - builder.Append(Space).Append(_dialect.IdentityColumnString); - emitNull = !_dialect.IdentityColumnString.ToLower().Contains("null"); // already defined by identity string ->>>>>>> orchard4ibn/IBN-Labs/SchemaBuilder.TableDbName } // [default value] @@ -315,21 +307,11 @@ namespace Orchard.Data.Migration.Interpreters { } // nullable -<<<<<<< HEAD builder.Append(command.IsNotNull ? " not null" : !command.IsPrimaryKey && !command.IsUnique ? _dialectLazy.Value.NullColumnString : string.Empty); -======= - if (emitNull) { - builder.Append(command.IsNotNull - ? " not null" - : !command.IsPrimaryKey && !command.IsUnique - ? _dialect.NullColumnString - : string.Empty); - } ->>>>>>> orchard4ibn/IBN-Labs/SchemaBuilder.TableDbName // append unique if handled, otherwise at the end of the satement if (command.IsUnique && _dialectLazy.Value.SupportsUnique) {