Provide full table name prefix for migrations

This commit is contained in:
qt1
2015-06-01 02:07:42 +03:00
parent 917fd8425f
commit 6e94264df2
4 changed files with 32 additions and 1 deletions

View File

@@ -24,5 +24,10 @@ namespace Orchard.Tests.DataMigration.Utilities {
public void Visit(DropForeignKeyCommand command) {
}
public string PrefixTableName(string tableName) {
return tableName;
}
}
}

View File

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

View File

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

View File

@@ -28,6 +28,13 @@ namespace Orchard.Data.Migration.Schema {
public Func<string, string> FormatPrefix {
get { return _formatPrefix; }
}
/// <summary>
/// Translate Table name into database table name - including prefixes
/// </summary>
public virtual string TableDbName(string srcTable) {
return _interpreter.PrefixTableName(String.Concat(FormatPrefix(FeaturePrefix), srcTable));
}
public SchemaBuilder CreateTable(string name, Action<CreateTableCommand> table) {
var createTable = new CreateTableCommand(String.Concat(_formatPrefix(_featurePrefix), name));