Skip to content

Commit 686bdc5

Browse files
Fixed migration issues
1 parent 6c73b27 commit 686bdc5

File tree

7 files changed

+240
-3
lines changed

7 files changed

+240
-3
lines changed

src/AbpCompanyName.AbpProjectName.Core/Authorization/Users/User.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public static User CreateTenantAdminUser(int tenantId, string emailAddress, stri
2626
Password = new PasswordHasher().HashPassword(password)
2727
};
2828

29+
user.SetNormalizedNames();
30+
2931
return user;
3032
}
3133
}

src/AbpCompanyName.AbpProjectName.EntityFramework/AbpCompanyName.AbpProjectName.EntityFramework.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@
232232
<Compile Include="Migrations\201901110613114_Upgraded_To_ABP_v4_1_0.Designer.cs">
233233
<DependentUpon>201901110613114_Upgraded_To_ABP_v4_1_0.cs</DependentUpon>
234234
</Compile>
235+
<Compile Include="Migrations\201902080730036_Upgrade_ABP_To_4_2_0.cs" />
236+
<Compile Include="Migrations\201902080730036_Upgrade_ABP_To_4_2_0.Designer.cs">
237+
<DependentUpon>201902080730036_Upgrade_ABP_To_4_2_0.cs</DependentUpon>
238+
</Compile>
235239
<Compile Include="Migrations\AbpZeroDbMigrator.cs" />
236240
<Compile Include="Migrations\Configuration.cs" />
237241
<Compile Include="Migrations\SeedData\DefaultEditionsCreator.cs" />
@@ -263,6 +267,9 @@
263267
<EmbeddedResource Include="Migrations\201901110613114_Upgraded_To_ABP_v4_1_0.resx">
264268
<DependentUpon>201901110613114_Upgraded_To_ABP_v4_1_0.cs</DependentUpon>
265269
</EmbeddedResource>
270+
<EmbeddedResource Include="Migrations\201902080730036_Upgrade_ABP_To_4_2_0.resx">
271+
<DependentUpon>201902080730036_Upgrade_ABP_To_4_2_0.cs</DependentUpon>
272+
</EmbeddedResource>
266273
</ItemGroup>
267274
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
268275
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />

