Small improvements to try and mitigate #2750

pull/2814/head
tidusjar 6 years ago
parent da9c481bb4
commit d834b96b4b

@ -87,53 +87,6 @@ namespace Ombi.Store.Context
public void Seed()
{
// VACUUM;
Database.ExecuteSqlCommand("VACUUM;");
// Make sure we have the roles
var newsletterRole = Roles.Where(x => x.Name == OmbiRoles.ReceivesNewsletter);
if (!newsletterRole.Any())
{
Roles.Add(new IdentityRole(OmbiRoles.ReceivesNewsletter)
{
NormalizedName = OmbiRoles.ReceivesNewsletter.ToUpper()
});
SaveChanges();
}
var requestMusicRole = Roles.Where(x => x.Name == OmbiRoles.RequestMusic);
if (!requestMusicRole.Any())
{
Roles.Add(new IdentityRole(OmbiRoles.RequestMusic)
{
NormalizedName = OmbiRoles.RequestMusic.ToUpper()
});
Roles.Add(new IdentityRole(OmbiRoles.AutoApproveMusic)
{
NormalizedName = OmbiRoles.AutoApproveMusic.ToUpper()
});
SaveChanges();
}
var manageOwnRequestsRole = Roles.Where(x => x.Name == OmbiRoles.ManageOwnRequests);
if (!manageOwnRequestsRole.Any())
{
Roles.Add(new IdentityRole(OmbiRoles.ManageOwnRequests)
{
NormalizedName = OmbiRoles.ManageOwnRequests.ToUpper()
});
SaveChanges();
}
var editCustomPage = Roles.Where(x => x.Name == OmbiRoles.EditCustomPage);
if (!editCustomPage.Any())
{
Roles.Add(new IdentityRole(OmbiRoles.EditCustomPage)
{
NormalizedName = OmbiRoles.EditCustomPage.ToUpper()
});
SaveChanges();
}
// Make sure we have the API User
var apiUserExists = Users.Any(x => x.UserName.Equals("Api", StringComparison.CurrentCultureIgnoreCase));
if (!apiUserExists)

File diff suppressed because it is too large Load Diff

@ -0,0 +1,32 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Ombi.Helpers;
namespace Ombi.Store.Migrations
{
public partial class Roles : Migration
{
protected override void Up(MigrationBuilder mb)
{
// Make sure we have the roles
InsertRole(mb, OmbiRoles.ReceivesNewsletter);
InsertRole(mb, OmbiRoles.RequestMusic);
InsertRole(mb, OmbiRoles.AutoApproveMusic);
InsertRole(mb, OmbiRoles.ManageOwnRequests);
InsertRole(mb, OmbiRoles.EditCustomPage);
}
private void InsertRole(MigrationBuilder mb, string role)
{
mb.Sql($@"
INSERT INTO AspnetRoles(Id, ConcurrencyStamp, Name, NormalizedName)
SELECT '{Guid.NewGuid().ToString()}','{Guid.NewGuid().ToString()}','{role}', '{role.ToUpper()}'
WHERE NOT EXISTS(SELECT 1 FROM AspnetRoles WHERE Name = '{role}');");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}
Loading…
Cancel
Save