diff --git a/src/Umbraco.Core/Persistence/DatabaseSchemaHelper.cs b/src/Umbraco.Core/Persistence/DatabaseSchemaHelper.cs
index 304cdc185f..f4cf7b23e9 100644
--- a/src/Umbraco.Core/Persistence/DatabaseSchemaHelper.cs
+++ b/src/Umbraco.Core/Persistence/DatabaseSchemaHelper.cs
@@ -1,6 +1,5 @@
using System;
using System.Linq;
-using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
@@ -11,6 +10,9 @@ using Umbraco.Core.Services;
namespace Umbraco.Core.Persistence
{
+ ///
+ /// Helper class for working with databases and schemas.
+ ///
public class DatabaseSchemaHelper
{
private readonly Database _db;
@@ -18,6 +20,22 @@ namespace Umbraco.Core.Persistence
private readonly ISqlSyntaxProvider _syntaxProvider;
private readonly BaseDataCreation _baseDataCreation;
+ ///
+ /// Intializes a new helper instance.
+ ///
+ /// The database to be used.
+ /// The logger.
+ /// The syntax provider.
+ ///
+ /// A new instance could be initialized like:
+ ///
+ /// var schemaHelper = new DatabaseSchemaHelper(
+ /// ApplicationContext.Current.DatabaseContext.Database,
+ /// ApplicationContext.Current.ProfilingLogger.Logger,
+ /// ApplicationContext.Current.DatabaseContext.SqlSyntax
+ /// );
+ ///
+ ///
public DatabaseSchemaHelper(Database db, ILogger logger, ISqlSyntaxProvider syntaxProvider)
{
_db = db;
@@ -26,11 +44,41 @@ namespace Umbraco.Core.Persistence
_baseDataCreation = new BaseDataCreation(db, logger);
}
+ ///
+ /// Returns whether a table with the specified exists in the database.
+ ///
+ /// The name of the table.
+ /// true if the table exists; otherwise false.
+ ///
+ ///
+ /// if (schemaHelper.TableExist("MyTable"))
+ /// {
+ /// // do something when the table exists
+ /// }
+ ///
+ ///
public bool TableExist(string tableName)
{
return _syntaxProvider.DoesTableExist(_db, tableName);
}
+ ///
+ /// Returns whether the table for the specified exists in the database.
+ ///
+ /// If has been decorated with an , the name from that
+ /// attribute will be used for the table name. If the attribute is not present, the name
+ /// will be used instead.
+ ///
+ /// The type representing the DTO/table.
+ /// true if the table exists; otherwise false.
+ ///
+ ///
+ /// if (schemaHelper.TableExist<MyDto>)
+ /// {
+ /// // do something when the table exists
+ /// }
+ ///
+ ///
public bool TableExist()
{
var poco = Database.PocoData.ForType(typeof(T));
@@ -90,6 +138,17 @@ namespace Umbraco.Core.Persistence
_logger.Info("Finalized database schema creation");
}
+ /// Creates a new table in the database based on the type of .
+ ///
+ /// If has been decorated with an , the name from that
+ /// attribute will be used for the table name. If the attribute is not present, the name
+ /// will be used instead.
+ ///
+ /// If a table with the same name already exists, the parameter will determine
+ /// whether the table is overwritten. If true, the table will be overwritten, whereas this method will
+ /// not do anything if the parameter is false.
+ /// The type representing the DTO/table.
+ /// Whether the table should be overwritten if it already exists.
public void CreateTable(bool overwrite)
where T : new()
{
@@ -97,6 +156,16 @@ namespace Umbraco.Core.Persistence
CreateTable(overwrite, tableType);
}
+ ///
+ /// Creates a new table in the database based on the type of .
+ ///
+ /// If has been decorated with an , the name from that
+ /// attribute will be used for the table name. If the attribute is not present, the name
+ /// will be used instead.
+ ///
+ /// If a table with the same name already exists, this method will not do anything.
+ ///
+ /// The type representing the DTO/table.
public void CreateTable()
where T : new()
{
@@ -104,6 +173,19 @@ namespace Umbraco.Core.Persistence
CreateTable(false, tableType);
}
+ ///
+ /// Creates a new table in the database for the specified .
+ ///
+ /// If has been decorated with an , the name from
+ /// that attribute will be used for the table name. If the attribute is not present, the name
+ /// will be used instead.
+ ///
+ /// If a table with the same name already exists, the parameter will determine
+ /// whether the table is overwritten. If true, the table will be overwritten, whereas this method will
+ /// not do anything if the parameter is false.
+ ///
+ /// Whether the table should be overwritten if it already exists.
+ /// The the representing the table.
public void CreateTable(bool overwrite, Type modelType)
{
var tableDefinition = DefinitionFactory.GetTableDefinition(_syntaxProvider, modelType);
@@ -189,6 +271,19 @@ namespace Umbraco.Core.Persistence
}
}
+ ///
+ /// Drops the table for the specified .
+ ///
+ /// If has been decorated with an , the name from that
+ /// attribute will be used for the table name. If the attribute is not present, the name
+ /// will be used instead.
+ ///
+ /// The type representing the DTO/table.
+ ///
+ ///
+ /// schemaHelper.DropTable<MyDto>);
+ ///
+ ///
public void DropTable()
where T : new()
{
@@ -204,6 +299,15 @@ namespace Umbraco.Core.Persistence
DropTable(tableName);
}
+ ///
+ /// Drops the table with the specified .
+ ///
+ /// The name of the table.
+ ///
+ ///
+ /// schemaHelper.DropTable("MyTable");
+ ///
+ ///
public void DropTable(string tableName)
{
var sql = new Sql(string.Format(