Skip to content

Commit

Permalink
Merge pull request #95 from Lombiq/issue/NEST-486
Browse files Browse the repository at this point in the history
NEST-486: Renaming EmailQuotaIndex columns and dropping index
  • Loading branch information
Piedone authored Oct 20, 2023
2 parents 17f5dc2 + de8f5b5 commit aed6627
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 43 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
using Lombiq.Hosting.Tenants.EmailQuotaManagement.Indexes;
using OrchardCore.Data.Migration;
using System;
using YesSql.Sql;

namespace Lombiq.Hosting.Tenants.EmailQuotaManagement.Migrations;

public class EmailQuotaMigrations : DataMigration
{
public int Create()
// This is actually needed like this, otherwise it won't work.
#pragma warning disable S3400
public int Create() => 3;
#pragma warning restore S3400

public int UpdateFrom1()
{
SchemaBuilder.CreateMapIndexTable<EmailQuotaIndex>(
table => table.Column<int>(nameof(EmailQuotaIndex.CurrentEmailUsageCount))
.Column<DateTime>(nameof(EmailQuotaIndex.LastReminderUtc))
.Column<int>(nameof(EmailQuotaIndex.LastReminderPercentage)));
SchemaBuilder.AlterTable("EmailQuotaIndex", table => table
.AddColumn<int>("LastReminderPercentage")
);

return 2;
}

public int UpdateFrom1()
public int UpdateFrom2()
{
SchemaBuilder.AlterTable(nameof(EmailQuotaIndex), table => table
.AddColumn<int>(nameof(EmailQuotaIndex.LastReminderPercentage))
);
// Deleting index because it is not needed.
SchemaBuilder.DropTable("EmailQuotaIndex");

return 2;
return 3;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Lombiq.Hosting.Tenants.EmailQuotaManagement.Indexes;
using Lombiq.Hosting.Tenants.EmailQuotaManagement.Models;
using Lombiq.Hosting.Tenants.EmailQuotaManagement.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -83,7 +82,7 @@ public async Task<QuotaResult> IsQuotaOverTheLimitAsync()

public async Task<EmailQuota> GetOrCreateCurrentQuotaAsync()
{
var currentQuota = await _session.Query<EmailQuota, EmailQuotaIndex>().FirstOrDefaultAsync();
var currentQuota = await _session.Query<EmailQuota>().FirstOrDefaultAsync();

if (currentQuota != null) return currentQuota;

Expand Down
3 changes: 0 additions & 3 deletions Lombiq.Hosting.Tenants.EmailQuotaManagement/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Lombiq.Hosting.Tenants.EmailQuotaManagement.Constants;
using Lombiq.Hosting.Tenants.EmailQuotaManagement.Filters;
using Lombiq.Hosting.Tenants.EmailQuotaManagement.Indexes;
using Lombiq.Hosting.Tenants.EmailQuotaManagement.Migrations;
using Lombiq.Hosting.Tenants.EmailQuotaManagement.Models;
using Lombiq.Hosting.Tenants.EmailQuotaManagement.Services;
Expand All @@ -12,7 +11,6 @@
using OrchardCore.Email;
using OrchardCore.Environment.Shell.Configuration;
using OrchardCore.Modules;
using YesSql.Indexes;
using static Lombiq.Hosting.Tenants.EmailQuotaManagement.Constants.EmailQuotaOptionsConstants;

namespace Lombiq.Hosting.Tenants.EmailQuotaManagement;
Expand All @@ -28,7 +26,6 @@ public Startup(IShellConfiguration shellConfiguration) =>
public override void ConfigureServices(IServiceCollection services)
{
services.AddDataMigration<EmailQuotaMigrations>();
services.AddSingleton<IIndexProvider, EmailQuotaIndexProvider>();
services.AddSingleton<IBackgroundTask, EmailQuotaResetBackgroundTask>();

services.Configure<EmailQuotaOptions>(options =>
Expand Down

0 comments on commit aed6627

Please sign in to comment.