diff --git a/src/Umbraco.Core/Models/Rdbms/AppDto.cs b/src/Umbraco.Core/Models/Rdbms/AppDto.cs index a53fe2af91..31a3b3fe12 100644 --- a/src/Umbraco.Core/Models/Rdbms/AppDto.cs +++ b/src/Umbraco.Core/Models/Rdbms/AppDto.cs @@ -14,20 +14,16 @@ namespace Umbraco.Core.Models.Rdbms public string AppAlias { get; set; } [Column("appIcon")] - [DatabaseType(DatabaseTypes.Nvarchar, Length = 255)] public string AppIcon { get; set; } [Column("appName")] - [DatabaseType(DatabaseTypes.Nvarchar, Length = 255)] public string AppName { get; set; } [Column("appInitWithTreeAlias")] [NullSetting(NullSetting = NullSettings.Null)] - [DatabaseType(DatabaseTypes.Nvarchar, Length = 255)] public string AppInitWithTreeAlias { get; set; } [Column("sortOrder")] - [DatabaseType(DatabaseTypes.TinyInteger)] [Constraint(Name = "DF_app_sortOrder", Default = "0")] public byte SortOrder { get; set; } } diff --git a/src/Umbraco.Core/Models/Rdbms/AppTreeDto.cs b/src/Umbraco.Core/Models/Rdbms/AppTreeDto.cs index 81d70eb3d4..cab38fa201 100644 --- a/src/Umbraco.Core/Models/Rdbms/AppTreeDto.cs +++ b/src/Umbraco.Core/Models/Rdbms/AppTreeDto.cs @@ -1,4 +1,5 @@ using Umbraco.Core.Persistence; +using Umbraco.Core.Persistence.DatabaseAnnotations; namespace Umbraco.Core.Models.Rdbms { @@ -8,15 +9,18 @@ namespace Umbraco.Core.Models.Rdbms internal class AppTreeDto { [Column("treeSilent")] + [Constraint(Default = "0")] public bool Silent { get; set; } [Column("treeInitialize")] + [Constraint(Default = "1")] public bool Initialize { get; set; } [Column("treeSortOrder")] public byte SortOrder { get; set; } [Column("appAlias")] + [PrimaryKeyColumn(AutoIncrement = false, Clustered = true, Name = "PK_umbracoAppTree", OnColumns = "[appAlias], [treeAlias]")] public string AppAlias { get; set; } [Column("treeAlias")] @@ -38,6 +42,7 @@ namespace Umbraco.Core.Models.Rdbms public string HandlerType { get; set; } [Column("action")] + [NullSetting(NullSetting = NullSettings.Null)] public string Action { get; set; } } } \ No newline at end of file diff --git a/src/Umbraco.Core/Models/Rdbms/ContentDto.cs b/src/Umbraco.Core/Models/Rdbms/ContentDto.cs index 4ad49bc367..1607df2d10 100644 --- a/src/Umbraco.Core/Models/Rdbms/ContentDto.cs +++ b/src/Umbraco.Core/Models/Rdbms/ContentDto.cs @@ -10,19 +10,16 @@ namespace Umbraco.Core.Models.Rdbms { [Column("pk")] [PrimaryKeyColumn] - [DatabaseType(DatabaseTypes.Integer)] [NullSetting(NullSetting = NullSettings.Null)] public int PrimaryKey { get; set; } [Column("nodeId")] [ForeignKey(typeof(NodeDto))] - [DatabaseType(DatabaseTypes.Integer)] [NullSetting(NullSetting = NullSettings.Null)] - [Index(IndexTypes.UniqueNonclustered, Name = "IX_cmsContent")] + [Index(IndexTypes.UniqueNonClustered, Name = "IX_cmsContent")] public int NodeId { get; set; } [Column("contentType")] - [DatabaseType(DatabaseTypes.Integer)] [NullSetting(NullSetting = NullSettings.Null)] public int ContentType { get; set; } diff --git a/src/Umbraco.Core/Models/Rdbms/ContentType2ContentTypeDto.cs b/src/Umbraco.Core/Models/Rdbms/ContentType2ContentTypeDto.cs index 0417aaad1b..c156003bfb 100644 --- a/src/Umbraco.Core/Models/Rdbms/ContentType2ContentTypeDto.cs +++ b/src/Umbraco.Core/Models/Rdbms/ContentType2ContentTypeDto.cs @@ -1,4 +1,5 @@ using Umbraco.Core.Persistence; +using Umbraco.Core.Persistence.DatabaseAnnotations; namespace Umbraco.Core.Models.Rdbms { @@ -7,6 +8,7 @@ namespace Umbraco.Core.Models.Rdbms internal class ContentType2ContentTypeDto { [Column("parentContentTypeId")] + [PrimaryKeyColumn(AutoIncrement = false, Clustered = true, Name = "PK_cmsContentType2ContentType", OnColumns = "[parentContentTypeId], [childContentTypeId]")] public int ParentId { get; set; } [Column("childContentTypeId")] diff --git a/src/Umbraco.Core/Models/Rdbms/ContentTypeAllowedContentTypeDto.cs b/src/Umbraco.Core/Models/Rdbms/ContentTypeAllowedContentTypeDto.cs index 9c3e2ad6a8..ae623ca0a4 100644 --- a/src/Umbraco.Core/Models/Rdbms/ContentTypeAllowedContentTypeDto.cs +++ b/src/Umbraco.Core/Models/Rdbms/ContentTypeAllowedContentTypeDto.cs @@ -1,4 +1,5 @@ using Umbraco.Core.Persistence; +using Umbraco.Core.Persistence.DatabaseAnnotations; namespace Umbraco.Core.Models.Rdbms { @@ -8,12 +9,16 @@ namespace Umbraco.Core.Models.Rdbms internal class ContentTypeAllowedContentTypeDto { [Column("Id")] + [ForeignKey(typeof(ContentTypeDto), Name = "FK_cmsContentTypeAllowedContentType_cmsContentType")] + [PrimaryKeyColumn(AutoIncrement = false, Clustered = true, Name = "PK_cmsContentTypeAllowedContentType", OnColumns = "[Id], [AllowedId]")] public int Id { get; set; } [Column("AllowedId")] + [ForeignKey(typeof(ContentTypeDto), Name = "FK_cmsContentTypeAllowedContentType_cmsContentType1")] public int AllowedId { get; set; } [Column("SortOrder")] + [Constraint(Name = "df_cmsContentTypeAllowedContentType_sortOrder", Default = "0")] public int SortOrder { get; set; } } } \ No newline at end of file diff --git a/src/Umbraco.Core/Models/Rdbms/ContentTypeDto.cs b/src/Umbraco.Core/Models/Rdbms/ContentTypeDto.cs index 1d97d24369..cd254a18ed 100644 --- a/src/Umbraco.Core/Models/Rdbms/ContentTypeDto.cs +++ b/src/Umbraco.Core/Models/Rdbms/ContentTypeDto.cs @@ -1,4 +1,5 @@ using Umbraco.Core.Persistence; +using Umbraco.Core.Persistence.DatabaseAnnotations; namespace Umbraco.Core.Models.Rdbms { @@ -8,27 +9,38 @@ namespace Umbraco.Core.Models.Rdbms internal class ContentTypeDto { [Column("pk")] + [PrimaryKeyColumn] public int PrimaryKey { get; set; } [Column("nodeId")] + [ForeignKey(typeof(NodeDto))] + [Index(IndexTypes.UniqueNonClustered, Name = "IX_cmsContentType")] public int NodeId { get; set; } [Column("alias")] + [NullSetting(NullSetting = NullSettings.Null)] public string Alias { get; set; } [Column("icon")] + [Index(IndexTypes.NonClustered)] + [NullSetting(NullSetting = NullSettings.Null)] public string Icon { get; set; } [Column("thumbnail")] + [Constraint(Default = "'folder.png'")] public string Thumbnail { get; set; } [Column("description")] + [NullSetting(NullSetting = NullSettings.Null)] + [DatabaseType(DatabaseTypes.Nvarchar, Length = 1500)] public string Description { get; set; } [Column("isContainer")] + [Constraint(Default = "0")] public bool IsContainer { get; set; } [Column("allowAtRoot")] + [Constraint(Default = "0")] public bool AllowAtRoot { get; set; } [ResultColumn] diff --git a/src/Umbraco.Core/Models/Rdbms/NodeDto.cs b/src/Umbraco.Core/Models/Rdbms/NodeDto.cs index fe46d22a86..78cab99f35 100644 --- a/src/Umbraco.Core/Models/Rdbms/NodeDto.cs +++ b/src/Umbraco.Core/Models/Rdbms/NodeDto.cs @@ -22,7 +22,7 @@ namespace Umbraco.Core.Models.Rdbms [Column("parentID")] [DatabaseType(DatabaseTypes.Integer)] [ForeignKey(typeof(NodeDto))] - [IndexAttribute(IndexTypes.Nonclustered, Name = "IX_umbracoNodeParentId")] + [IndexAttribute(IndexTypes.NonClustered, Name = "IX_umbracoNodeParentId")] public int ParentId { get; set; } [Column("nodeUser")] @@ -55,7 +55,7 @@ namespace Umbraco.Core.Models.Rdbms [Column("nodeObjectType")] [DatabaseType(DatabaseTypes.UniqueIdentifier)] [NullSetting(NullSetting = NullSettings.Null)] - [IndexAttribute(IndexTypes.Nonclustered, Name = "IX_umbracoNodeObjectType")] + [IndexAttribute(IndexTypes.NonClustered, Name = "IX_umbracoNodeObjectType")] public Guid? NodeObjectType { get; set; } [Column("createDate")] diff --git a/src/Umbraco.Core/Persistence/DatabaseAnnotations/AttributeExtensions.cs b/src/Umbraco.Core/Persistence/DatabaseAnnotations/AttributeExtensions.cs index c21b10a675..80fd277a99 100644 --- a/src/Umbraco.Core/Persistence/DatabaseAnnotations/AttributeExtensions.cs +++ b/src/Umbraco.Core/Persistence/DatabaseAnnotations/AttributeExtensions.cs @@ -57,7 +57,7 @@ string syntax = string.Empty; if (attribute.AutoIncrement) - syntax = "IDENTITY(1, 1)"; + syntax = " IDENTITY(1, 1)"; return syntax; } @@ -70,8 +70,11 @@ if (DatabaseFactory.Current.DatabaseProvider == DatabaseProviders.SqlServerCE) clustered = string.Empty; - string syntax = string.Format("ALTER TABLE [{0}] ADD CONSTRAINT [{1}] PRIMARY KEY {2} ([{3}])", tableName, - constraintName, clustered, propertyName); + string syntax = string.IsNullOrEmpty(attribute.OnColumns) + ? string.Format("ALTER TABLE [{0}] ADD CONSTRAINT [{1}] PRIMARY KEY {2} ([{3}])", + tableName, constraintName, clustered, propertyName) + : string.Format("ALTER TABLE [{0}] ADD CONSTRAINT [{1}] PRIMARY KEY {2} ({3})", + tableName, constraintName, clustered, attribute.OnColumns); return syntax; } @@ -90,7 +93,9 @@ var primaryKeyAttribute = attribute.Type.FirstAttribute(); var referencedTableName = tableNameAttribute.Value; - string constraintName = string.Format("FK_{0}_{1}", tableName, referencedTableName); + string constraintName = string.IsNullOrEmpty(attribute.Name) + ? string.Format("FK_{0}_{1}", tableName, referencedTableName) + : attribute.Name; string syntax = string.Format( "ALTER TABLE [{0}] ADD CONSTRAINT [{1}] FOREIGN KEY ([{2}]) REFERENCES [{3}] ([{4}])", @@ -107,7 +112,7 @@ case IndexTypes.Clustered: indexType = "CLUSTERED"; break; - case IndexTypes.Nonclustered: + case IndexTypes.NonClustered: indexType = "NONCLUSTERED"; break; case IndexTypes.PrimaryXml: @@ -116,8 +121,8 @@ case IndexTypes.Spartial: indexType = "SPARTIAL"; break; - case IndexTypes.UniqueNonclustered: - indexType = "UNIQUENONCLUSTERED"; + case IndexTypes.UniqueNonClustered: + indexType = "UNIQUE NONCLUSTERED"; break; } string name = string.IsNullOrEmpty(attribute.Name) ? string.Format("IX_{0}_{1}", tableName, propertyName) : attribute.Name; diff --git a/src/Umbraco.Core/Persistence/DatabaseAnnotations/ForeignKeyAttribute.cs b/src/Umbraco.Core/Persistence/DatabaseAnnotations/ForeignKeyAttribute.cs index 5796826016..4c4eb91876 100644 --- a/src/Umbraco.Core/Persistence/DatabaseAnnotations/ForeignKeyAttribute.cs +++ b/src/Umbraco.Core/Persistence/DatabaseAnnotations/ForeignKeyAttribute.cs @@ -12,6 +12,6 @@ namespace Umbraco.Core.Persistence.DatabaseAnnotations public string OnDelete { get; set; } public string OnUpdate { get; set; } - //Default naming: FK_thisTableName_refTableName + public string Name { get; set; }//Used to override Default naming: FK_thisTableName_refTableName } } \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/DatabaseAnnotations/IndexTypes.cs b/src/Umbraco.Core/Persistence/DatabaseAnnotations/IndexTypes.cs index 97f3680aa7..21d718065d 100644 --- a/src/Umbraco.Core/Persistence/DatabaseAnnotations/IndexTypes.cs +++ b/src/Umbraco.Core/Persistence/DatabaseAnnotations/IndexTypes.cs @@ -3,8 +3,8 @@ public enum IndexTypes { Clustered, - Nonclustered, - UniqueNonclustered, + NonClustered, + UniqueNonClustered, PrimaryXml, Spartial } diff --git a/src/Umbraco.Core/Persistence/DatabaseAnnotations/PrimaryKeyColumnAttribute.cs b/src/Umbraco.Core/Persistence/DatabaseAnnotations/PrimaryKeyColumnAttribute.cs index 20e56b84c3..784cf80af6 100644 --- a/src/Umbraco.Core/Persistence/DatabaseAnnotations/PrimaryKeyColumnAttribute.cs +++ b/src/Umbraco.Core/Persistence/DatabaseAnnotations/PrimaryKeyColumnAttribute.cs @@ -14,5 +14,6 @@ namespace Umbraco.Core.Persistence.DatabaseAnnotations public bool Clustered { get; set; }//Defaults to true public bool AutoIncrement { get; set; }//Default to true public string Name { get; set; }//Overrides the default naming of a PrimaryKey constraint: PK_tableName + public string OnColumns { get; set; } } } \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Migrations/AddColumnChange.cs b/src/Umbraco.Core/Persistence/Migrations/AddColumnChange.cs deleted file mode 100644 index e154f61c2a..0000000000 --- a/src/Umbraco.Core/Persistence/Migrations/AddColumnChange.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Umbraco.Core.Persistence.DatabaseAnnotations; - -namespace Umbraco.Core.Persistence.Migrations -{ - /// - /// Represents an abstract class for descriping changes to a database column - /// Used to Add a column with an optional constraint - /// - public abstract class AddColumnChange : DropColumnChange - { - public abstract string Constraint { get; } - - public abstract string DefaultForConstraint { get; } - - public abstract DatabaseTypes DatabaseType { get; } - - public virtual int DatabaseTypeLength - { - get { return 0; } - } - - public abstract NullSettings NullSetting { get; } - - public override Sql ToSql() - { - var sql = new Sql(); - - string constraint = !string.IsNullOrEmpty(Constraint) - ? string.Format("CONSTRAINT [{0}] DEFAULT ({1})", Constraint, DefaultForConstraint) - : string.Format("CONSTRAINT [DF_{0}_{1}] DEFAULT ({2})", TableName, ColumnName, - DefaultForConstraint); - - sql.Append(string.Format("ALTER TABLE [{0}] ADD [{1}] {2} {3} {4};", - TableName, ColumnName, - DatabaseType.ToSqlSyntax(DatabaseTypeLength), - NullSetting.ToSqlSyntax(), - constraint)); - return sql; - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Migrations/BaseChange.cs b/src/Umbraco.Core/Persistence/Migrations/BaseChange.cs deleted file mode 100644 index bf31dcbe88..0000000000 --- a/src/Umbraco.Core/Persistence/Migrations/BaseChange.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Umbraco.Core.Persistence.Migrations -{ - public abstract class BaseChange : IDatabaseChange - { - public abstract Sql ToSql(); - - public abstract string TableName { get; } - - public abstract string Version { get; } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Migrations/ChangeTypes.cs b/src/Umbraco.Core/Persistence/Migrations/ChangeTypes.cs deleted file mode 100644 index 51275e2da5..0000000000 --- a/src/Umbraco.Core/Persistence/Migrations/ChangeTypes.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Umbraco.Core.Persistence.Migrations -{ - public enum ChangeTypes - { - ADD, - DROP, - RENAME - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Migrations/ConstraintChange.cs b/src/Umbraco.Core/Persistence/Migrations/ConstraintChange.cs deleted file mode 100644 index 61d3efe9ec..0000000000 --- a/src/Umbraco.Core/Persistence/Migrations/ConstraintChange.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Umbraco.Core.Persistence.Migrations -{ - /// - /// Represents an abstract class for descriping changes to a database constraint - /// Used to Add, Remove or Rename a constraint - /// - public abstract class ConstraintChange - { - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Migrations/DatabaseTypeChange.cs b/src/Umbraco.Core/Persistence/Migrations/DatabaseTypeChange.cs deleted file mode 100644 index 5880170024..0000000000 --- a/src/Umbraco.Core/Persistence/Migrations/DatabaseTypeChange.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Umbraco.Core.Persistence.Migrations -{ - /// - /// Represents an abstract class for descriping changes to a database column's type - /// Used to Add, Remove or Change (increase/decrease length) a column's database - /// - public abstract class DatabaseTypeChange - { - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Migrations/DropColumnChange.cs b/src/Umbraco.Core/Persistence/Migrations/DropColumnChange.cs deleted file mode 100644 index 0657537d27..0000000000 --- a/src/Umbraco.Core/Persistence/Migrations/DropColumnChange.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Umbraco.Core.Persistence.DatabaseAnnotations; - -namespace Umbraco.Core.Persistence.Migrations -{ - /// - /// Represents an abstract class for descriping changes to a database column - /// Used to Remove a column - /// - public abstract class DropColumnChange : BaseChange - { - public abstract string ColumnName { get; } - - public virtual ChangeTypes ChangeType - { - get - { - return ChangeTypes.DROP; - } - } - - public override Sql ToSql() - { - var sql = new Sql(); - sql.Append(string.Format("ALTER TABLE [{0}] DROP COLUMN [{1}];", - TableName, ColumnName)); - return sql; - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Migrations/ForeignKeyChange.cs b/src/Umbraco.Core/Persistence/Migrations/ForeignKeyChange.cs deleted file mode 100644 index a05aa92587..0000000000 --- a/src/Umbraco.Core/Persistence/Migrations/ForeignKeyChange.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Umbraco.Core.Persistence.Migrations -{ - /// - /// Represents an abstract class for descriping changes to a database column's foreign key - /// Used to Add, Remove or Rename a column's foreign key - /// - public abstract class ForeignKeyChange - { - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Migrations/IDatabaseChange.cs b/src/Umbraco.Core/Persistence/Migrations/IDatabaseChange.cs deleted file mode 100644 index b19ee80657..0000000000 --- a/src/Umbraco.Core/Persistence/Migrations/IDatabaseChange.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Umbraco.Core.Persistence.Migrations -{ - public interface IDatabaseChange - { - string Version { get; } - Sql ToSql(); - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Migrations/IndexChange.cs b/src/Umbraco.Core/Persistence/Migrations/IndexChange.cs deleted file mode 100644 index fdb935df6f..0000000000 --- a/src/Umbraco.Core/Persistence/Migrations/IndexChange.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Umbraco.Core.Persistence.Migrations -{ - /// - /// Represents an abstract class for descriping changes to a database index - /// Used to Add, Remove or Rename an index - /// - public abstract class IndexChange - { - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Migrations/TableChange.cs b/src/Umbraco.Core/Persistence/Migrations/TableChange.cs deleted file mode 100644 index 838e36c77f..0000000000 --- a/src/Umbraco.Core/Persistence/Migrations/TableChange.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Umbraco.Core.Persistence.Migrations -{ - /// - /// Represents an abstract class for descriping changes to a database table. - /// Used to create or drop tables - /// - public abstract class TableChange - { - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/PetaPocoExtensions.cs b/src/Umbraco.Core/Persistence/PetaPocoExtensions.cs index 2b40b5ed64..87066c1979 100644 --- a/src/Umbraco.Core/Persistence/PetaPocoExtensions.cs +++ b/src/Umbraco.Core/Persistence/PetaPocoExtensions.cs @@ -38,6 +38,11 @@ namespace Umbraco.Core.Persistence var last = objProperties.Last(); foreach (var propertyInfo in objProperties) { + //If current property is a ResultColumn then skip it + var resultColumnAttribute = propertyInfo.FirstAttribute(); + if(resultColumnAttribute != null) continue; + + //Assumes ExplicitColumn attribute and thus having a ColumnAttribute with the name of the column var columnAttribute = propertyInfo.FirstAttribute(); if(columnAttribute == null) continue; @@ -52,6 +57,31 @@ namespace Umbraco.Core.Persistence else { //Convetion - Use property's Type to set/find db type + //TODO Improve :) + if(propertyInfo.PropertyType == typeof(string)) + { + sb.AppendFormat(" [nvarchar] (255)"); + } + else if (propertyInfo.PropertyType == typeof(int)) + { + sb.AppendFormat(" [int]"); + } + else if (propertyInfo.PropertyType == typeof(bool)) + { + sb.AppendFormat(" [bit]"); + } + else if (propertyInfo.PropertyType == typeof(byte)) + { + sb.AppendFormat(" [tinyint]"); + } + else if (propertyInfo.PropertyType == typeof(DateTime)) + { + sb.AppendFormat(" [datetime]"); + } + else if (propertyInfo.PropertyType == typeof(Guid)) + { + sb.AppendFormat(" [uniqueidentifier]"); + } } var nullSettingAttribute = propertyInfo.FirstAttribute(); @@ -68,7 +98,7 @@ namespace Umbraco.Core.Persistence var primaryKeyColumnAttribute = propertyInfo.FirstAttribute(); if(primaryKeyColumnAttribute != null) { - sb.AppendFormat(" {0}", primaryKeyColumnAttribute.ToSqlSyntax()); + sb.Append(primaryKeyColumnAttribute.ToSqlSyntax()); //Add to list of primary key constraints primaryKeyConstraints.Add(new Sql(primaryKeyColumnAttribute.ToSqlSyntax(tableName, columnAttribute.Name))); } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index efd5386f17..285fe765c4 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -105,7 +105,6 @@ - @@ -132,16 +131,7 @@ - - - - - - - - - diff --git a/src/Umbraco.Tests/Persistence/DatabaseExtensionsTest.cs b/src/Umbraco.Tests/Persistence/DatabaseExtensionsTest.cs index 03f1c0cdeb..83e7856832 100644 --- a/src/Umbraco.Tests/Persistence/DatabaseExtensionsTest.cs +++ b/src/Umbraco.Tests/Persistence/DatabaseExtensionsTest.cs @@ -33,7 +33,7 @@ namespace Umbraco.Tests.Persistence engine.CreateDatabase(); //Create the umbraco database - DatabaseFactory.Current.Database.Initialize(); + //DatabaseFactory.Current.Database.Initialize(); } [Test] @@ -59,5 +59,42 @@ namespace Umbraco.Tests.Persistence //transaction.Complete(); } } + + [Test] + public void Can_Create_umbracoAppTree_Table() + { + var factory = DatabaseFactory.Current; + using (Transaction transaction = factory.Database.GetTransaction()) + { + factory.Database.CreateTable(); + + //transaction.Complete(); + } + } + + [Test] + public void Can_Create_cmsContentType2ContentType_Table() + { + var factory = DatabaseFactory.Current; + using (Transaction transaction = factory.Database.GetTransaction()) + { + factory.Database.CreateTable(); + + //transaction.Complete(); + } + } + + [Test, NUnit.Framework.Ignore] + public void Can_Create_cmsContentTypeAllowedContentType_Table() + { + var factory = DatabaseFactory.Current; + using (Transaction transaction = factory.Database.GetTransaction()) + { + //Requires the cmsContentType table in order to create refecences + factory.Database.CreateTable(); + + //transaction.Complete(); + } + } } } \ No newline at end of file diff --git a/src/Umbraco.Tests/Persistence/MigrationTests.cs b/src/Umbraco.Tests/Persistence/MigrationTests.cs deleted file mode 100644 index 2964bb001f..0000000000 --- a/src/Umbraco.Tests/Persistence/MigrationTests.cs +++ /dev/null @@ -1,28 +0,0 @@ -using NUnit.Framework; -using Umbraco.Core.Persistence; -using Umbraco.Tests.TestHelpers.MockedMigrations; - -namespace Umbraco.Tests.Persistence -{ - [TestFixture] - public class MigrationTests - { - [Test] - public void Can_Verify_Add_ColumnChange() - { - var columnChange = new AddAllowAtRootColumn(); - Sql sql = columnChange.ToSql(); - - Assert.AreEqual(sql.SQL, "ALTER TABLE [cmsContentType] ADD [allowAtRoot] [bit] NOT NULL CONSTRAINT [df_cmsContentType_allowAtRoot] DEFAULT (0);"); - } - - [Test] - public void Can_Verify_Drop_ColumnChange() - { - var columnChange = new DropMasterContentTypeColumn(); - Sql sql = columnChange.ToSql(); - - Assert.AreEqual(sql.SQL, "ALTER TABLE [cmsContentType] DROP COLUMN [masterContentType];"); - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Tests/TestHelpers/MockedMigrations/AddAllowAtRootColumn.cs b/src/Umbraco.Tests/TestHelpers/MockedMigrations/AddAllowAtRootColumn.cs deleted file mode 100644 index 8f2bceb8ed..0000000000 --- a/src/Umbraco.Tests/TestHelpers/MockedMigrations/AddAllowAtRootColumn.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Umbraco.Core.Persistence.DatabaseAnnotations; -using Umbraco.Core.Persistence.Migrations; - -namespace Umbraco.Tests.TestHelpers.MockedMigrations -{ - /// - /// Mocked Column Change that'll generate the following sql: - /// ALTER TABLE [cmsContentType] - /// ADD [allowAtRoot] bit NOT NULL - /// CONSTRAINT [df_cmsContentType_allowAtRoot] DEFAULT 0 - /// - public class AddAllowAtRootColumn : AddColumnChange - { - public override string TableName - { - get { return "cmsContentType"; } - } - - public override string Version - { - get { return "4.10.0"; } - } - - public override string ColumnName - { - get { return "allowAtRoot"; } - } - - public override string Constraint - { - get { return "df_cmsContentType_allowAtRoot"; } - } - - public override string DefaultForConstraint - { - get { return "0"; } - } - - public override DatabaseTypes DatabaseType - { - get { return DatabaseTypes.Bool; } - } - - public override NullSettings NullSetting - { - get { return NullSettings.NotNull; } - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Tests/TestHelpers/MockedMigrations/DropMasterContentTypeColumn.cs b/src/Umbraco.Tests/TestHelpers/MockedMigrations/DropMasterContentTypeColumn.cs deleted file mode 100644 index 6ee431b07d..0000000000 --- a/src/Umbraco.Tests/TestHelpers/MockedMigrations/DropMasterContentTypeColumn.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Umbraco.Core.Persistence.Migrations; - -namespace Umbraco.Tests.TestHelpers.MockedMigrations -{ - /// - /// Mocked Column Change that'll generate the following sql: - /// ALTER TABLE [cmsContentType] DROP COLUMN [masterContentType]; - /// - public class DropMasterContentTypeColumn : DropColumnChange - { - public override string Version - { - get { return "4.10.0"; } - } - - public override string TableName - { - get { return "cmsContentType"; } - } - - public override string ColumnName - { - get { return "masterContentType"; } - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index cef8489396..3f874c22c0 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -92,7 +92,6 @@ - @@ -129,8 +128,6 @@ - -