-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(users): add entities configurations and dbcontext
- Loading branch information
1 parent
d6538cb
commit 8bd200d
Showing
5 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/Users/Infrastructure/Persistence/EntityFramework/ArmoryUserDbContext.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,24 @@ | ||
using Armory.Users.Domain; | ||
using Armory.Users.Infrastructure.Persistence.EntityFramework.EntityConfigurations; | ||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Armory.Users.Infrastructure.Persistence.EntityFramework | ||
{ | ||
public class ArmoryUserDbContext : IdentityDbContext<ArmoryUser, ArmoryRole, string> | ||
{ | ||
public ArmoryUserDbContext(DbContextOptions<ArmoryUserDbContext> options) : base(options) | ||
{ | ||
} | ||
|
||
protected override void OnModelCreating(ModelBuilder builder) | ||
{ | ||
base.OnModelCreating(builder); | ||
|
||
builder.ApplyConfiguration(new ArmoryRoleConfiguration()); | ||
builder.ApplyConfiguration(new ArmoryUserConfiguration()); | ||
builder.ApplyConfiguration(new ArmoryUserLogin()); | ||
builder.ApplyConfiguration(new ArmoryUserTokenConfiguration()); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...nfrastructure/Persistence/EntityFramework/EntityConfigurations/ArmoryRoleConfiguration.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,16 @@ | ||
using Armory.Users.Domain; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace Armory.Users.Infrastructure.Persistence.EntityFramework.EntityConfigurations | ||
{ | ||
public class ArmoryRoleConfiguration : IEntityTypeConfiguration<ArmoryRole> | ||
{ | ||
public void Configure(EntityTypeBuilder<ArmoryRole> builder) | ||
{ | ||
builder.Property(p => p.Id).HasMaxLength(255); | ||
builder.Property(p => p.Name).HasMaxLength(255); | ||
builder.Property(p => p.NormalizedName).HasMaxLength(255); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...nfrastructure/Persistence/EntityFramework/EntityConfigurations/ArmoryUserConfiguration.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,23 @@ | ||
using Armory.Users.Domain; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace Armory.Users.Infrastructure.Persistence.EntityFramework.EntityConfigurations | ||
{ | ||
public class ArmoryUserConfiguration : IEntityTypeConfiguration<ArmoryUser> | ||
{ | ||
public void Configure(EntityTypeBuilder<ArmoryUser> builder) | ||
{ | ||
builder.Property(p => p.Id).HasMaxLength(255); | ||
builder.Property(p => p.UserName).HasMaxLength(15); | ||
builder.Property(p => p.NormalizedUserName).HasMaxLength(15); | ||
builder.Property(p => p.PasswordHash).HasMaxLength(255); | ||
builder.Property(p => p.PhoneNumber).HasMaxLength(10); | ||
builder.Property(p => p.Email).HasMaxLength(127); | ||
builder.Property(p => p.NormalizedEmail).HasMaxLength(127); | ||
|
||
builder.HasIndex(p => p.Email).IsUnique(); | ||
builder.HasIndex(p => p.PhoneNumber).IsUnique(); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Users/Infrastructure/Persistence/EntityFramework/EntityConfigurations/ArmoryUserLogin.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,15 @@ | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace Armory.Users.Infrastructure.Persistence.EntityFramework.EntityConfigurations | ||
{ | ||
public class ArmoryUserLogin : IEntityTypeConfiguration<IdentityUserLogin<string>> | ||
{ | ||
public void Configure(EntityTypeBuilder<IdentityUserLogin<string>> builder) | ||
{ | ||
builder.Property(p => p.LoginProvider).HasMaxLength(255); | ||
builder.Property(p => p.ProviderKey).HasMaxLength(255); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...tructure/Persistence/EntityFramework/EntityConfigurations/ArmoryUserTokenConfiguration.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,15 @@ | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace Armory.Users.Infrastructure.Persistence.EntityFramework.EntityConfigurations | ||
{ | ||
public class ArmoryUserTokenConfiguration : IEntityTypeConfiguration<IdentityUserToken<string>> | ||
{ | ||
public void Configure(EntityTypeBuilder<IdentityUserToken<string>> builder) | ||
{ | ||
builder.Property(p => p.LoginProvider).HasMaxLength(255); | ||
builder.Property(p => p.Name).HasMaxLength(255); | ||
} | ||
} | ||
} |