Completes: U4-6104 Remove SqlSyntaxContext - quite a large refactor and cleanup since the SqlSyntaxContext was used everywhere :( haven't run tests, etc... yet but the project builds now.

This commit is contained in:
Shannon
2015-02-22 21:36:02 +01:00
parent 693384bdf6
commit 905e58e3b6
261 changed files with 2004 additions and 3669 deletions

View File

@@ -365,7 +365,7 @@ namespace Umbraco.Core
//the database migration objects
MigrationResolver.Current = new MigrationResolver(
ServiceProvider, ProfilingLogger.Logger,
Container, ProfilingLogger.Logger,
() => PluginManager.ResolveTypes<IMigration>());

View File

@@ -35,17 +35,6 @@ namespace Umbraco.Core
private string _providerName;
private DatabaseSchemaResult _result;
[Obsolete("Use the constructor specifying all dependencies instead")]
public DatabaseContext(IDatabaseFactory factory)
: this(factory, LoggerResolver.Current.Logger, new SqlSyntaxProviders(new ISqlSyntaxProvider[]
{
new MySqlSyntaxProvider(LoggerResolver.Current.Logger),
new SqlCeSyntaxProvider(),
new SqlServerSyntaxProvider()
}))
{
}
/// <summary>
/// Default constructor
/// </summary>
@@ -74,7 +63,6 @@ namespace Umbraco.Core
{
_providerName = providerName;
SqlSyntax = sqlSyntax;
SqlSyntaxContext.SqlSyntaxProvider = SqlSyntax;
_factory = factory;
_logger = logger;
_configured = true;
@@ -150,7 +138,7 @@ namespace Umbraco.Core
_providerName = "System.Data.SqlClient";
if (ConfigurationManager.ConnectionStrings[GlobalSettings.UmbracoConnectionName] != null)
{
if (!string.IsNullOrEmpty(ConfigurationManager.ConnectionStrings[GlobalSettings.UmbracoConnectionName].ProviderName))
if (string.IsNullOrEmpty(ConfigurationManager.ConnectionStrings[GlobalSettings.UmbracoConnectionName].ProviderName) == false)
_providerName = ConfigurationManager.ConnectionStrings[GlobalSettings.UmbracoConnectionName].ProviderName;
}
else
@@ -458,8 +446,6 @@ namespace Umbraco.Core
throw new InvalidOperationException("No " + typeof(ISqlSyntaxProvider) + " specified or no " + typeof(SqlSyntaxProviders) + " instance specified");
}
SqlSyntaxContext.SqlSyntaxProvider = SqlSyntax;
_configured = true;
}
catch (Exception e)
@@ -523,7 +509,7 @@ namespace Umbraco.Core
internal DatabaseSchemaResult ValidateDatabaseSchema()
{
if (_configured == false || (string.IsNullOrEmpty(_connectionString) || string.IsNullOrEmpty(ProviderName)))
return new DatabaseSchemaResult();
return new DatabaseSchemaResult(SqlSyntax);
if (_result == null)
{
@@ -583,7 +569,8 @@ namespace Umbraco.Core
//If Configuration Status is empty and the determined version is "empty" its a new install - otherwise upgrade the existing
if (string.IsNullOrEmpty(GlobalSettings.ConfigurationStatus) && installedVersion.Equals(new Version(0, 0, 0)))
{
database.CreateDatabaseSchema();
var schemaHelper = new DatabaseSchemaHelper(database, _logger, SqlSyntax);
schemaHelper.CreateDatabaseSchema();
message = message + "<p>Installation completed!</p>";
//now that everything is done, we need to determine the version of SQL server that is executing
@@ -640,7 +627,7 @@ namespace Umbraco.Core
: new Version(GlobalSettings.ConfigurationStatus);
var targetVersion = UmbracoVersion.Current;
var runner = new MigrationRunner(_logger, currentVersion, targetVersion, GlobalSettings.UmbracoMigrationName);
var upgraded = runner.Execute(database, true);
var upgraded = runner.Execute(database, DatabaseProvider, SqlSyntax, true);
message = message + "<p>Upgrade completed!</p>";
//now that everything is done, we need to determine the version of SQL server that is executing

View File

@@ -9,7 +9,7 @@ namespace Umbraco.Core.Persistence.DatabaseModelDefinitions
{
internal static class DefinitionFactory
{
public static TableDefinition GetTableDefinition(Type modelType)
public static TableDefinition GetTableDefinition(Type modelType, ISqlSyntaxProvider sqlSyntax)
{
//Looks for PetaPoco's TableNameAtribute for the name of the table
//If no attribute is set we use the name of the Type as the default convention
@@ -32,7 +32,7 @@ namespace Umbraco.Core.Persistence.DatabaseModelDefinitions
//Otherwise use the name of the property itself as the default convention
var columnAttribute = propertyInfo.FirstAttribute<ColumnAttribute>();
string columnName = columnAttribute != null ? columnAttribute.Name : propertyInfo.Name;
var columnDefinition = GetColumnDefinition(modelType, propertyInfo, columnName, tableName);
var columnDefinition = GetColumnDefinition(modelType, propertyInfo, columnName, tableName, sqlSyntax);
tableDefinition.Columns.Add(columnDefinition);
//Creates a foreignkey definition and adds it to the collection on the table definition
@@ -58,7 +58,7 @@ namespace Umbraco.Core.Persistence.DatabaseModelDefinitions
return tableDefinition;
}
public static ColumnDefinition GetColumnDefinition(Type modelType, PropertyInfo propertyInfo, string columnName, string tableName)
public static ColumnDefinition GetColumnDefinition(Type modelType, PropertyInfo propertyInfo, string columnName, string tableName, ISqlSyntaxProvider sqlSyntax)
{
var definition = new ColumnDefinition{ Name = columnName, TableName = tableName, ModificationType = ModificationType.Create };
@@ -110,7 +110,7 @@ namespace Umbraco.Core.Persistence.DatabaseModelDefinitions
{
//Special case for MySQL as it can't have multiple default DateTime values, which
//is what the umbracoServer table definition is trying to create
if (SqlSyntaxContext.SqlSyntaxProvider is MySqlSyntaxProvider && definition.TableName == "umbracoServer" &&
if (sqlSyntax is MySqlSyntaxProvider && definition.TableName == "umbracoServer" &&
definition.TableName.ToLowerInvariant() == "lastNotifiedDate".ToLowerInvariant())
return definition;

View File

@@ -37,41 +37,13 @@ namespace Umbraco.Core.Persistence
/// <summary>
/// Creates the Umbraco db schema in the Database of the current Database.
/// Safe method that is only able to create the schema in non-configured
/// umbraco instances.
/// </summary>
public void CreateDatabaseSchema(ApplicationContext applicationContext)
public void CreateDatabaseSchema()
{
if (applicationContext == null) throw new ArgumentNullException("applicationContext");
CreateDatabaseSchema(true, applicationContext);
}
/// <summary>
/// Creates the Umbraco db schema in the Database of the current Database
/// with the option to guard the db from having the schema created
/// multiple times.
/// </summary>
/// <param name="guardConfiguration"></param>
/// <param name="applicationContext"></param>
public void CreateDatabaseSchema(bool guardConfiguration, ApplicationContext applicationContext)
{
if (applicationContext == null) throw new ArgumentNullException("applicationContext");
if (guardConfiguration && applicationContext.IsConfigured)
throw new Exception("Umbraco is already configured!");
CreateDatabaseSchemaDo();
}
internal void CreateDatabaseSchemaDo(bool guardConfiguration, ApplicationContext applicationContext)
{
if (guardConfiguration && applicationContext.IsConfigured)
throw new Exception("Umbraco is already configured!");
CreateDatabaseSchemaDo();
}
internal void CreateDatabaseSchemaDo()
private void CreateDatabaseSchemaDo()
{
_logger.Info<Database>("Initializing database schema creation");
@@ -97,7 +69,7 @@ namespace Umbraco.Core.Persistence
public void CreateTable(bool overwrite, Type modelType)
{
var tableDefinition = DefinitionFactory.GetTableDefinition(modelType);
var tableDefinition = DefinitionFactory.GetTableDefinition(modelType, _syntaxProvider);
var tableName = tableDefinition.Name;
string createSql = _syntaxProvider.Format(tableDefinition);
@@ -105,10 +77,10 @@ namespace Umbraco.Core.Persistence
var foreignSql = _syntaxProvider.Format(tableDefinition.ForeignKeys);
var indexSql = _syntaxProvider.Format(tableDefinition.Indexes);
var tableExist = _db.TableExist(tableName);
var tableExist = TableExist(tableName);
if (overwrite && tableExist)
{
_db.DropTable(tableName);
DropTable(tableName);
tableExist = false;
}

View File

@@ -8,10 +8,25 @@ namespace Umbraco.Core.Persistence.Mappers
{
public abstract class BaseMapper
{
private readonly ISqlSyntaxProvider _sqlSyntax;
protected BaseMapper(ISqlSyntaxProvider sqlSyntax)
{
_sqlSyntax = sqlSyntax;
}
internal abstract ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache { get; }
internal abstract void BuildMap();
private bool _built = false;
public void Build()
{
if (_built) return;
_built = true;
BuildMap();
}
protected abstract void BuildMap();
internal string Map(string propertyName, bool throws = false)
{
@@ -58,8 +73,8 @@ namespace Umbraco.Core.Persistence.Mappers
string columnName = columnAttribute.Name;
string columnMap = string.Format("{0}.{1}",
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName(tableName),
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumnName(columnName));
_sqlSyntax.GetQuotedTableName(tableName),
_sqlSyntax.GetQuotedColumnName(columnName));
return columnMap;
}
}

View File

@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
using System.Linq.Expressions;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -16,21 +17,19 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public ContentMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public ContentMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
if(PropertyInfoCache.IsEmpty)
{

View File

@@ -1,6 +1,7 @@
using System.Collections.Concurrent;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -14,21 +15,19 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public ContentTypeMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public ContentTypeMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
if (PropertyInfoCache.IsEmpty)
{

View File

@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
using System.Linq.Expressions;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -16,21 +17,19 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public DataTypeDefinitionMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public DataTypeDefinitionMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
CacheMap<DataTypeDefinition, NodeDto>(src => src.Id, dto => dto.NodeId);
CacheMap<DataTypeDefinition, NodeDto>(src => src.CreateDate, dto => dto.CreateDate);

View File

@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
using System.Linq.Expressions;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -16,21 +17,19 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public DictionaryMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public DictionaryMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
CacheMap<DictionaryItem, DictionaryDto>(src => src.Id, dto => dto.PrimaryKey);
CacheMap<DictionaryItem, DictionaryDto>(src => src.Key, dto => dto.UniqueId);

View File

@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
using System.Linq.Expressions;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -16,21 +17,19 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public DictionaryTranslationMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public DictionaryTranslationMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
CacheMap<DictionaryTranslation, LanguageTextDto>(src => src.Id, dto => dto.PrimaryKey);
CacheMap<DictionaryTranslation, LanguageTextDto>(src => src.Key, dto => dto.UniqueId);

View File

@@ -1,6 +1,7 @@
using System.Collections.Concurrent;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -9,9 +10,9 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
public DomainMapper()
public DomainMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
BuildMap();
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
@@ -19,7 +20,7 @@ namespace Umbraco.Core.Persistence.Mappers
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
CacheMap<DomainRepository.CacheableDomain, DomainDto>(src => src.Id, dto => dto.Id);
CacheMap<DomainRepository.CacheableDomain, DomainDto>(src => src.RootContentId, dto => dto.RootStructureId);

View File

@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
using System.Linq.Expressions;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -16,19 +17,19 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
public LanguageMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public LanguageMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
CacheMap<Language, LanguageDto>(src => src.Id, dto => dto.Id);
CacheMap<Language, LanguageDto>(src => src.IsoCode, dto => dto.IsoCode);

View File

@@ -1,6 +1,7 @@
using System.Collections.Concurrent;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -10,21 +11,20 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public MacroMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public MacroMapper(ISqlSyntaxProvider sqlSyntax)
: base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
CacheMap<Macro, MacroDto>(src => src.Id, dto => dto.Id);
CacheMap<Macro, MacroDto>(src => src.Alias, dto => dto.Alias);

View File

@@ -42,6 +42,8 @@ namespace Umbraco.Core.Persistence.Mappers
var byAttribute = TryGetMapperByAttribute(type);
if (byAttribute.Success)
{
//ensure it's built
byAttribute.Result.Build();
return byAttribute.Result;
}
throw new Exception("Invalid Type: A Mapper could not be resolved based on the passed in Type");
@@ -65,6 +67,9 @@ namespace Umbraco.Core.Persistence.Mappers
return Attempt<BaseMapper>.Fail();
}
//ensure it's built
mapper.Build();
return Attempt<BaseMapper>.Succeed(mapper);
}

View File

@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
using System.Linq.Expressions;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -16,21 +17,18 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public MediaMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public MediaMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
if (PropertyInfoCache.IsEmpty)
{

View File

@@ -1,6 +1,7 @@
using System.Collections.Concurrent;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -14,21 +15,19 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public MediaTypeMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public MediaTypeMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
if (PropertyInfoCache.IsEmpty)
{

View File

@@ -1,6 +1,7 @@
using System.Collections.Concurrent;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -10,11 +11,9 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public MemberGroupMapper()
public MemberGroupMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
BuildMap();
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
@@ -22,7 +21,7 @@ namespace Umbraco.Core.Persistence.Mappers
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
CacheMap<MemberGroup, NodeDto>(src => src.Id, dto => dto.NodeId);
CacheMap<MemberGroup, NodeDto>(src => src.CreateDate, dto => dto.CreateDate);

View File

@@ -2,6 +2,7 @@
using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -15,21 +16,18 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public MemberMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public MemberMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
CacheMap<Member, NodeDto>(src => src.Id, dto => dto.NodeId);
CacheMap<Member, NodeDto>(src => src.CreateDate, dto => dto.CreateDate);

View File

@@ -1,6 +1,7 @@
using System.Collections.Concurrent;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -15,21 +16,18 @@ namespace Umbraco.Core.Persistence.Mappers
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance =
new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public MemberTypeMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public MemberTypeMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
if (PropertyInfoCache.IsEmpty)
{

View File

@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
using System.Linq.Expressions;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -15,21 +16,19 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public PropertyGroupMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public PropertyGroupMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
CacheMap<PropertyGroup, PropertyTypeGroupDto>(src => src.Id, dto => dto.Id);
CacheMap<PropertyGroup, PropertyTypeGroupDto>(src => src.ParentId, dto => dto.ParentGroupId);

View File

@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
using System.Linq.Expressions;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -11,27 +12,22 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public PropertyMapper()
public PropertyMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
BuildMap();
}
#region Overrides of BaseMapper
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
CacheMap<Property, PropertyDataDto>(src => src.Id, dto => dto.Id);
CacheMap<Property, PropertyDataDto>(src => src.Version, dto => dto.VersionId);
CacheMap<Property, PropertyDataDto>(src => src.PropertyTypeId, dto => dto.PropertyTypeId);
}
#endregion
}
}

View File

@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
using System.Linq.Expressions;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -15,21 +16,18 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public PropertyTypeMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public PropertyTypeMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
if(PropertyInfoCache.IsEmpty)
{

View File

@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
using System.Linq.Expressions;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -16,21 +17,18 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public RelationMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public RelationMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
CacheMap<Relation, RelationDto>(src => src.Id, dto => dto.Id);
CacheMap<Relation, RelationDto>(src => src.ChildId, dto => dto.ChildId);

View File

@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
using System.Linq.Expressions;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -16,21 +17,18 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public RelationTypeMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public RelationTypeMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
CacheMap<RelationType, RelationTypeDto>(src => src.Id, dto => dto.Id);
CacheMap<RelationType, RelationTypeDto>(src => src.Alias, dto => dto.Alias);

View File

@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
using System.Linq.Expressions;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -11,21 +12,19 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public ServerRegistrationMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public ServerRegistrationMapper(ISqlSyntaxProvider sqlSyntax)
: base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
CacheMap<ServerRegistration, ServerRegistrationDto>(src => src.Id, dto => dto.Id);
CacheMap<ServerRegistration, ServerRegistrationDto>(src => src.IsActive, dto => dto.IsActive);

View File

@@ -1,6 +1,7 @@
using System.Collections.Concurrent;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -14,21 +15,19 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public TagMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public TagMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
if (PropertyInfoCache.IsEmpty)
{

View File

@@ -6,6 +6,7 @@ using System.Text;
using System.Threading.Tasks;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -19,21 +20,19 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public TemplateMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public TemplateMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
if(PropertyInfoCache.IsEmpty)
{

View File

@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
using System.Linq.Expressions;
using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -11,21 +12,19 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public UmbracoEntityMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public UmbracoEntityMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
CacheMap<IUmbracoEntity, NodeDto>(src => src.Id, dto => dto.NodeId);
CacheMap<IUmbracoEntity, NodeDto>(src => src.CreateDate, dto => dto.CreateDate);

View File

@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
using System.Linq.Expressions;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -12,21 +13,19 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public UserMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public UserMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
CacheMap<User, UserDto>(src => src.Id, dto => dto.Id);
CacheMap<User, UserDto>(src => src.Email, dto => dto.Email);

View File

@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
using System.Linq.Expressions;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Mappers
{
@@ -16,21 +17,18 @@ namespace Umbraco.Core.Persistence.Mappers
{
private static readonly ConcurrentDictionary<string, DtoMapModel> PropertyInfoCacheInstance = new ConcurrentDictionary<string, DtoMapModel>();
//NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it
// otherwise that would fail because there is no public constructor.
public UserTypeMapper()
{
BuildMap();
}
#region Overrides of BaseMapper
public UserTypeMapper(ISqlSyntaxProvider sqlSyntax) : base(sqlSyntax)
{
}
internal override ConcurrentDictionary<string, DtoMapModel> PropertyInfoCache
{
get { return PropertyInfoCacheInstance; }
}
internal override void BuildMap()
protected override void BuildMap()
{
CacheMap<UserType, UserTypeDto>(src => src.Id, dto => dto.Id);
CacheMap<UserType, UserTypeDto>(src => src.Alias, dto => dto.Alias);

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations
{
@@ -7,5 +8,6 @@ namespace Umbraco.Core.Persistence.Migrations
ICollection<IMigrationExpression> Expressions { get; set; }
DatabaseProviders CurrentDatabaseProvider { get; }
Database Database { get; }
ISqlSyntaxProvider SqlSyntax { get; }
}
}

View File

@@ -142,7 +142,7 @@ namespace Umbraco.Core.Persistence.Migrations.Initial
/// </summary>
public DatabaseSchemaResult ValidateSchema()
{
var result = new DatabaseSchemaResult();
var result = new DatabaseSchemaResult(_sqlSyntaxProvider);
//get the db index defs
result.DbIndexDefinitions = _sqlSyntaxProvider.GetDefinedIndexes(_database)
@@ -156,7 +156,7 @@ namespace Umbraco.Core.Persistence.Migrations.Initial
foreach (var item in OrderedTables.OrderBy(x => x.Key))
{
var tableDefinition = DefinitionFactory.GetTableDefinition(item.Value);
var tableDefinition = DefinitionFactory.GetTableDefinition(item.Value, _sqlSyntaxProvider);
result.TableDefinitions.Add(tableDefinition);
}

View File

@@ -10,8 +10,11 @@ namespace Umbraco.Core.Persistence.Migrations.Initial
{
public class DatabaseSchemaResult
{
public DatabaseSchemaResult()
private readonly ISqlSyntaxProvider _sqlSyntax;
public DatabaseSchemaResult(ISqlSyntaxProvider sqlSyntax)
{
_sqlSyntax = sqlSyntax;
Errors = new List<Tuple<string, string>>();
TableDefinitions = new List<TableDefinition>();
ValidTables = new List<string>();
@@ -150,7 +153,7 @@ namespace Umbraco.Core.Persistence.Migrations.Initial
sb.AppendLine(" ");
}
if (SqlSyntaxContext.SqlSyntaxProvider is MySqlSyntaxProvider)
if (_sqlSyntax is MySqlSyntaxProvider)
{
sb.AppendLine("Please note that the constraints could not be validated because the current dataprovider is MySql.");
}

View File

@@ -17,12 +17,6 @@ namespace Umbraco.Core.Persistence.Migrations
public ISqlSyntaxProvider SqlSyntax { get; private set; }
public ILogger Logger { get; private set; }
[Obsolete("Use the other constructor specifying all dependencies instead")]
protected MigrationBase()
: this(SqlSyntaxContext.SqlSyntaxProvider, LoggerResolver.Current.Logger)
{
}
protected MigrationBase(ISqlSyntaxProvider sqlSyntax, ILogger logger)
{
SqlSyntax = sqlSyntax;
@@ -53,12 +47,12 @@ namespace Umbraco.Core.Persistence.Migrations
public ICreateBuilder Create
{
get { return new CreateBuilder(Context, SqlSyntax); }
get { return new CreateBuilder(Context); }
}
public IDeleteBuilder Delete
{
get { return new DeleteBuilder(Context, SqlSyntax); }
get { return new DeleteBuilder(Context); }
}
public IExecuteBuilder Execute

View File

@@ -1,17 +1,24 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations
{
internal class MigrationContext : IMigrationContext
{
public MigrationContext(DatabaseProviders databaseProvider, Database database, ILogger logger)
public MigrationContext(DatabaseProviders databaseProvider, Database database, ILogger logger, ISqlSyntaxProvider sqlSyntax)
{
if (database == null) throw new ArgumentNullException("database");
if (logger == null) throw new ArgumentNullException("logger");
if (sqlSyntax == null) throw new ArgumentNullException("sqlSyntax");
Expressions = new Collection<IMigrationExpression>();
CurrentDatabaseProvider = databaseProvider;
Database = database;
Logger = logger;
SqlSyntax = sqlSyntax;
}
public ICollection<IMigrationExpression> Expressions { get; set; }
@@ -20,6 +27,8 @@ namespace Umbraco.Core.Persistence.Migrations
public Database Database { get; private set; }
public ISqlSyntaxProvider SqlSyntax { get; private set; }
public ILogger Logger { get; private set; }
}
}

View File

@@ -7,28 +7,17 @@ namespace Umbraco.Core.Persistence.Migrations
{
public abstract class MigrationExpressionBase : IMigrationExpression
{
[Obsolete("Use the other constructors specifying an ISqlSyntaxProvider instead")]
protected MigrationExpressionBase()
: this(SqlSyntaxContext.SqlSyntaxProvider)
{
}
[Obsolete("Use the other constructors specifying an ISqlSyntaxProvider instead")]
protected MigrationExpressionBase(DatabaseProviders current, DatabaseProviders[] databaseProviders)
: this(current, databaseProviders, SqlSyntaxContext.SqlSyntaxProvider)
{
}
//protected MigrationExpressionBase(ISqlSyntaxProvider sqlSyntax)
//{
// SqlSyntax = sqlSyntax;
//}
protected MigrationExpressionBase(ISqlSyntaxProvider sqlSyntax)
protected MigrationExpressionBase(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, DatabaseProviders[] supportedDatabaseProviders = null)
{
SupportedDatabaseProviders = supportedDatabaseProviders;
SqlSyntax = sqlSyntax;
}
protected MigrationExpressionBase(DatabaseProviders current, DatabaseProviders[] databaseProviders, ISqlSyntaxProvider sqlSyntax)
{
SupportedDatabaseProviders = databaseProviders;
SqlSyntax = sqlSyntax;
CurrentDatabaseProvider = current;
CurrentDatabaseProvider = currentDatabaseProvider;
}
public virtual DatabaseProviders[] SupportedDatabaseProviders { get; private set; }

View File

@@ -1,36 +1,29 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.LightInject;
using Umbraco.Core.Logging;
using Umbraco.Core.ObjectResolution;
namespace Umbraco.Core.Persistence.Migrations
{
/// <summary>
/// A resolver to return all IMigrations
/// </summary>
internal class MigrationResolver : LazyManyObjectsResolverBase<MigrationResolver, IMigration>
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="serviceProvider"></param>
/// <param name="logger"></param>
/// <param name="migrations"></param>
/// <remarks>
/// Use transient objects as we don't want these as singletons and take up memory that is not required
/// </remarks>
public MigrationResolver(IServiceProvider serviceProvider, ILogger logger, Func<IEnumerable<Type>> migrations)
: base(serviceProvider, logger, migrations, ObjectLifetimeScope.Transient)
{
}
/// <summary>
/// A resolver to return all IMigrations
/// </summary>
internal class MigrationResolver : ContainerLazyManyObjectsResolver<MigrationResolver, IMigration>
{
/// <summary>
/// Gets the migrations
/// </summary>
public IEnumerable<IMigration> Migrations
{
get { return Values; }
}
public MigrationResolver(IServiceContainer container, ILogger logger, Func<IEnumerable<Type>> migrations)
: base(container, logger, migrations, ObjectLifetimeScope.Transient)
{
}
}
/// <summary>
/// Gets the migrations
/// </summary>
public IEnumerable<IMigration> Migrations
{
get { return Values; }
}
}
}

View File

@@ -4,6 +4,7 @@ using System.Linq;
using Umbraco.Core.Events;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.Migrations.Syntax.IfDatabase;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations
{
@@ -18,11 +19,6 @@ namespace Umbraco.Core.Persistence.Migrations
private readonly Version _targetVersion;
private readonly string _productName;
[Obsolete("Use the ctor that specifies all dependencies instead")]
public MigrationRunner(Version currentVersion, Version targetVersion, string productName)
: this(LoggerResolver.Current.Logger, currentVersion, targetVersion, productName)
{
}
public MigrationRunner(ILogger logger, Version currentVersion, Version targetVersion, string productName)
{
@@ -37,25 +33,16 @@ namespace Umbraco.Core.Persistence.Migrations
_productName = productName;
}
/// <summary>
/// Executes the migrations against the database.
/// </summary>
/// <param name="database">The PetaPoco Database, which the migrations will be run against</param>
/// <param name="isUpgrade">Boolean indicating whether this is an upgrade or downgrade</param>
/// <returns><c>True</c> if migrations were applied, otherwise <c>False</c></returns>
public virtual bool Execute(Database database, bool isUpgrade = true)
{
return Execute(database, database.GetDatabaseProvider(), isUpgrade);
}
/// <summary>
/// Executes the migrations against the database.
/// </summary>
/// <param name="database">The PetaPoco Database, which the migrations will be run against</param>
/// <param name="databaseProvider"></param>
/// <param name="sqlSyntaxProvider"></param>
/// <param name="isUpgrade">Boolean indicating whether this is an upgrade or downgrade</param>
/// <returns><c>True</c> if migrations were applied, otherwise <c>False</c></returns>
public virtual bool Execute(Database database, DatabaseProviders databaseProvider, bool isUpgrade = true)
public virtual bool Execute(Database database, DatabaseProviders databaseProvider, ISqlSyntaxProvider sqlSyntaxProvider, bool isUpgrade = true)
{
_logger.Info<MigrationRunner>("Initializing database migrations");
@@ -72,7 +59,7 @@ namespace Umbraco.Core.Persistence.Migrations
return false;
//Loop through migrations to generate sql
var migrationContext = InitializeMigrations(migrations, database, databaseProvider, isUpgrade);
var migrationContext = InitializeMigrations(migrations, database, databaseProvider, sqlSyntaxProvider, isUpgrade);
try
{
@@ -152,10 +139,15 @@ namespace Umbraco.Core.Persistence.Migrations
return MigrationResolver.Current.Migrations.ToArray();
}
internal MigrationContext InitializeMigrations(List<IMigration> migrations, Database database, DatabaseProviders databaseProvider, bool isUpgrade = true)
internal MigrationContext InitializeMigrations(
List<IMigration> migrations,
Database database,
DatabaseProviders databaseProvider,
ISqlSyntaxProvider sqlSyntax,
bool isUpgrade = true)
{
//Loop through migrations to generate sql
var context = new MigrationContext(databaseProvider, database, _logger);
var context = new MigrationContext(databaseProvider, database, _logger, sqlSyntax);
foreach (var migration in migrations)
{

View File

@@ -15,14 +15,14 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter
public IAlterTableSyntax Table(string tableName)
{
var expression = new AlterTableExpression { TableName = tableName };
var expression = new AlterTableExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider) { TableName = tableName };
//_context.Expressions.Add(expression);
return new AlterTableBuilder(expression, _context);
}
public IAlterColumnSyntax Column(string columnName)
{
var expression = new AlterColumnExpression { Column = { Name = columnName } };
var expression = new AlterColumnExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider) { Column = { Name = columnName } };
//_context.Expressions.Add(expression);
return new AlterColumnBuilder(expression, _context);
}

View File

@@ -33,7 +33,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Column
public IAlterColumnOptionSyntax WithDefault(SystemMethods method)
{
var dc = new AlterDefaultConstraintExpression
var dc = new AlterDefaultConstraintExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
TableName = Expression.TableName,
SchemaName = Expression.SchemaName,
@@ -51,7 +51,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Column
public IAlterColumnOptionSyntax WithDefaultValue(object value)
{
var dc = new AlterDefaultConstraintExpression
var dc = new AlterDefaultConstraintExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
TableName = Expression.TableName,
SchemaName = Expression.SchemaName,
@@ -81,7 +81,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Column
{
Expression.Column.IsIndexed = true;
var index = new CreateIndexExpression
var index = new CreateIndexExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
Index = new IndexDefinition
{
@@ -135,7 +135,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Column
{
Expression.Column.IsUnique = true;
var index = new CreateIndexExpression
var index = new CreateIndexExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
Index = new IndexDefinition
{
@@ -172,7 +172,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Column
{
Expression.Column.IsForeignKey = true;
var fk = new CreateForeignKeyExpression
var fk = new CreateForeignKeyExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
ForeignKey = new ForeignKeyDefinition
{
@@ -212,7 +212,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Column
public IAlterColumnOptionForeignKeyCascadeSyntax ReferencedBy(string foreignKeyName, string foreignTableSchema,
string foreignTableName, string foreignColumnName)
{
var fk = new CreateForeignKeyExpression
var fk = new CreateForeignKeyExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
ForeignKey = new ForeignKeyDefinition
{

View File

@@ -6,32 +6,12 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Expressions
{
public class AlterColumnExpression : MigrationExpressionBase
{
public AlterColumnExpression(ISqlSyntaxProvider sqlSyntax)
: base(sqlSyntax)
public AlterColumnExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, DatabaseProviders[] supportedDatabaseProviders = null)
: base(sqlSyntax, currentDatabaseProvider, supportedDatabaseProviders)
{
Column = new ColumnDefinition() { ModificationType = ModificationType.Alter };
}
public AlterColumnExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders, ISqlSyntaxProvider sqlSyntax)
: base(current, databaseProviders, sqlSyntax)
{
Column = new ColumnDefinition() { ModificationType = ModificationType.Alter };
}
[Obsolete("Use the constructor specifying an ISqlSyntaxProvider instead")]
public AlterColumnExpression()
: this(SqlSyntaxContext.SqlSyntaxProvider)
{
}
[Obsolete("Use the constructor specifying an ISqlSyntaxProvider instead")]
public AlterColumnExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders)
: this(current, databaseProviders, SqlSyntaxContext.SqlSyntaxProvider)
{
}
public virtual string SchemaName { get; set; }
public virtual string TableName { get; set; }
public virtual ColumnDefinition Column { get; set; }
@@ -42,9 +22,10 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Expressions
// SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumnName(Column.Name),
// SqlSyntaxContext.SqlSyntaxProvider.Format(Column));
return string.Format(SqlSyntaxContext.SqlSyntaxProvider.AlterColumn,
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName(TableName),
SqlSyntaxContext.SqlSyntaxProvider.Format(Column));
return string.Format(
SqlSyntax.AlterColumn,
SqlSyntax.GetQuotedTableName(TableName),
SqlSyntax.Format(Column));
//return string.Format(SqlSyntaxContext.SqlSyntaxProvider.AlterColumn,
// SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName(TableName),

View File

@@ -4,11 +4,8 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Expressions
{
public class AlterDefaultConstraintExpression : MigrationExpressionBase
{
public AlterDefaultConstraintExpression()
{
}
public AlterDefaultConstraintExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders) : base(current, databaseProviders)
public AlterDefaultConstraintExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, DatabaseProviders[] supportedDatabaseProviders = null)
: base(sqlSyntax, currentDatabaseProvider, supportedDatabaseProviders)
{
}
@@ -22,9 +19,9 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Expressions
{
//NOTE Should probably investigate if Deleting a Default Constraint is different from deleting a 'regular' constraint
return string.Format(SqlSyntaxContext.SqlSyntaxProvider.DeleteConstraint,
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName(TableName),
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedName(ConstraintName));
return string.Format(SqlSyntax.DeleteConstraint,
SqlSyntax.GetQuotedTableName(TableName),
SqlSyntax.GetQuotedName(ConstraintName));
}
}
}

View File

@@ -1,12 +1,11 @@
namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Expressions
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Expressions
{
public class AlterTableExpression : MigrationExpressionBase
{
public AlterTableExpression()
{
}
public AlterTableExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders) : base(current, databaseProviders)
public AlterTableExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, DatabaseProviders[] supportedDatabaseProviders = null)
: base(sqlSyntax, currentDatabaseProvider, supportedDatabaseProviders)
{
}

View File

@@ -36,7 +36,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Table
{
if (CurrentColumn.ModificationType == ModificationType.Alter)
{
var dc = new AlterDefaultConstraintExpression
var dc = new AlterDefaultConstraintExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
TableName = Expression.TableName,
SchemaName = Expression.SchemaName,
@@ -66,7 +66,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Table
{
CurrentColumn.IsIndexed = true;
var index = new CreateIndexExpression
var index = new CreateIndexExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
Index = new IndexDefinition
{
@@ -120,7 +120,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Table
{
CurrentColumn.IsUnique = true;
var index = new CreateIndexExpression
var index = new CreateIndexExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
Index = new IndexDefinition
{
@@ -157,7 +157,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Table
{
CurrentColumn.IsForeignKey = true;
var fk = new CreateForeignKeyExpression
var fk = new CreateForeignKeyExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
ForeignKey = new ForeignKeyDefinition
{
@@ -197,7 +197,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Table
public IAlterTableColumnOptionForeignKeyCascadeSyntax ReferencedBy(string foreignKeyName, string foreignTableSchema,
string foreignTableName, string foreignColumnName)
{
var fk = new CreateForeignKeyExpression
var fk = new CreateForeignKeyExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
ForeignKey = new ForeignKeyDefinition
{
@@ -220,7 +220,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Table
public IAlterTableColumnTypeSyntax AddColumn(string name)
{
var column = new ColumnDefinition { Name = name, ModificationType = ModificationType.Create };
var createColumn = new CreateColumnExpression
var createColumn = new CreateColumnExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
Column = column,
SchemaName = Expression.SchemaName,
@@ -236,7 +236,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Alter.Table
public IAlterTableColumnTypeSyntax AlterColumn(string name)
{
var column = new ColumnDefinition { Name = name, ModificationType = ModificationType.Alter };
var alterColumn = new AlterColumnExpression
var alterColumn = new AlterColumnExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
Column = column,
SchemaName = Expression.SchemaName,

View File

@@ -56,7 +56,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create.Column
{
Expression.Column.IsIndexed = true;
var index = new CreateIndexExpression
var index = new CreateIndexExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
Index = new IndexDefinition
{
@@ -110,7 +110,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create.Column
{
Expression.Column.IsUnique = true;
var index = new CreateIndexExpression
var index = new CreateIndexExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
Index = new IndexDefinition
{
@@ -147,7 +147,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create.Column
{
Expression.Column.IsForeignKey = true;
var fk = new CreateForeignKeyExpression
var fk = new CreateForeignKeyExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
ForeignKey = new ForeignKeyDefinition
{
@@ -187,7 +187,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create.Column
public ICreateColumnOptionForeignKeyCascadeSyntax ReferencedBy(string foreignKeyName, string foreignTableSchema,
string foreignTableName, string foreignColumnName)
{
var fk = new CreateForeignKeyExpression
var fk = new CreateForeignKeyExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
ForeignKey = new ForeignKeyDefinition
{

View File

@@ -14,80 +14,78 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create
public class CreateBuilder : ICreateBuilder
{
private readonly IMigrationContext _context;
private readonly ISqlSyntaxProvider _sqlSyntax;
private readonly DatabaseProviders[] _databaseProviders;
public CreateBuilder(IMigrationContext context, ISqlSyntaxProvider sqlSyntax, params DatabaseProviders[] databaseProviders)
public CreateBuilder(IMigrationContext context, params DatabaseProviders[] databaseProviders)
{
_context = context;
_sqlSyntax = sqlSyntax;
_databaseProviders = databaseProviders;
}
[Obsolete("Use alternate ctor specifying ISqlSyntaxProvider instead")]
public CreateBuilder(IMigrationContext context, params DatabaseProviders[] databaseProviders)
:this(context, SqlSyntaxContext.SqlSyntaxProvider, databaseProviders)
{
}
public ICreateTableWithColumnSyntax Table(string tableName)
{
var expression = new CreateTableExpression { TableName = tableName };
var expression = new CreateTableExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, _databaseProviders)
{
TableName = tableName
};
_context.Expressions.Add(expression);
return new CreateTableBuilder(expression, _context);
}
public ICreateColumnOnTableSyntax Column(string columnName)
{
var expression = _databaseProviders == null
? new CreateColumnExpression { Column = { Name = columnName } }
: new CreateColumnExpression(_context.CurrentDatabaseProvider, _databaseProviders) { Column = { Name = columnName } };
var expression = new CreateColumnExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, _databaseProviders)
{
Column = { Name = columnName }
};
_context.Expressions.Add(expression);
return new CreateColumnBuilder(expression, _context);
}
public ICreateForeignKeyFromTableSyntax ForeignKey()
{
var expression = _databaseProviders == null
? new CreateForeignKeyExpression()
: new CreateForeignKeyExpression(_context.CurrentDatabaseProvider, _databaseProviders);
var expression = new CreateForeignKeyExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, _databaseProviders);
_context.Expressions.Add(expression);
return new CreateForeignKeyBuilder(expression);
}
public ICreateForeignKeyFromTableSyntax ForeignKey(string foreignKeyName)
{
var expression = _databaseProviders == null
? new CreateForeignKeyExpression { ForeignKey = { Name = foreignKeyName } }
: new CreateForeignKeyExpression(_context.CurrentDatabaseProvider, _databaseProviders) { ForeignKey = { Name = foreignKeyName } };
var expression = new CreateForeignKeyExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, _databaseProviders)
{
ForeignKey = { Name = foreignKeyName }
};
_context.Expressions.Add(expression);
return new CreateForeignKeyBuilder(expression);
}
public ICreateIndexForTableSyntax Index()
{
var expression = new CreateIndexExpression(_sqlSyntax);
var expression = new CreateIndexExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, _databaseProviders);
_context.Expressions.Add(expression);
return new CreateIndexBuilder(expression);
}
public ICreateIndexForTableSyntax Index(string indexName)
{
var expression = new CreateIndexExpression(_sqlSyntax) { Index = { Name = indexName } };
var expression = new CreateIndexExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, _databaseProviders)
{
Index = { Name = indexName }
};
_context.Expressions.Add(expression);
return new CreateIndexBuilder(expression);
}
public ICreateConstraintOnTableSyntax PrimaryKey()
{
var expression = new CreateConstraintExpression(ConstraintType.PrimaryKey);
var expression = new CreateConstraintExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, ConstraintType.PrimaryKey, _databaseProviders);
_context.Expressions.Add(expression);
return new CreateConstraintBuilder(expression);
}
public ICreateConstraintOnTableSyntax PrimaryKey(string primaryKeyName)
{
var expression = new CreateConstraintExpression(ConstraintType.PrimaryKey);
var expression = new CreateConstraintExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, ConstraintType.PrimaryKey, _databaseProviders);
expression.Constraint.ConstraintName = primaryKeyName;
_context.Expressions.Add(expression);
return new CreateConstraintBuilder(expression);
@@ -95,14 +93,14 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create
public ICreateConstraintOnTableSyntax UniqueConstraint()
{
var expression = new CreateConstraintExpression(ConstraintType.Unique);
var expression = new CreateConstraintExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, ConstraintType.Unique, _databaseProviders);
_context.Expressions.Add(expression);
return new CreateConstraintBuilder(expression);
}
public ICreateConstraintOnTableSyntax UniqueConstraint(string constraintName)
{
var expression = new CreateConstraintExpression(ConstraintType.Unique);
var expression = new CreateConstraintExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, ConstraintType.Unique, _databaseProviders);
expression.Constraint.ConstraintName = constraintName;
_context.Expressions.Add(expression);
return new CreateConstraintBuilder(expression);
@@ -110,7 +108,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create
public ICreateConstraintOnTableSyntax Constraint(string constraintName)
{
var expression = new CreateConstraintExpression(ConstraintType.NonUnique);
var expression = new CreateConstraintExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, ConstraintType.NonUnique, _databaseProviders);
expression.Constraint.ConstraintName = constraintName;
_context.Expressions.Add(expression);
return new CreateConstraintBuilder(expression);

View File

@@ -6,9 +6,10 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create.Expressions
{
public class CreateConstraintExpression : MigrationExpressionBase
{
public CreateConstraintExpression(ConstraintType type)
public CreateConstraintExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, ConstraintType constraintType, DatabaseProviders[] supportedDatabaseProviders = null)
: base(sqlSyntax, currentDatabaseProvider, supportedDatabaseProviders)
{
Constraint = new ConstraintDefinition(type);
Constraint = new ConstraintDefinition(constraintType);
}
public ConstraintDefinition Constraint { get; private set; }
@@ -17,7 +18,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create.Expressions
{
var constraintType = (Constraint.IsPrimaryKeyConstraint) ? "PRIMARY KEY" : "UNIQUE";
if (Constraint.IsPrimaryKeyConstraint && SqlSyntaxContext.SqlSyntaxProvider.SupportsClustered())
if (Constraint.IsPrimaryKeyConstraint && SqlSyntax.SupportsClustered())
constraintType += " CLUSTERED";
if (Constraint.IsNonUniqueConstraint)
@@ -27,12 +28,12 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create.Expressions
for (int i = 0; i < Constraint.Columns.Count; i++)
{
columns[i] = SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumnName(Constraint.Columns.ElementAt(i));
columns[i] = SqlSyntax.GetQuotedColumnName(Constraint.Columns.ElementAt(i));
}
return string.Format(SqlSyntaxContext.SqlSyntaxProvider.CreateConstraint,
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName(Constraint.TableName),
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedName(Constraint.ConstraintName),
return string.Format(SqlSyntax.CreateConstraint,
SqlSyntax.GetQuotedTableName(Constraint.TableName),
SqlSyntax.GetQuotedName(Constraint.ConstraintName),
constraintType,
string.Join(", ", columns));
}

View File

@@ -7,27 +7,8 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create.Expressions
{
public class CreateTableExpression : MigrationExpressionBase
{
[Obsolete("Use the other constructors specifying an ISqlSyntaxProvider instead")]
public CreateTableExpression()
{
Columns = new List<ColumnDefinition>();
}
[Obsolete("Use the other constructors specifying an ISqlSyntaxProvider instead")]
public CreateTableExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders)
: base(current, databaseProviders)
{
Columns = new List<ColumnDefinition>();
}
public CreateTableExpression(ISqlSyntaxProvider sqlSyntax)
: base(sqlSyntax)
{
Columns = new List<ColumnDefinition>();
}
public CreateTableExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders, ISqlSyntaxProvider sqlSyntax)
: base(current, databaseProviders, sqlSyntax)
public CreateTableExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, DatabaseProviders[] supportedDatabaseProviders = null)
: base(sqlSyntax, currentDatabaseProvider, supportedDatabaseProviders)
{
Columns = new List<ColumnDefinition>();
}

View File

@@ -62,7 +62,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create.Table
{
CurrentColumn.IsIndexed = true;
var index = new CreateIndexExpression
var index = new CreateIndexExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
Index = new IndexDefinition
{
@@ -86,7 +86,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create.Table
{
CurrentColumn.IsPrimaryKey = true;
var expression = new CreateConstraintExpression(ConstraintType.PrimaryKey)
var expression = new CreateConstraintExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, ConstraintType.PrimaryKey)
{
Constraint =
{
@@ -104,7 +104,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create.Table
CurrentColumn.IsPrimaryKey = true;
CurrentColumn.PrimaryKeyName = primaryKeyName;
var expression = new CreateConstraintExpression(ConstraintType.PrimaryKey)
var expression = new CreateConstraintExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, ConstraintType.PrimaryKey)
{
Constraint =
{
@@ -139,7 +139,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create.Table
{
CurrentColumn.IsUnique = true;
var index = new CreateIndexExpression
var index = new CreateIndexExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
Index = new IndexDefinition
{
@@ -176,7 +176,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create.Table
{
CurrentColumn.IsForeignKey = true;
var fk = new CreateForeignKeyExpression
var fk = new CreateForeignKeyExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
ForeignKey = new ForeignKeyDefinition
{
@@ -216,7 +216,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Create.Table
public ICreateTableColumnOptionForeignKeyCascadeSyntax ReferencedBy(string foreignKeyName, string foreignTableSchema,
string foreignTableName, string foreignColumnName)
{
var fk = new CreateForeignKeyExpression
var fk = new CreateForeignKeyExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider)
{
ForeignKey = new ForeignKeyDefinition
{

View File

@@ -13,79 +13,80 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete
public class DeleteBuilder : IDeleteBuilder
{
private readonly IMigrationContext _context;
private readonly ISqlSyntaxProvider _sqlSyntax;
private readonly DatabaseProviders[] _databaseProviders;
public DeleteBuilder(IMigrationContext context, ISqlSyntaxProvider sqlSyntax, params DatabaseProviders[] databaseProviders)
public DeleteBuilder(IMigrationContext context, params DatabaseProviders[] databaseProviders)
{
_context = context;
_sqlSyntax = sqlSyntax;
_databaseProviders = databaseProviders;
}
[Obsolete("Use the other constructor specifying an ISqlSyntaxProvider instead")]
public DeleteBuilder(IMigrationContext context, params DatabaseProviders[] databaseProviders)
: this(context, SqlSyntaxContext.SqlSyntaxProvider, databaseProviders)
{
}
public void Table(string tableName)
{
var expression = new DeleteTableExpression { TableName = tableName };
var expression = new DeleteTableExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, _databaseProviders)
{
TableName = tableName
};
_context.Expressions.Add(expression);
}
public IDeleteColumnFromTableSyntax Column(string columnName)
{
var expression = _databaseProviders == null
? new DeleteColumnExpression { ColumnNames = { columnName } }
: new DeleteColumnExpression(_context.CurrentDatabaseProvider, _databaseProviders) { ColumnNames = { columnName } };
var expression = new DeleteColumnExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, _databaseProviders)
{
ColumnNames = { columnName }
};
_context.Expressions.Add(expression);
return new DeleteColumnBuilder(expression);
}
public IDeleteForeignKeyFromTableSyntax ForeignKey()
{
var expression = _databaseProviders == null
? new DeleteForeignKeyExpression(_sqlSyntax)
: new DeleteForeignKeyExpression(_context.CurrentDatabaseProvider, _databaseProviders, _sqlSyntax);
var expression = new DeleteForeignKeyExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, _databaseProviders);
_context.Expressions.Add(expression);
return new DeleteForeignKeyBuilder(expression);
}
public IDeleteForeignKeyOnTableSyntax ForeignKey(string foreignKeyName)
{
var expression = _databaseProviders == null
? new DeleteForeignKeyExpression(_sqlSyntax) { ForeignKey = { Name = foreignKeyName } }
: new DeleteForeignKeyExpression(_context.CurrentDatabaseProvider, _databaseProviders, _sqlSyntax) { ForeignKey = { Name = foreignKeyName } };
var expression = new DeleteForeignKeyExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, _databaseProviders)
{
ForeignKey = { Name = foreignKeyName }
};
_context.Expressions.Add(expression);
return new DeleteForeignKeyBuilder(expression);
}
public IDeleteDataSyntax FromTable(string tableName)
{
var expression = new DeleteDataExpression { TableName = tableName };
var expression = new DeleteDataExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, _databaseProviders)
{
TableName = tableName
};
_context.Expressions.Add(expression);
return new DeleteDataBuilder(expression);
}
public IDeleteIndexForTableSyntax Index()
{
var expression = new DeleteIndexExpression();
var expression = new DeleteIndexExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, _databaseProviders);
_context.Expressions.Add(expression);
return new DeleteIndexBuilder(expression);
}
public IDeleteIndexForTableSyntax Index(string indexName)
{
var expression = new DeleteIndexExpression { Index = { Name = indexName } };
var expression = new DeleteIndexExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, _databaseProviders)
{
Index = { Name = indexName }
};
_context.Expressions.Add(expression);
return new DeleteIndexBuilder(expression);
}
public IDeleteConstraintOnTableSyntax PrimaryKey(string primaryKeyName)
{
var expression = new DeleteConstraintExpression(_context.CurrentDatabaseProvider, _databaseProviders, ConstraintType.PrimaryKey)
var expression = new DeleteConstraintExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, ConstraintType.PrimaryKey, _databaseProviders)
{
Constraint = { ConstraintName = primaryKeyName }
};
@@ -95,7 +96,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete
public IDeleteConstraintOnTableSyntax UniqueConstraint(string constraintName)
{
var expression = new DeleteConstraintExpression(ConstraintType.Unique)
var expression = new DeleteConstraintExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, ConstraintType.Unique, _databaseProviders)
{
Constraint = { ConstraintName = constraintName }
};
@@ -105,9 +106,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete
public IDeleteDefaultConstraintOnTableSyntax DefaultConstraint()
{
var expression = _databaseProviders == null
? new DeleteDefaultConstraintExpression()
: new DeleteDefaultConstraintExpression(_context.CurrentDatabaseProvider, _databaseProviders);
var expression = new DeleteDefaultConstraintExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider, _databaseProviders);
_context.Expressions.Add(expression);
return new DeleteDefaultConstraintBuilder(expression);
}

View File

@@ -7,13 +7,8 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete.Expressions
{
public class DeleteColumnExpression : MigrationExpressionBase
{
public DeleteColumnExpression()
{
ColumnNames = new List<string>();
}
public DeleteColumnExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders)
: base(current, databaseProviders)
public DeleteColumnExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, DatabaseProviders[] supportedDatabaseProviders = null)
: base(sqlSyntax, currentDatabaseProvider, supportedDatabaseProviders)
{
ColumnNames = new List<string>();
}
@@ -31,9 +26,9 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete.Expressions
foreach (string columnName in ColumnNames)
{
if (ColumnNames.First() != columnName) sb.AppendLine(";");
sb.AppendFormat(SqlSyntaxContext.SqlSyntaxProvider.DropColumn,
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName(TableName),
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumnName(columnName));
sb.AppendFormat(SqlSyntax.DropColumn,
SqlSyntax.GetQuotedTableName(TableName),
SqlSyntax.GetQuotedColumnName(columnName));
}
return sb.ToString();

View File

@@ -5,13 +5,8 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete.Expressions
{
public class DeleteConstraintExpression : MigrationExpressionBase
{
public DeleteConstraintExpression(ConstraintType type)
{
Constraint = new ConstraintDefinition(type);
}
public DeleteConstraintExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders, ConstraintType type)
: base(current, databaseProviders)
public DeleteConstraintExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders current, ConstraintType type, DatabaseProviders[] databaseProviders = null)
: base(sqlSyntax, current, databaseProviders)
{
Constraint = new ConstraintDefinition(type);
}
@@ -25,24 +20,27 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete.Expressions
{
if (Constraint.IsPrimaryKeyConstraint)
{
return string.Format(SqlSyntaxContext.SqlSyntaxProvider.DeleteConstraint,
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName(Constraint.TableName),
"PRIMARY KEY",
"");
return string.Format(
SqlSyntax.DeleteConstraint,
SqlSyntax.GetQuotedTableName(Constraint.TableName),
"PRIMARY KEY",
"");
}
else
{
return string.Format(SqlSyntaxContext.SqlSyntaxProvider.DeleteConstraint,
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName(Constraint.TableName),
"FOREIGN KEY",
"");
return string.Format(
SqlSyntax.DeleteConstraint,
SqlSyntax.GetQuotedTableName(Constraint.TableName),
"FOREIGN KEY",
"");
}
}
else
{
return string.Format(SqlSyntaxContext.SqlSyntaxProvider.DeleteConstraint,
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName(Constraint.TableName),
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedName(Constraint.ConstraintName));
return string.Format(
SqlSyntax.DeleteConstraint,
SqlSyntax.GetQuotedTableName(Constraint.TableName),
SqlSyntax.GetQuotedName(Constraint.ConstraintName));
}
}
}

View File

@@ -9,11 +9,9 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete.Expressions
{
private readonly List<DeletionDataDefinition> _rows = new List<DeletionDataDefinition>();
public DeleteDataExpression()
{
}
public DeleteDataExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders) : base(current, databaseProviders)
public DeleteDataExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, DatabaseProviders[] supportedDatabaseProviders = null)
: base(sqlSyntax, currentDatabaseProvider, supportedDatabaseProviders)
{
}
@@ -32,7 +30,9 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete.Expressions
if (IsAllRows)
{
deleteItems.Add(string.Format(SqlSyntaxContext.SqlSyntaxProvider.DeleteData, SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName(TableName), "1 = 1"));
deleteItems.Add(string.Format(
SqlSyntax.DeleteData,
SqlSyntax.GetQuotedTableName(TableName), "1 = 1"));
}
else
{
@@ -42,13 +42,13 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete.Expressions
foreach (KeyValuePair<string, object> item in row)
{
whereClauses.Add(string.Format("{0} {1} {2}",
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumnName(item.Key),
SqlSyntax.GetQuotedColumnName(item.Key),
item.Value == null ? "IS" : "=",
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedValue(item.Value.ToString())));
SqlSyntax.GetQuotedValue(item.Value.ToString())));
}
deleteItems.Add(string.Format(SqlSyntaxContext.SqlSyntaxProvider.DeleteData,
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName(TableName),
deleteItems.Add(string.Format(SqlSyntax.DeleteData,
SqlSyntax.GetQuotedTableName(TableName),
String.Join(" AND ", whereClauses.ToArray())));
}
}

View File

@@ -4,12 +4,8 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete.Expressions
{
public class DeleteDefaultConstraintExpression : MigrationExpressionBase
{
public DeleteDefaultConstraintExpression()
{
}
public DeleteDefaultConstraintExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders)
: base(current, databaseProviders)
public DeleteDefaultConstraintExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, DatabaseProviders[] supportedDatabaseProviders = null)
: base(sqlSyntax, currentDatabaseProvider, supportedDatabaseProviders)
{
}
@@ -22,7 +18,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete.Expressions
if (IsExpressionSupported() == false)
return string.Empty;
return string.Format(SqlSyntaxContext.SqlSyntaxProvider.DeleteDefaultConstraint,
return string.Format(SqlSyntax.DeleteDefaultConstraint,
TableName,
ColumnName);
}

View File

@@ -8,31 +8,12 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete.Expressions
{
public class DeleteForeignKeyExpression : MigrationExpressionBase
{
[Obsolete("Use the other constructors specifying an ILogger instead")]
public DeleteForeignKeyExpression()
public DeleteForeignKeyExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, DatabaseProviders[] supportedDatabaseProviders = null)
: base(sqlSyntax, currentDatabaseProvider, supportedDatabaseProviders)
{
ForeignKey = new ForeignKeyDefinition();
}
[Obsolete("Use the other constructors specifying an ILogger instead")]
public DeleteForeignKeyExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders)
: base(current, databaseProviders)
{
ForeignKey = new ForeignKeyDefinition();
}
public DeleteForeignKeyExpression(ISqlSyntaxProvider sqlSyntax)
: base(sqlSyntax)
{
ForeignKey = new ForeignKeyDefinition();
}
public DeleteForeignKeyExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders, ISqlSyntaxProvider sqlSyntax)
: base(current, databaseProviders, sqlSyntax)
{
ForeignKey = new ForeignKeyDefinition();
}
public virtual ForeignKeyDefinition ForeignKey { get; set; }
public override string ToString()

View File

@@ -5,12 +5,8 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete.Expressions
{
public class DeleteIndexExpression : MigrationExpressionBase
{
public DeleteIndexExpression()
{
Index = new IndexDefinition();
}
public DeleteIndexExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders) : base(current, databaseProviders)
public DeleteIndexExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, DatabaseProviders[] supportedDatabaseProviders = null)
: base(sqlSyntax, currentDatabaseProvider, supportedDatabaseProviders)
{
Index = new IndexDefinition();
}
@@ -19,9 +15,9 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete.Expressions
public override string ToString()
{
return string.Format(SqlSyntaxContext.SqlSyntaxProvider.DropIndex,
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedName(Index.Name),
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName(Index.TableName));
return string.Format(SqlSyntax.DropIndex,
SqlSyntax.GetQuotedName(Index.Name),
SqlSyntax.GetQuotedTableName(Index.TableName));
}
}
}

View File

@@ -4,11 +4,8 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete.Expressions
{
public class DeleteTableExpression : MigrationExpressionBase
{
public DeleteTableExpression()
{
}
public DeleteTableExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders) : base(current, databaseProviders)
public DeleteTableExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, DatabaseProviders[] supportedDatabaseProviders = null)
: base(sqlSyntax, currentDatabaseProvider, supportedDatabaseProviders)
{
}
@@ -17,8 +14,8 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Delete.Expressions
public override string ToString()
{
return string.Format(SqlSyntaxContext.SqlSyntaxProvider.DropTable,
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName(TableName));
return string.Format(SqlSyntax.DropTable,
SqlSyntax.GetQuotedTableName(TableName));
}
}
}

View File

@@ -16,19 +16,19 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Execute
public void Sql(string sqlStatement)
{
var expression = _databaseProviders == null
? new ExecuteSqlStatementExpression {SqlStatement = sqlStatement}
: new ExecuteSqlStatementExpression(_context.CurrentDatabaseProvider,
_databaseProviders) {SqlStatement = sqlStatement};
var expression = new ExecuteSqlStatementExpression(
_context.SqlSyntax,
_context.CurrentDatabaseProvider,
_databaseProviders) {SqlStatement = sqlStatement};
_context.Expressions.Add(expression);
}
public void Code(Func<Database, string> codeStatement)
{
var expression = _databaseProviders == null
? new ExecuteCodeStatementExpression { CodeStatement = codeStatement }
: new ExecuteCodeStatementExpression(_context.CurrentDatabaseProvider,
_databaseProviders) { CodeStatement = codeStatement };
var expression = new ExecuteCodeStatementExpression(
_context.SqlSyntax,
_context.CurrentDatabaseProvider,
_databaseProviders) {CodeStatement = codeStatement};
_context.Expressions.Add(expression);
}
}

View File

@@ -1,15 +1,12 @@
using System;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Syntax.Execute.Expressions
{
public class ExecuteCodeStatementExpression : MigrationExpressionBase
{
public ExecuteCodeStatementExpression()
{
}
public ExecuteCodeStatementExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders)
: base(current, databaseProviders)
public ExecuteCodeStatementExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, DatabaseProviders[] supportedDatabaseProviders = null)
: base(sqlSyntax, currentDatabaseProvider, supportedDatabaseProviders)
{
}
@@ -17,7 +14,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Execute.Expressions
public override string Process(Database database)
{
if(CodeStatement != null)
if (CodeStatement != null)
return CodeStatement(database);
return base.Process(database);

View File

@@ -1,12 +1,11 @@
namespace Umbraco.Core.Persistence.Migrations.Syntax.Execute.Expressions
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Syntax.Execute.Expressions
{
public class ExecuteSqlStatementExpression : MigrationExpressionBase
{
public ExecuteSqlStatementExpression()
{
}
public ExecuteSqlStatementExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders) : base(current, databaseProviders)
public ExecuteSqlStatementExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, DatabaseProviders[] supportedDatabaseProviders = null)
: base(sqlSyntax, currentDatabaseProvider, supportedDatabaseProviders)
{
}

View File

@@ -5,13 +5,8 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Expressions
{
public class CreateColumnExpression : MigrationExpressionBase
{
public CreateColumnExpression()
{
Column = new ColumnDefinition { ModificationType = ModificationType.Create };
}
public CreateColumnExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders)
: base(current, databaseProviders)
public CreateColumnExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, DatabaseProviders[] supportedDatabaseProviders = null)
: base(sqlSyntax, currentDatabaseProvider, supportedDatabaseProviders)
{
Column = new ColumnDefinition { ModificationType = ModificationType.Create };
}
@@ -28,9 +23,9 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Expressions
if (string.IsNullOrEmpty(Column.TableName))
Column.TableName = TableName;
return string.Format(SqlSyntaxContext.SqlSyntaxProvider.AddColumn,
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName(Column.TableName),
SqlSyntaxContext.SqlSyntaxProvider.Format(Column));
return string.Format(SqlSyntax.AddColumn,
SqlSyntax.GetQuotedTableName(Column.TableName),
SqlSyntax.Format(Column));
}
}
}

View File

@@ -5,13 +5,8 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Expressions
{
public class CreateForeignKeyExpression : MigrationExpressionBase
{
public CreateForeignKeyExpression()
{
ForeignKey = new ForeignKeyDefinition();
}
public CreateForeignKeyExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders)
: base(current, databaseProviders)
public CreateForeignKeyExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, DatabaseProviders[] supportedDatabaseProviders = null)
: base(sqlSyntax, currentDatabaseProvider, supportedDatabaseProviders)
{
ForeignKey = new ForeignKeyDefinition();
}
@@ -23,7 +18,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Expressions
if (IsExpressionSupported() == false)
return string.Empty;
return SqlSyntaxContext.SqlSyntaxProvider.Format(ForeignKey);
return SqlSyntax.Format(ForeignKey);
}
}
}

View File

@@ -6,30 +6,11 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Expressions
{
public class CreateIndexExpression : MigrationExpressionBase
{
public CreateIndexExpression(ISqlSyntaxProvider sqlSyntax)
: base(sqlSyntax)
public CreateIndexExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, DatabaseProviders[] supportedDatabaseProviders = null)
: base(sqlSyntax, currentDatabaseProvider, supportedDatabaseProviders)
{
Index = new IndexDefinition();
}
public CreateIndexExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders, ISqlSyntaxProvider sqlSyntax)
: base(current, databaseProviders, sqlSyntax)
{
Index = new IndexDefinition();
}
[Obsolete("Use alternate ctor specifying ISqlSyntaxProvider instead")]
public CreateIndexExpression()
: this(SqlSyntaxContext.SqlSyntaxProvider)
{
}
[Obsolete("Use alternate ctor specifying ISqlSyntaxProvider instead")]
public CreateIndexExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders)
: this(current, databaseProviders, SqlSyntaxContext.SqlSyntaxProvider)
{
}
public virtual IndexDefinition Index { get; set; }

View File

@@ -9,24 +9,21 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Insert.Expressions
{
private readonly List<InsertionDataDefinition> _rows = new List<InsertionDataDefinition>();
public InsertDataExpression()
{
}
public InsertDataExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders) : base(current, databaseProviders)
public InsertDataExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, DatabaseProviders[] supportedDatabaseProviders = null)
: base(sqlSyntax, currentDatabaseProvider, supportedDatabaseProviders)
{
}
public string SchemaName { get; set; }
public string TableName { get; set; }
public List<InsertionDataDefinition> Rows
{
get { return _rows; }
}
public override string ToString()
{
@@ -36,7 +33,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Insert.Expressions
return string.Empty;
var insertItems = new List<string>();
foreach (var item in Rows)
{
var cols = "";
@@ -50,10 +47,11 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Insert.Expressions
vals = vals.TrimEnd(',');
var sql = string.Format(SqlSyntaxContext.SqlSyntaxProvider.InsertData,
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName(TableName),
cols, vals);
var sql = string.Format(
SqlSyntax.InsertData,
SqlSyntax.GetQuotedTableName(TableName),
cols, vals);
insertItems.Add(sql);
}
@@ -64,12 +62,12 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Insert.Expressions
{
var type = val.GetType();
switch (Type.GetTypeCode(type))
{
{
case TypeCode.Boolean:
return ((bool) val) ? "1" : "0";
return ((bool)val) ? "1" : "0";
case TypeCode.Single:
case TypeCode.Double:
case TypeCode.Decimal:
case TypeCode.Decimal:
case TypeCode.SByte:
case TypeCode.Int16:
case TypeCode.Int32:
@@ -80,7 +78,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Insert.Expressions
case TypeCode.UInt64:
return val.ToString();
default:
return SqlSyntaxContext.SqlSyntaxProvider.GetQuotedValue(val.ToString());
return SqlSyntax.GetQuotedValue(val.ToString());
}
}
}

View File

@@ -13,7 +13,7 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Insert
public IInsertDataSyntax IntoTable(string tableName)
{
var expression = new InsertDataExpression { TableName = tableName };
var expression = new InsertDataExpression(_context.SqlSyntax, _context.CurrentDatabaseProvider) { TableName = tableName };
_context.Expressions.Add(expression);
return new InsertDataBuilder(expression);
}

View File

@@ -4,12 +4,8 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Rename.Expressions
{
public class RenameColumnExpression : MigrationExpressionBase
{
public RenameColumnExpression()
{
}
public RenameColumnExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders)
: base(current, databaseProviders)
public RenameColumnExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, DatabaseProviders[] supportedDatabaseProviders = null)
: base(sqlSyntax, currentDatabaseProvider, supportedDatabaseProviders)
{
}
@@ -52,7 +48,7 @@ SELECT CONCAT(
if (IsExpressionSupported() == false)
return string.Empty;
return SqlSyntaxContext.SqlSyntaxProvider.FormatColumnRename(TableName, OldName, NewName);
return SqlSyntax.FormatColumnRename(TableName, OldName, NewName);
}
}
}

View File

@@ -4,12 +4,8 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Rename.Expressions
{
public class RenameTableExpression : MigrationExpressionBase
{
public RenameTableExpression()
{
}
public RenameTableExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders)
: base(current, databaseProviders)
public RenameTableExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, DatabaseProviders[] supportedDatabaseProviders = null)
: base(sqlSyntax, currentDatabaseProvider, supportedDatabaseProviders)
{
}
@@ -21,8 +17,8 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Rename.Expressions
{
if (IsExpressionSupported() == false)
return string.Empty;
return SqlSyntaxContext.SqlSyntaxProvider.FormatTableRename(OldName, NewName);
return SqlSyntax.FormatTableRename(OldName, NewName);
}
}
}

View File

@@ -17,18 +17,18 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Rename
public IRenameTableSyntax Table(string oldName)
{
var expression = _databaseProviders == null
? new RenameTableExpression {OldName = oldName}
: new RenameTableExpression(_context.CurrentDatabaseProvider, _databaseProviders) { OldName = oldName };
var expression = new RenameTableExpression(
_context.SqlSyntax,
_context.CurrentDatabaseProvider, _databaseProviders) {OldName = oldName};
_context.Expressions.Add(expression);
return new RenameTableBuilder(expression);
}
public IRenameColumnTableSyntax Column(string oldName)
{
var expression = _databaseProviders == null
? new RenameColumnExpression {OldName = oldName}
: new RenameColumnExpression(_context.CurrentDatabaseProvider, _databaseProviders) { OldName = oldName };
var expression = new RenameColumnExpression(
_context.SqlSyntax,
_context.CurrentDatabaseProvider, _databaseProviders) {OldName = oldName};
_context.Expressions.Add(expression);
return new RenameColumnBuilder(expression);
}

View File

@@ -5,11 +5,8 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Update.Expressions
{
public class UpdateDataExpression : MigrationExpressionBase
{
public UpdateDataExpression()
{
}
public UpdateDataExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders) : base(current, databaseProviders)
public UpdateDataExpression(ISqlSyntaxProvider sqlSyntax, DatabaseProviders currentDatabaseProvider, DatabaseProviders[] supportedDatabaseProviders = null)
: base(sqlSyntax, currentDatabaseProvider, supportedDatabaseProviders)
{
}
@@ -31,8 +28,8 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Update.Expressions
foreach (var item in Set)
{
updateItems.Add(string.Format("{0} = {1}",
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumnName(item.Key),
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedValue(item.Value.ToString())));
SqlSyntax.GetQuotedColumnName(item.Key),
SqlSyntax.GetQuotedValue(item.Value.ToString())));
}
if (IsAllRows)
@@ -44,14 +41,14 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Update.Expressions
foreach (var item in Where)
{
whereClauses.Add(string.Format("{0} {1} {2}",
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumnName(item.Key),
SqlSyntax.GetQuotedColumnName(item.Key),
item.Value == null ? "IS" : "=",
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedValue(item.Value.ToString())));
SqlSyntax.GetQuotedValue(item.Value.ToString())));
}
}
return string.Format(SqlSyntaxContext.SqlSyntaxProvider.UpdateData,
SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName(TableName),
string.Join(", ", updateItems.ToArray()),
return string.Format(SqlSyntax.UpdateData,
SqlSyntax.GetQuotedTableName(TableName),
string.Join(", ", updateItems.ToArray()),
string.Join(" AND ", whereClauses.ToArray()));
}
}

View File

@@ -15,9 +15,11 @@ namespace Umbraco.Core.Persistence.Migrations.Syntax.Update
public IUpdateSetSyntax Table(string tableName)
{
var expression = _databaseProviders == null
? new UpdateDataExpression { TableName = tableName }
: new UpdateDataExpression(_context.CurrentDatabaseProvider, _databaseProviders) { TableName = tableName };
var expression = new UpdateDataExpression(
_context.SqlSyntax,
_context.CurrentDatabaseProvider,
_databaseProviders) {TableName = tableName};
_context.Expressions.Add(expression);
return new UpdateDataBuilder(expression, _context);
}

View File

@@ -1,6 +1,7 @@
using System.Data;
using System.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionFourNineZero
@@ -8,6 +9,11 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionFourNineZero
[MigrationAttribute("4.9.0", 0, GlobalSettings.UmbracoMigrationName)]
public class RemoveUmbracoAppConstraints : MigrationBase
{
public RemoveUmbracoAppConstraints(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
//This will work on mysql and should work on mssql however the old keys were not named consistently with how the keys are
@@ -27,15 +33,15 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionFourNineZero
{
Delete.ForeignKey("FK_umbracoUser2app_umbracoApp").OnTable("umbracoUser2app");
//name this migration, this is a hack for DeleteAppTables to ensure it's not executed twice
((MigrationExpressionBase) Context.Expressions.Last()).Name = "FK_umbracoUser2app_umbracoApp";
((MigrationExpressionBase)Context.Expressions.Last()).Name = "FK_umbracoUser2app_umbracoApp";
}
if (constraints.Any(x => x.Item1.InvariantEquals("umbracoUser2app") && x.Item3.InvariantEquals("FK_umbracoUser2app_umbracoUser")))
{
Delete.ForeignKey("FK_umbracoUser2app_umbracoUser").OnTable("umbracoUser2app");
}
}
}
public override void Down()

View File

@@ -21,14 +21,14 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
_skipIndexCheck = skipIndexCheck;
}
public AddIndexToCmsMacroPropertyTable()
public AddIndexToCmsMacroPropertyTable(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
var dbIndexes = _skipIndexCheck ? new DbIndexDefinition[]{} : SqlSyntax.GetDefinedIndexes(Context.Database)
var dbIndexes = _skipIndexCheck ? new DbIndexDefinition[] { } : SqlSyntax.GetDefinedIndexes(Context.Database)
.Select(x => new DbIndexDefinition()
{
TableName = x.Item1,
@@ -47,7 +47,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
.Unique();
}
}
public override void Down()

View File

@@ -22,9 +22,9 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
_skipIndexCheck = skipIndexCheck;
}
public AddIndexToCmsMacroTable()
public AddIndexToCmsMacroTable(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
@@ -41,9 +41,9 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
//make sure it doesn't already exist
if (dbIndexes.Any(x => x.IndexName.InvariantEquals("IX_cmsMacro_Alias")) == false)
{
Create.Index("IX_cmsMacro_Alias").OnTable("cmsMacro").OnColumn("macroAlias").Unique();
Create.Index("IX_cmsMacro_Alias").OnTable("cmsMacro").OnColumn("macroAlias").Unique();
}
}
public override void Down()

View File

@@ -1,5 +1,7 @@
using System;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
{
@@ -7,8 +9,13 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
[Migration("7.0.0", 0, GlobalSettings.UmbracoMigrationName)]
public class AddPropertyEditorAliasColumn : MigrationBase
{
public AddPropertyEditorAliasColumn(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
{
Alter.Table("cmsDataType").AddColumn("propertyEditorAlias").AsString(255).NotNullable().WithDefaultValue("");
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
using Umbraco.Core.Persistence.Migrations.Syntax.Delete.DefaultConstraint;
using Umbraco.Core.Persistence.Migrations.Syntax.Delete.Expressions;
@@ -19,11 +20,16 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
[Migration("7.0.0", 6, GlobalSettings.UmbracoMigrationName)]
public class AlterCmsMacroPropertyTable : MigrationBase
{
public AlterCmsMacroPropertyTable(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
//now that the controlId column is renamed and now a string we need to convert
if (Context == null || Context.Database == null) return;
//var cpt = SqlSyntaxContext.SqlSyntaxProvider.GetConstraintsPerTable(Context.Database);
//var di = SqlSyntaxContext.SqlSyntaxProvider.GetDefinedIndexes(Context.Database);
@@ -68,7 +74,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
Delete.ForeignKey(constraint.Item3).OnTable("cmsMacroProperty");
}
}
Alter.Table("cmsMacroProperty").AddColumn("editorAlias").AsString(255).NotNullable().WithDefaultValue("");
//we need to get the data and create the migration scripts before we change the actual schema bits below!

View File

@@ -12,6 +12,11 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
[Migration("7.0.0", 8, GlobalSettings.UmbracoMigrationName)]
public class AlterTagRelationsTable : MigrationBase
{
public AlterTagRelationsTable(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
if (Context == null || Context.Database == null) return;
@@ -52,7 +57,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
// at least since 6.0 and the new installation way but perhaps it had them way back in 4.x so we need to check
// it exists before trying to drop it.
if (Context.CurrentDatabaseProvider == DatabaseProviders.MySql)
{
{
//this will let us know if this pk exists on this table
if (constraints.Count(x => x.Item1.InvariantEquals("cmsTagRelationship") && x.Item3.InvariantEquals("PRIMARY")) > 0)
{
@@ -65,10 +70,10 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
var pkName = constraints.FirstOrDefault(x => x.Item1.InvariantEquals("cmsTagRelationship") && x.Item3.InvariantStartsWith("PK_"));
if (pkName != null)
{
Delete.PrimaryKey(pkName.Item3).FromTable("cmsTagRelationship");
Delete.PrimaryKey(pkName.Item3).FromTable("cmsTagRelationship");
}
}
}
private void Upgrade()

View File

@@ -2,6 +2,7 @@
using System.Data;
using System.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
using Umbraco.Core.Persistence.SqlSyntax;
@@ -10,6 +11,11 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
[Migration("7.0.0", 9, GlobalSettings.UmbracoMigrationName)]
public class AlterTagsTable : MigrationBase
{
public AlterTagsTable(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
var dbIndexes = SqlSyntax.GetDefinedIndexes(Context.Database)
@@ -20,7 +26,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
ColumnName = x.Item3,
IsUnique = x.Item4
}).ToArray();
//add a foreign key to the parent id column too!
Create.ForeignKey("FK_cmsTags_cmsTags")
.FromTable("cmsTags")
@@ -28,7 +34,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
.ToTable("cmsTags")
.PrimaryColumn("id")
.OnDelete(Rule.None)
.OnUpdate(Rule.None);
.OnUpdate(Rule.None);
//make sure it doesn't already exist
if (dbIndexes.Any(x => x.IndexName.InvariantEquals("IX_cmsTags")) == false)
@@ -36,7 +42,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
//add an index to tag/group since it's queried often
Create.Index("IX_cmsTags").OnTable("cmsTags").OnColumn("tag").Ascending().OnColumn("group").Ascending().WithOptions().NonClustered();
}
}
public override void Down()

View File

@@ -1,11 +1,18 @@
using System;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
{
[Migration("7.0.0", 3, GlobalSettings.UmbracoMigrationName)]
public class AlterUserTable : MigrationBase
{
public AlterUserTable(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
Delete.Column("userDefaultPermissions").FromTable("umbracoUser");

View File

@@ -1,6 +1,7 @@
using System.Data;
using System.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
using Umbraco.Core.Persistence.SqlSyntax;
@@ -14,6 +15,11 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
[Migration("7.0.0", 0, GlobalSettings.UmbracoMigrationName)]
public class AssignMissingKeysAndIndexes : MigrationBase
{
public AssignMissingKeysAndIndexes(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
@@ -33,7 +39,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
Create.Index("IX_cmsContent").OnTable("cmsContent").OnColumn("nodeId").Ascending().WithOptions().Unique();
}
if (Context.CurrentDatabaseProvider == DatabaseProviders.SqlServer
if (Context.CurrentDatabaseProvider == DatabaseProviders.SqlServer
|| Context.CurrentDatabaseProvider == DatabaseProviders.SqlServerCE)
{
var constraints = SqlSyntax.GetConstraintsPerColumn(Context.Database).Distinct().ToArray();

View File

@@ -1,11 +1,18 @@
using System;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
{
[Migration("7.0.0", 2, GlobalSettings.UmbracoMigrationName)]
public class DropControlIdColumn : MigrationBase
{
public DropControlIdColumn(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
Delete.Column("controlId").FromTable("cmsDataType");

View File

@@ -1,11 +1,18 @@
using System;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
{
[Migration("7.0.0", 7, GlobalSettings.UmbracoMigrationName)]
public class RemoveCmsMacroPropertyTypeTable : MigrationBase
{
public RemoveCmsMacroPropertyTypeTable(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
Delete.Table("cmsMacroPropertyType");

View File

@@ -1,5 +1,7 @@
using System;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.SqlSyntax;
using Umbraco.Core.PropertyEditors;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
@@ -10,6 +12,11 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
[Migration("7.0.0", 1, GlobalSettings.UmbracoMigrationName)]
public class UpdateControlIdToPropertyEditorAlias : MigrationBase
{
public UpdateControlIdToPropertyEditorAlias(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
//now that the controlId column is renamed and now a string we need to convert

View File

@@ -12,12 +12,18 @@ using Newtonsoft.Json;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
{
[Migration("7.0.0", 10, GlobalSettings.UmbracoMigrationName)]
public class UpdateRelatedLinksData : MigrationBase
{
public UpdateRelatedLinksData(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
Execute.Code(UpdateRelatedLinksDataDo);
@@ -27,7 +33,8 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
{
if (database != null)
{
var dtSql = new Sql().Select("nodeId").From<DataTypeDto>().Where<DataTypeDto>(dto => dto.PropertyEditorAlias == Constants.PropertyEditors.RelatedLinksAlias);
var dtSql = new Sql().Select("nodeId").From<DataTypeDto>(SqlSyntax)
.Where<DataTypeDto>(SqlSyntax, dto => dto.PropertyEditorAlias == Constants.PropertyEditors.RelatedLinksAlias);
var dataTypeIds = database.Fetch<int>(dtSql);
if (!dataTypeIds.Any()) return string.Empty;
@@ -64,9 +71,9 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven
xml = new XmlDocument();
xml.LoadXml(data.Text);
}
catch (Exception ex)
catch (Exception ex)
{
Logger.Error<UpdateRelatedLinksData>("The data stored for property id " + data.Id + " on document " + data.NodeId +
Logger.Error<UpdateRelatedLinksData>("The data stored for property id " + data.Id + " on document " + data.NodeId +
" is not valid XML, the data will be removed because it cannot be converted to the new format. The value was: " + data.Text, ex);
data.Text = "";

View File

@@ -1,5 +1,6 @@
using System.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenOneZero
@@ -13,12 +14,17 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenOneZero
[Migration("7.0.0", "7.1.0", 0, GlobalSettings.UmbracoMigrationName)]
public class AssignMissingPrimaryForMySqlKeys : MigrationBase
{
public AssignMissingPrimaryForMySqlKeys(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
if (Context.CurrentDatabaseProvider == DatabaseProviders.MySql)
{
var constraints = SqlSyntax.GetConstraintsPerColumn(Context.Database).Distinct().ToArray();
//This should be 3 because this table has 3 keys
if (constraints.Count(x => x.Item1.InvariantEquals("cmsTagRelationship") && x.Item3.InvariantEquals("PRIMARY")) == 0)
{

View File

@@ -1,11 +1,18 @@
using System.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZero
{
[Migration("7.3.0", 5, GlobalSettings.UmbracoMigrationName)]
public class AddPublicAccessTables : MigrationBase
{
public AddPublicAccessTables(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
//Don't exeucte if the table is already there

View File

@@ -1,12 +1,19 @@
using System;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZero
{
[Migration("7.3.0", 0, GlobalSettings.UmbracoMigrationName)]
public class AddRelationTypeForDocumentOnDelete : MigrationBase
{
public AddRelationTypeForDocumentOnDelete(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
Insert.IntoTable("umbracoRelationType").Row(new

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.SqlSyntax;
@@ -12,6 +13,11 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZe
[Migration("7.3.0", 1, GlobalSettings.UmbracoMigrationName)]
public class MigrateAndRemoveTemplateMasterColumn : MigrationBase
{
public MigrateAndRemoveTemplateMasterColumn(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
@@ -24,14 +30,14 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZe
//update the parentId column for all templates to be correct so it matches the current 'master' template
//NOTE: we are using dynamic because we need to get the data in a column that no longer exists in the schema
var templates = Context.Database.Fetch<dynamic>(new Sql().Select("*").From<TemplateDto>());
var templates = Context.Database.Fetch<dynamic>(new Sql().Select("*").From<TemplateDto>(SqlSyntax));
foreach (var template in templates)
{
Update.Table("umbracoNode").Set(new {parentID = template.master ?? -1}).Where(new {id = template.nodeId});
Update.Table("umbracoNode").Set(new { parentID = template.master ?? -1 }).Where(new { id = template.nodeId });
//now build the correct path for the template
Update.Table("umbracoNode").Set(new { path = BuildPath (template, templates)}).Where(new { id = template.nodeId });
Update.Table("umbracoNode").Set(new { path = BuildPath(template, templates) }).Where(new { id = template.nodeId });
}
//now remove the master column and key
@@ -46,7 +52,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZe
if (constraints.Any(x => x.Item1.InvariantEquals("cmsTemplate") && x.Item3.InvariantEquals("FK_cmsTemplate_cmsTemplate")))
{
Delete.ForeignKey("FK_cmsTemplate_cmsTemplate").OnTable("cmsTemplate");
Delete.ForeignKey("FK_cmsTemplate_cmsTemplate").OnTable("cmsTemplate");
}
//TODO: Hopefully it's not named something else silly in some crazy old versions
@@ -55,7 +61,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZe
var columns = SqlSyntax.GetColumnsInSchema(Context.Database).Distinct().ToArray();
if (columns.Any(x => x.ColumnName.InvariantEquals("master") && x.TableName.InvariantEquals("cmsTemplate")))
{
Delete.Column("master").FromTable("cmsTemplate");
Delete.Column("master").FromTable("cmsTemplate");
}
}

View File

@@ -4,7 +4,9 @@ using System.Linq;
using System.Text;
using Umbraco.Core.Configuration;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.SqlSyntax;
using File = System.IO.File;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZero
@@ -21,6 +23,11 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZe
[Migration("7.3.0", 2, GlobalSettings.UmbracoMigrationName)]
public class MigrateStylesheetDataToFile : MigrationBase
{
public MigrateStylesheetDataToFile(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
//Don't exeucte if the stylesheet table is not there
@@ -30,7 +37,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZe
//This is all rather nasty but it's how stylesheets used to work in the 2 various ugly ways so we just have to
// deal with that to get this migration done
var tempFolder = IOHelper.MapPath("~/App_Data/TEMP/CssMigration/");
if (Directory.Exists(tempFolder))
{
@@ -44,7 +51,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZe
}
//create the temp folder
var tempDir = Directory.CreateDirectory(IOHelper.MapPath("~/App_Data/TEMP/CssMigration/"));
var sheets = Context.Database.Fetch<dynamic>("SELECT * FROM cmsStylesheet INNER JOIN umbracoNode on cmsStylesheet.nodeId = umbracoNode.id");
foreach (var sheet in sheets)
@@ -55,7 +62,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZe
//we will always use the file content over the db content if there is any
using (var memStream = new MemoryStream(Encoding.UTF8.GetBytes(sheet.content)))
{
dbContent = GetContentAboveUmbracoProps(memStream);
dbContent = GetContentAboveUmbracoProps(memStream);
}
var fileContent = string.Empty;
@@ -69,7 +76,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZe
{
using (var stream = File.OpenRead(filePath))
{
fileContent = GetContentAboveUmbracoProps(stream);
fileContent = GetContentAboveUmbracoProps(stream);
}
}
@@ -86,10 +93,10 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZe
{
if (stylesheetInstance.Properties.Any(x => x.Name == prop.text) == false)
{
stylesheetInstance.AddProperty(new StylesheetProperty(prop.text, prop.stylesheetPropertyAlias, prop.stylesheetPropertyValue));
stylesheetInstance.AddProperty(new StylesheetProperty(prop.text, prop.stylesheetPropertyAlias, prop.stylesheetPropertyValue));
}
}
//Save to temp folder
//ensure the folder for the file exists since it could be in a sub folder
@@ -97,7 +104,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZe
Directory.CreateDirectory(Path.GetDirectoryName(tempFilePath));
File.WriteAllText(tempFilePath, stylesheetInstance.Content, Encoding.UTF8);
}
}

View File

@@ -1,11 +1,18 @@
using System.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZero
{
[Migration("7.3.0", 4, GlobalSettings.UmbracoMigrationName)]
public class RemoveLanguageLocaleColumn : MigrationBase
{
public RemoveLanguageLocaleColumn(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
var columns = SqlSyntax.GetColumnsInSchema(Context.Database).Distinct().ToArray();

View File

@@ -1,12 +1,19 @@
using System;
using System.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZero
{
[Migration("7.3.0", 3, GlobalSettings.UmbracoMigrationName)]
public class RemoveStylesheetDataAndTables : MigrationBase
{
public RemoveStylesheetDataAndTables(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
//Clear all stylesheet data if the tables exist

View File

@@ -1,5 +1,6 @@
using System.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
using Umbraco.Core.Persistence.SqlSyntax;
@@ -10,13 +11,15 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenTwoZero
{
private readonly bool _skipIndexCheck;
internal AddIndexToUmbracoNodeTable(bool skipIndexCheck)
{
_skipIndexCheck = skipIndexCheck;
public AddIndexToUmbracoNodeTable(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public AddIndexToUmbracoNodeTable()
internal AddIndexToUmbracoNodeTable(ISqlSyntaxProvider sqlSyntax, ILogger logger, bool skipIndexCheck)
: base(sqlSyntax, logger)
{
_skipIndexCheck = skipIndexCheck;
}
public override void Up()
@@ -33,7 +36,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenTwoZero
//make sure it doesn't already exist
if (dbIndexes.Any(x => x.IndexName.InvariantEquals("IX_umbracoNodeUniqueID")) == false)
{
Create.Index("IX_umbracoNodeUniqueID").OnTable("umbracoNode").OnColumn("uniqueID").Ascending().WithOptions().NonClustered();
Create.Index("IX_umbracoNodeUniqueID").OnTable("umbracoNode").OnColumn("uniqueID").Ascending().WithOptions().NonClustered();
}
}

View File

@@ -1,6 +1,7 @@
using System.Data;
using System.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
using Umbraco.Core.Persistence.SqlSyntax;
@@ -10,6 +11,11 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenTwoZero
[Migration("7.2.0", 1, GlobalSettings.UmbracoMigrationName)]
public class AddMissingForeignKeyForContentType : MigrationBase
{
public AddMissingForeignKeyForContentType(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
@@ -43,7 +49,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenTwoZero
//Some very old schemas don't have an index on the cmsContentType.nodeId column, I'm not actually sure when it was added but
// it is absolutely required to exist in order to add other foreign keys and much better for perf, so we'll need to check it's existence
// this came to light from this issue: http://issues.umbraco.org/issue/U4-4133
var dbIndexes = SqlSyntaxContext.SqlSyntaxProvider.GetDefinedIndexes(Context.Database)
var dbIndexes = SqlSyntax.GetDefinedIndexes(Context.Database)
.Select(x => new DbIndexDefinition()
{
TableName = x.Item1,
@@ -69,7 +75,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenTwoZero
.OnUpdate(Rule.None);
}
}
public override void Down()

View File

@@ -1,32 +1,38 @@
using System.Linq;
using AutoMapper;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.DatabaseAnnotations;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenTwoZero
{
[Migration("7.2.0", 0, GlobalSettings.UmbracoMigrationName)]
public class AlterDataTypePreValueTable : MigrationBase
{
public AlterDataTypePreValueTable(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
var columns = SqlSyntax.GetColumnsInSchema(Context.Database).Distinct().ToArray();
//Check if it's already text
if (columns.Any(x => x.ColumnName.InvariantEquals("value") && x.TableName.InvariantEquals("cmsDataTypePreValues")
if (columns.Any(x => x.ColumnName.InvariantEquals("value") && x.TableName.InvariantEquals("cmsDataTypePreValues")
//mysql check
&& (x.DataType.InvariantEquals("longtext") == false
//sql server check
&& (x.DataType.InvariantEquals("longtext") == false
//sql server check
&& x.DataType.InvariantEquals("ntext") == false)))
{
//To text
var textType = SqlSyntax.GetSpecialDbType(SpecialDbTypes.NTEXT);
Alter.Table("cmsDataTypePreValues").AlterColumn("value").AsCustom(textType).Nullable();
}
}
public override void Down()

View File

@@ -1,5 +1,6 @@
using System.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenTwoZero
@@ -7,13 +8,18 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenTwoZero
[Migration("7.2.0", 2, GlobalSettings.UmbracoMigrationName)]
public class RemoveCmsDocumentAliasColumn : MigrationBase
{
public RemoveCmsDocumentAliasColumn(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
var columns = SqlSyntax.GetColumnsInSchema(Context.Database).Distinct().ToArray();
if (columns.Any(x => x.ColumnName.InvariantEquals("alias") && x.TableName.InvariantEquals("cmsDocument")))
{
Delete.Column("alias").FromTable("cmsDocument");
Delete.Column("alias").FromTable("cmsDocument");
}
}

View File

@@ -1,13 +1,19 @@
using System.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSix
{
[Migration("6.0.0", 10, GlobalSettings.UmbracoMigrationName)]
public class DeleteAppTables : MigrationBase
{
public DeleteAppTables(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
Delete.Table("umbracoAppTree");
@@ -34,7 +40,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSix
if (constraints.Any(x => x.Item1.InvariantEquals("umbracoUser2app") && x.Item3.InvariantEquals("FK_umbracoUser2app_umbracoUser")))
{
Delete.ForeignKey("FK_umbracoUser2app_umbracoUser").OnTable("umbracoUser2app");
}
}
}
Delete.Table("umbracoApp");

View File

@@ -1,11 +1,18 @@
using System;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSix
{
[Migration("6.0.0", 9, GlobalSettings.UmbracoMigrationName)]
public class EnsureAppsTreesUpdated : MigrationBase
{
public EnsureAppsTreesUpdated(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
var e = new UpgradingEventArgs();
@@ -20,6 +27,6 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSix
public static event EventHandler<UpgradingEventArgs> Upgrading;
public class UpgradingEventArgs : EventArgs{}
public class UpgradingEventArgs : EventArgs { }
}
}

View File

@@ -1,10 +1,17 @@
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSix
{
[Migration("6.0.0", 5, GlobalSettings.UmbracoMigrationName)]
public class MoveMasterContentTypeData : MigrationBase
{
public MoveMasterContentTypeData(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
//Reading entries from the cmsContentType table in order to update the parentID on the umbracoNode table.

View File

@@ -1,10 +1,17 @@
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSix
{
[Migration("6.0.0", 4, GlobalSettings.UmbracoMigrationName)]
public class NewCmsContentType2ContentTypeTable : MigrationBase
{
public NewCmsContentType2ContentTypeTable(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
Create.Table("cmsContentType2ContentType")
@@ -13,7 +20,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSix
Create.PrimaryKey("PK_cmsContentType2ContentType")
.OnTable("cmsContentType2ContentType")
.Columns(new[] {"parentContentTypeId", "childContentTypeId"});
.Columns(new[] { "parentContentTypeId", "childContentTypeId" });
}
public override void Down()

View File

@@ -1,10 +1,17 @@
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSix
{
[Migration("6.0.0", 6, GlobalSettings.UmbracoMigrationName)]
public class RemoveMasterContentTypeColumn : MigrationBase
{
public RemoveMasterContentTypeColumn(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
//NOTE Don't think we can remove this column yet as it seems to be used by some starterkits

View File

@@ -1,10 +1,17 @@
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSix
{
[Migration("6.0.0", 0, GlobalSettings.UmbracoMigrationName)]
public class RenameCmsTabTable : MigrationBase
{
public RenameCmsTabTable(ISqlSyntaxProvider sqlSyntax, ILogger logger)
: base(sqlSyntax, logger)
{
}
public override void Up()
{
Rename.Table("cmsTab").To("cmsPropertyTypeGroup");

Some files were not shown because too many files have changed in this diff Show More