src/AbpCompanyName.AbpProjectName.EntityFramework/Migrations/201902080730036_Upgrade_ABP_To_4_2_0.Designer.cs

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
namespace AbpCompanyName.AbpProjectName.Migrations
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Data.Entity.Infrastructure.Annotations;
6+
using System.Data.Entity.Migrations;
7+
8+
public partial class Upgrade_ABP_To_4_2_0 : DbMigration
9+
{
10+
public override void Up()
11+
{
12+
CreateTable(
13+
"dbo.AbpOrganizationUnitRoles",
14+
c => new
15+
{
16+
Id = c.Long(nullable: false, identity: true),
17+
TenantId = c.Int(),
18+
RoleId = c.Int(nullable: false),
19+
OrganizationUnitId = c.Long(nullable: false),
20+
IsDeleted = c.Boolean(nullable: false),
21+
CreationTime = c.DateTime(nullable: false),
22+
CreatorUserId = c.Long(),
23+
},
24+
annotations: new Dictionary<string, object>
25+
{
26+
{ "DynamicFilter_OrganizationUnitRole_MayHaveTenant", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
27+
})
28+
.PrimaryKey(t => t.Id)
29+
.Index(t => t.TenantId);
30+
31+
AddColumn("dbo.AbpAuditLogs", "ReturnValue", c => c.String());
32+
AddColumn("dbo.AbpRoles", "NormalizedName", c => c.String(nullable: false, maxLength: 32));
33+
AddColumn("dbo.AbpUsers", "NormalizedUserName", c => c.String(nullable: false, maxLength: 256));
34+
AddColumn("dbo.AbpUsers", "NormalizedEmailAddress", c => c.String(nullable: false, maxLength: 256));
35+
DropColumn("dbo.AbpUsers", "LastLoginTime");
36+
DropColumn("dbo.AbpUserAccounts", "LastLoginTime");
37+
}
38+
39+
public override void Down()
40+
{
41+
AddColumn("dbo.AbpUserAccounts", "LastLoginTime", c => c.DateTime());
42+
AddColumn("dbo.AbpUsers", "LastLoginTime", c => c.DateTime());
43+
DropIndex("dbo.AbpOrganizationUnitRoles", new[] { "TenantId" });
44+
DropColumn("dbo.AbpUsers", "NormalizedEmailAddress");
45+
DropColumn("dbo.AbpUsers", "NormalizedUserName");
46+
DropColumn("dbo.AbpRoles", "NormalizedName");
47+
DropColumn("dbo.AbpAuditLogs", "ReturnValue");
48+
DropTable("dbo.AbpOrganizationUnitRoles",
49+
removedAnnotations: new Dictionary<string, object>
50+
{
51+
{ "DynamicFilter_OrganizationUnitRole_MayHaveTenant", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
52+
});
53+
}
54+
}
55+
}

src/AbpCompanyName.AbpProjectName.EntityFramework/Migrations/201902080730036_Upgrade_ABP_To_4_2_0.resx

Lines changed: 126 additions & 0 deletions
Large diffs are not rendered by default.

src/AbpCompanyName.AbpProjectName.EntityFramework/Migrations/SeedData/HostRoleAndUserCreator.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,17 @@ private void CreateHostRoleAndUsers()
3232
var adminRoleForHost = _context.Roles.FirstOrDefault(r => r.TenantId == null && r.Name == StaticRoleNames.Host.Admin);
3333
if (adminRoleForHost == null)
3434
{
35-
adminRoleForHost = _context.Roles.Add(new Role { Name = StaticRoleNames.Host.Admin, DisplayName = StaticRoleNames.Host.Admin, IsStatic = true });
35+
36+
adminRoleForHost = new Role
37+
{
38+
Name = StaticRoleNames.Host.Admin,
39+
DisplayName = StaticRoleNames.Host.Admin,
40+
IsStatic = true
41+
};
42+
43+
adminRoleForHost.SetNormalizedName();
44+
45+
_context.Roles.Add(adminRoleForHost);
3646
_context.SaveChanges();
3747

3848
//Grant all tenant permissions
@@ -71,10 +81,11 @@ private void CreateHostRoleAndUsers()
7181
Password = new PasswordHasher().HashPassword(User.DefaultPassword)
7282
});
7383

84+
adminUserForHost.SetNormalizedNames();
85+
7486
_context.SaveChanges();
7587

7688
_context.UserRoles.Add(new UserRole(null, adminUserForHost.Id, adminRoleForHost.Id));
77-
7889
_context.SaveChanges();
7990
}
8091
}

src/AbpCompanyName.AbpProjectName.EntityFramework/Migrations/SeedData/TenantRoleAndUserBuilder.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@ private void CreateRolesAndUsers()
3333
var adminRole = _context.Roles.FirstOrDefault(r => r.TenantId == _tenantId && r.Name == StaticRoleNames.Tenants.Admin);
3434
if (adminRole == null)
3535
{
36-
adminRole = _context.Roles.Add(new Role(_tenantId, StaticRoleNames.Tenants.Admin, StaticRoleNames.Tenants.Admin) { IsStatic = true });
36+
adminRole = new Role(_tenantId, StaticRoleNames.Tenants.Admin, StaticRoleNames.Tenants.Admin)
37+
{
38+
IsStatic = true
39+
};
40+
41+
adminRole.SetNormalizedName();
42+
43+
_context.Roles.Add(adminRole);
3744
_context.SaveChanges();
3845

3946
//Grant all permissions to admin role

0 commit comments

Comments
 (0)