-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added composer, model and components for migration
- Loading branch information
Imran
committed
Nov 11, 2020
1 parent
93d5ce4
commit 83df507
Showing
5 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
Source/BackOfficeContentBlocker.Core/Components/BackOfficeContentBlockerComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using BackOfficeContentBlocker.Core.Migrations; | ||
using Umbraco.Core.Composing; | ||
using Umbraco.Core.Logging; | ||
using Umbraco.Core.Migrations; | ||
using Umbraco.Core.Migrations.Upgrade; | ||
using Umbraco.Core.Scoping; | ||
using Umbraco.Core.Services; | ||
|
||
namespace BackOfficeContentBlocker.Core.Components | ||
{ | ||
public class BackOfficeContentBlockerComponent : IComponent | ||
{ | ||
private readonly IScopeProvider _scopeProvider; | ||
private readonly IMigrationBuilder _migrationBuilder; | ||
private readonly IKeyValueService _keyValueService; | ||
private readonly ILogger _logger; | ||
|
||
public BackOfficeContentBlockerComponent(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, | ||
IKeyValueService keyValueService, ILogger logger) | ||
{ | ||
_scopeProvider = scopeProvider; | ||
_migrationBuilder = migrationBuilder; | ||
_keyValueService = keyValueService; | ||
_logger = logger; | ||
} | ||
|
||
public void Initialize() | ||
{ | ||
// Create a migration plan for a specific project/feature | ||
// We can then track that latest migration state/step for this project/feature | ||
var migrationPlan = new MigrationPlan("BackOfficeContentBlocker"); | ||
|
||
// This is the steps we need to take | ||
// Each step in the migration adds a unique value | ||
migrationPlan.From(string.Empty) | ||
.To<AddBackOfficeContentBlockerTable>("backofficecontentblocker-db"); | ||
|
||
// Go and upgrade our site (Will check if it needs to do the work or not) | ||
// Based on the current/latest step | ||
var upgrader = new Upgrader(migrationPlan); | ||
|
||
upgrader.Execute(_scopeProvider, _migrationBuilder, _keyValueService, _logger); | ||
} | ||
|
||
public void Terminate() | ||
{ | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Source/BackOfficeContentBlocker.Core/Composers/BackOfficeContentBlockerComposer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using BackOfficeContentBlocker.Core.Components; | ||
using Umbraco.Core; | ||
using Umbraco.Core.Composing; | ||
|
||
namespace BackOfficeContentBlocker.Core.Composers | ||
{ | ||
[RuntimeLevel(MinLevel = RuntimeLevel.Run)] | ||
public class BackOfficeContentBlockerComposer : ComponentComposer<BackOfficeContentBlockerComponent> | ||
{ | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Source/BackOfficeContentBlocker.Core/Migrations/AddCommentsTable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using BackOfficeContentBlocker.Core.Models.Schemas; | ||
using Umbraco.Core.Logging; | ||
using Umbraco.Core.Migrations; | ||
|
||
namespace BackOfficeContentBlocker.Core.Migrations | ||
{ | ||
public class AddBackOfficeContentBlockerTable : MigrationBase | ||
{ | ||
public AddBackOfficeContentBlockerTable(IMigrationContext context) : base(context) | ||
{ | ||
} | ||
|
||
public override void Migrate() | ||
{ | ||
Logger.Debug<AddBackOfficeContentBlockerTable>("Running migration {MigrationStep}", "AddCommentsTable"); | ||
|
||
// Lots of methods available in the MigrationBase class - discover with this. | ||
if (TableExists("BackOfficeContentBlocker") == false) | ||
{ | ||
Create.Table<BackOfficeContentBlockerSchema>().Do(); | ||
} | ||
else | ||
{ | ||
Logger.Debug<AddBackOfficeContentBlockerTable>("The database table {DbTable} already exists, skipping", | ||
"BlogComments"); | ||
} | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Source/BackOfficeContentBlocker.Core/Models/Schemas/BackOfficeContentBlockerSchema.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using NPoco; | ||
using Umbraco.Core.Persistence.DatabaseAnnotations; | ||
|
||
namespace BackOfficeContentBlocker.Core.Models.Schemas | ||
{ | ||
[TableName("BackOfficeContentBlocker")] | ||
[PrimaryKey("Id", AutoIncrement = true)] | ||
[ExplicitColumns] | ||
public class BackOfficeContentBlockerSchema | ||
{ | ||
[PrimaryKeyColumn(AutoIncrement = true, IdentitySeed = 1)] | ||
[Column("Id")] | ||
public int Id { get; set; } | ||
|
||
[Column("UserEmail")] public string UserEmail { get; set; } | ||
|
||
[Column("PageId")] public int PageId { get; set; } | ||
|
||
[Column("TimeStamp")] public int TimeStamp { get; set; } | ||
} | ||
} |