From bdb644b8df2a1c7e91ff11cbb30503661e296b55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 23 Jan 2017 15:42:17 +0300 Subject: [PATCH] Revided Identity DbContext and recreated initial migration. --- .../AbpDesk.Domain/AbpDesk/Tickets/Ticket.cs | 14 +- .../EntityFrameworkCore/AbpDeskDbContext.cs | 7 +- ...161210211733_Initial_Migration.Designer.cs | 35 --- ..._Ticket_Added_Data_Annotations.Designer.cs | 38 --- ...211123930_Ticket_Added_Data_Annotations.cs | 30 --- ...062008_Added_ConcurrencyStamp_To_Ticket.cs | 24 -- ...0170123122207_AbpDesk_Initial.Designer.cs} | 7 +- ...n.cs => 20170123122207_AbpDesk_Initial.cs} | 7 +- .../AbpDeskDbContextModelSnapshot.cs | 3 +- ...119175536_Initial_Abp_Identity.Designer.cs | 236 ------------------ ...3063841_Remove_Unique_Index_Constraints.cs | 110 -------- ...170123121521_Identity_Initial.Designer.cs} | 76 ++++-- ....cs => 20170123121521_Identity_Initial.cs} | 70 +++--- .../IdentityDbContextModelSnapshot.cs | 72 ++++-- .../EntityFrameworkCore/IdentityDbContext.cs | 48 +++- .../Volo/Abp/Identity/IdentityRole.cs | 6 +- .../Volo/Abp/Identity/IdentityRoleClaim.cs | 8 +- .../Volo/Abp/Identity/IdentityUser.cs | 10 +- .../Volo/Abp/Identity/IdentityUserClaim.cs | 5 + .../Volo/Abp/Identity/IdentityUserLogin.cs | 6 + .../Volo/Abp/Identity/IdentityUserRole.cs | 2 + .../Volo/Abp/Identity/IdentityUserToken.cs | 7 +- 22 files changed, 239 insertions(+), 582 deletions(-) delete mode 100644 src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20161210211733_Initial_Migration.Designer.cs delete mode 100644 src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20161211123930_Ticket_Added_Data_Annotations.Designer.cs delete mode 100644 src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20161211123930_Ticket_Added_Data_Annotations.cs delete mode 100644 src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20170123062008_Added_ConcurrencyStamp_To_Ticket.cs rename src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/{20170123062008_Added_ConcurrencyStamp_To_Ticket.Designer.cs => 20170123122207_AbpDesk_Initial.Designer.cs} (85%) rename src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/{20161210211733_Initial_Migration.cs => 20170123122207_AbpDesk_Initial.cs} (76%) delete mode 100644 src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20170119175536_Initial_Abp_Identity.Designer.cs delete mode 100644 src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20170123063841_Remove_Unique_Index_Constraints.cs rename src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/{20170123063841_Remove_Unique_Index_Constraints.Designer.cs => 20170123121521_Identity_Initial.Designer.cs} (72%) rename src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/{20170119175536_Initial_Abp_Identity.cs => 20170123121521_Identity_Initial.cs} (79%) diff --git a/src/AbpDesk/AbpDesk.Domain/AbpDesk/Tickets/Ticket.cs b/src/AbpDesk/AbpDesk.Domain/AbpDesk/Tickets/Ticket.cs index 59c1d69291..ac883c0889 100644 --- a/src/AbpDesk/AbpDesk.Domain/AbpDesk/Tickets/Ticket.cs +++ b/src/AbpDesk/AbpDesk.Domain/AbpDesk/Tickets/Ticket.cs @@ -1,4 +1,4 @@ -using System.ComponentModel.DataAnnotations; +using System; using JetBrains.Annotations; using Volo; using Volo.Abp.Domain.Entities; @@ -11,12 +11,11 @@ namespace AbpDesk.Tickets public const int MaxBodyLength = 64 * 1024; //64K - [Required] - [MaxLength(MaxTitleLength)] - public string Title { get; set; } + [NotNull] + public string Title { get; protected set; } - [MaxLength(MaxBodyLength)] - public string Body { get; set; } + [CanBeNull] + public string Body { get; protected set; } public string ConcurrencyStamp { get; set; } @@ -25,12 +24,13 @@ namespace AbpDesk.Tickets } - public Ticket([NotNull] string title, string body) + public Ticket([NotNull] string title, [CanBeNull] string body = null) { Check.NotNull(title, nameof(title)); Title = title; Body = body; + ConcurrencyStamp = Guid.NewGuid().ToString(); } } } diff --git a/src/AbpDesk/AbpDesk.EntityFrameworkCore/AbpDesk/EntityFrameworkCore/AbpDeskDbContext.cs b/src/AbpDesk/AbpDesk.EntityFrameworkCore/AbpDesk/EntityFrameworkCore/AbpDeskDbContext.cs index da9b462e92..b523edddc9 100644 --- a/src/AbpDesk/AbpDesk.EntityFrameworkCore/AbpDesk/EntityFrameworkCore/AbpDeskDbContext.cs +++ b/src/AbpDesk/AbpDesk.EntityFrameworkCore/AbpDesk/EntityFrameworkCore/AbpDeskDbContext.cs @@ -21,9 +21,12 @@ namespace AbpDesk.EntityFrameworkCore base.OnModelCreating(modelBuilder); //Use different classes to map each entity type? - modelBuilder.Entity(builder => + modelBuilder.Entity(b => { - builder.ToTable("DskTickets"); + b.ToTable("DskTickets"); + + b.Property(t => t.Title).HasMaxLength(Ticket.MaxTitleLength).IsRequired(); + b.Property(t => t.Body).HasMaxLength(Ticket.MaxBodyLength); }); } } diff --git a/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20161210211733_Initial_Migration.Designer.cs b/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20161210211733_Initial_Migration.Designer.cs deleted file mode 100644 index 59290a099e..0000000000 --- a/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20161210211733_Initial_Migration.Designer.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using AbpDesk.EntityFrameworkCore; - -namespace AbpDesk.EntityFrameworkCore.Migrations -{ - [DbContext(typeof(AbpDeskDbContext))] - [Migration("20161210211733_Initial_Migration")] - partial class Initial_Migration - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { - modelBuilder - .HasAnnotation("ProductVersion", "1.1.0-rtm-22752") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("AbpDesk.Tickets.Ticket", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("Body"); - - b.Property("Title"); - - b.HasKey("Id"); - - b.ToTable("DskTickets"); - }); - } - } -} diff --git a/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20161211123930_Ticket_Added_Data_Annotations.Designer.cs b/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20161211123930_Ticket_Added_Data_Annotations.Designer.cs deleted file mode 100644 index 95c11c5380..0000000000 --- a/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20161211123930_Ticket_Added_Data_Annotations.Designer.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using AbpDesk.EntityFrameworkCore; - -namespace AbpDesk.EntityFrameworkCore.Migrations -{ - [DbContext(typeof(AbpDeskDbContext))] - [Migration("20161211123930_Ticket_Added_Data_Annotations")] - partial class Ticket_Added_Data_Annotations - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { - modelBuilder - .HasAnnotation("ProductVersion", "1.1.0-rtm-22752") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("AbpDesk.Tickets.Ticket", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("Body") - .HasMaxLength(65536); - - b.Property("Title") - .IsRequired() - .HasMaxLength(256); - - b.HasKey("Id"); - - b.ToTable("DskTickets"); - }); - } - } -} diff --git a/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20161211123930_Ticket_Added_Data_Annotations.cs b/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20161211123930_Ticket_Added_Data_Annotations.cs deleted file mode 100644 index 6ef36d68ca..0000000000 --- a/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20161211123930_Ticket_Added_Data_Annotations.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace AbpDesk.EntityFrameworkCore.Migrations -{ - public partial class Ticket_Added_Data_Annotations : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterColumn( - name: "Title", - table: "DskTickets", - maxLength: 256, - nullable: false, - oldClrType: typeof(string), - oldNullable: true); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterColumn( - name: "Title", - table: "DskTickets", - nullable: true, - oldClrType: typeof(string), - oldMaxLength: 256); - } - } -} diff --git a/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20170123062008_Added_ConcurrencyStamp_To_Ticket.cs b/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20170123062008_Added_ConcurrencyStamp_To_Ticket.cs deleted file mode 100644 index f1a9735438..0000000000 --- a/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20170123062008_Added_ConcurrencyStamp_To_Ticket.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace AbpDesk.EntityFrameworkCore.Migrations -{ - public partial class Added_ConcurrencyStamp_To_Ticket : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "ConcurrencyStamp", - table: "DskTickets", - nullable: true); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "ConcurrencyStamp", - table: "DskTickets"); - } - } -} diff --git a/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20170123062008_Added_ConcurrencyStamp_To_Ticket.Designer.cs b/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20170123122207_AbpDesk_Initial.Designer.cs similarity index 85% rename from src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20170123062008_Added_ConcurrencyStamp_To_Ticket.Designer.cs rename to src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20170123122207_AbpDesk_Initial.Designer.cs index bd014d1fec..908a2dec30 100644 --- a/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20170123062008_Added_ConcurrencyStamp_To_Ticket.Designer.cs +++ b/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20170123122207_AbpDesk_Initial.Designer.cs @@ -8,8 +8,8 @@ using AbpDesk.EntityFrameworkCore; namespace AbpDesk.EntityFrameworkCore.Migrations { [DbContext(typeof(AbpDeskDbContext))] - [Migration("20170123062008_Added_ConcurrencyStamp_To_Ticket")] - partial class Added_ConcurrencyStamp_To_Ticket + [Migration("20170123122207_AbpDesk_Initial")] + partial class AbpDesk_Initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) { @@ -25,7 +25,8 @@ namespace AbpDesk.EntityFrameworkCore.Migrations b.Property("Body") .HasMaxLength(65536); - b.Property("ConcurrencyStamp"); + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); b.Property("Title") .IsRequired() diff --git a/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20161210211733_Initial_Migration.cs b/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20170123122207_AbpDesk_Initial.cs similarity index 76% rename from src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20161210211733_Initial_Migration.cs rename to src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20170123122207_AbpDesk_Initial.cs index a59a3df5b9..6315a3d284 100644 --- a/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20161210211733_Initial_Migration.cs +++ b/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20170123122207_AbpDesk_Initial.cs @@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore.Metadata; namespace AbpDesk.EntityFrameworkCore.Migrations { - public partial class Initial_Migration : Migration + public partial class AbpDesk_Initial : Migration { protected override void Up(MigrationBuilder migrationBuilder) { @@ -15,8 +15,9 @@ namespace AbpDesk.EntityFrameworkCore.Migrations { Id = table.Column(nullable: false) .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), - Body = table.Column(nullable: true), - Title = table.Column(nullable: true) + Body = table.Column(maxLength: 65536, nullable: true), + ConcurrencyStamp = table.Column(nullable: true), + Title = table.Column(maxLength: 256, nullable: false) }, constraints: table => { diff --git a/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/AbpDeskDbContextModelSnapshot.cs b/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/AbpDeskDbContextModelSnapshot.cs index 9e9e61c8b3..915e70d3d0 100644 --- a/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/AbpDeskDbContextModelSnapshot.cs +++ b/src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/AbpDeskDbContextModelSnapshot.cs @@ -24,7 +24,8 @@ namespace AbpDesk.EntityFrameworkCore.Migrations b.Property("Body") .HasMaxLength(65536); - b.Property("ConcurrencyStamp"); + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); b.Property("Title") .IsRequired() diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20170119175536_Initial_Abp_Identity.Designer.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20170119175536_Initial_Abp_Identity.Designer.cs deleted file mode 100644 index e54095b147..0000000000 --- a/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20170119175536_Initial_Abp_Identity.Designer.cs +++ /dev/null @@ -1,236 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Volo.Abp.Identity.EntityFrameworkCore; - -namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations -{ - [DbContext(typeof(IdentityDbContext))] - [Migration("20170119175536_Initial_Abp_Identity")] - partial class Initial_Abp_Identity - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { - modelBuilder - .HasAnnotation("ProductVersion", "1.1.0-rtm-22752") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("Volo.Abp.Identity.IdentityRole", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken(); - - b.Property("Name") - .HasMaxLength(256); - - b.Property("NormalizedName") - .HasMaxLength(256); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasName("RoleNameIndex"); - - b.ToTable("IdentityRoles"); - }); - - modelBuilder.Entity("Volo.Abp.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("ClaimType"); - - b.Property("ClaimValue"); - - b.Property("RoleId"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("IdentityRoleClaims"); - }); - - modelBuilder.Entity("Volo.Abp.Identity.IdentityUser", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("AccessFailedCount"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken(); - - b.Property("Email") - .HasMaxLength(256); - - b.Property("EmailConfirmed"); - - b.Property("LockoutEnabled"); - - b.Property("LockoutEnd"); - - b.Property("NormalizedEmail") - .HasMaxLength(256); - - b.Property("NormalizedUserName") - .HasMaxLength(256); - - b.Property("PasswordHash"); - - b.Property("PhoneNumber"); - - b.Property("PhoneNumberConfirmed"); - - b.Property("SecurityStamp"); - - b.Property("TwoFactorEnabled"); - - b.Property("UserName") - .HasMaxLength(256); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasName("UserNameIndex"); - - b.ToTable("IdentityUsers"); - }); - - modelBuilder.Entity("Volo.Abp.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("ClaimType"); - - b.Property("ClaimValue"); - - b.Property("UserId"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("IdentityUserClaims"); - }); - - modelBuilder.Entity("Volo.Abp.Identity.IdentityUserLogin", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("LoginProvider"); - - b.Property("ProviderDisplayName"); - - b.Property("ProviderKey"); - - b.Property("UserId"); - - b.HasKey("Id"); - - b.HasIndex("UserId", "LoginProvider", "ProviderKey") - .IsUnique(); - - b.ToTable("IdentityUserLogins"); - }); - - modelBuilder.Entity("Volo.Abp.Identity.IdentityUserRole", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("RoleId"); - - b.Property("UserId"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.HasIndex("UserId", "RoleId") - .IsUnique(); - - b.ToTable("IdentityUserRoles"); - }); - - modelBuilder.Entity("Volo.Abp.Identity.IdentityUserToken", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("LoginProvider"); - - b.Property("Name"); - - b.Property("UserId"); - - b.Property("Value"); - - b.HasKey("Id"); - - b.HasIndex("UserId", "LoginProvider", "Name") - .IsUnique(); - - b.ToTable("IdentityUserTokens"); - }); - - modelBuilder.Entity("Volo.Abp.Identity.IdentityRoleClaim", b => - { - b.HasOne("Volo.Abp.Identity.IdentityRole") - .WithMany("Claims") - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("Volo.Abp.Identity.IdentityUserClaim", b => - { - b.HasOne("Volo.Abp.Identity.IdentityUser") - .WithMany("Claims") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("Volo.Abp.Identity.IdentityUserLogin", b => - { - b.HasOne("Volo.Abp.Identity.IdentityUser") - .WithMany("Logins") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("Volo.Abp.Identity.IdentityUserRole", b => - { - b.HasOne("Volo.Abp.Identity.IdentityRole") - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade); - - b.HasOne("Volo.Abp.Identity.IdentityUser") - .WithMany("Roles") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("Volo.Abp.Identity.IdentityUserToken", b => - { - b.HasOne("Volo.Abp.Identity.IdentityUser") - .WithMany("Tokens") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade); - }); - } - } -} diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20170123063841_Remove_Unique_Index_Constraints.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20170123063841_Remove_Unique_Index_Constraints.cs deleted file mode 100644 index b1dfd8b729..0000000000 --- a/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20170123063841_Remove_Unique_Index_Constraints.cs +++ /dev/null @@ -1,110 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations -{ - public partial class Remove_Unique_Index_Constraints : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropIndex( - name: "IX_IdentityUserTokens_UserId_LoginProvider_Name", - table: "IdentityUserTokens"); - - migrationBuilder.DropIndex( - name: "IX_IdentityUserRoles_UserId_RoleId", - table: "IdentityUserRoles"); - - migrationBuilder.DropIndex( - name: "IX_IdentityUserLogins_UserId_LoginProvider_ProviderKey", - table: "IdentityUserLogins"); - - migrationBuilder.DropIndex( - name: "UserNameIndex", - table: "IdentityUsers"); - - migrationBuilder.DropIndex( - name: "RoleNameIndex", - table: "IdentityRoles"); - - migrationBuilder.CreateIndex( - name: "IX_IdentityUserTokens_UserId_LoginProvider_Name", - table: "IdentityUserTokens", - columns: new[] { "UserId", "LoginProvider", "Name" }); - - migrationBuilder.CreateIndex( - name: "IX_IdentityUserRoles_UserId_RoleId", - table: "IdentityUserRoles", - columns: new[] { "UserId", "RoleId" }); - - migrationBuilder.CreateIndex( - name: "IX_IdentityUserLogins_UserId_LoginProvider_ProviderKey", - table: "IdentityUserLogins", - columns: new[] { "UserId", "LoginProvider", "ProviderKey" }); - - migrationBuilder.CreateIndex( - name: "UserNameIndex", - table: "IdentityUsers", - column: "NormalizedUserName"); - - migrationBuilder.CreateIndex( - name: "RoleNameIndex", - table: "IdentityRoles", - column: "NormalizedName"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropIndex( - name: "IX_IdentityUserTokens_UserId_LoginProvider_Name", - table: "IdentityUserTokens"); - - migrationBuilder.DropIndex( - name: "IX_IdentityUserRoles_UserId_RoleId", - table: "IdentityUserRoles"); - - migrationBuilder.DropIndex( - name: "IX_IdentityUserLogins_UserId_LoginProvider_ProviderKey", - table: "IdentityUserLogins"); - - migrationBuilder.DropIndex( - name: "UserNameIndex", - table: "IdentityUsers"); - - migrationBuilder.DropIndex( - name: "RoleNameIndex", - table: "IdentityRoles"); - - migrationBuilder.CreateIndex( - name: "IX_IdentityUserTokens_UserId_LoginProvider_Name", - table: "IdentityUserTokens", - columns: new[] { "UserId", "LoginProvider", "Name" }, - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_IdentityUserRoles_UserId_RoleId", - table: "IdentityUserRoles", - columns: new[] { "UserId", "RoleId" }, - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_IdentityUserLogins_UserId_LoginProvider_ProviderKey", - table: "IdentityUserLogins", - columns: new[] { "UserId", "LoginProvider", "ProviderKey" }, - unique: true); - - migrationBuilder.CreateIndex( - name: "UserNameIndex", - table: "IdentityUsers", - column: "NormalizedUserName", - unique: true); - - migrationBuilder.CreateIndex( - name: "RoleNameIndex", - table: "IdentityRoles", - column: "NormalizedName", - unique: true); - } - } -} diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20170123063841_Remove_Unique_Index_Constraints.Designer.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20170123121521_Identity_Initial.Designer.cs similarity index 72% rename from src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20170123063841_Remove_Unique_Index_Constraints.Designer.cs rename to src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20170123121521_Identity_Initial.Designer.cs index ca58a0d112..42a0a38486 100644 --- a/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20170123063841_Remove_Unique_Index_Constraints.Designer.cs +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20170123121521_Identity_Initial.Designer.cs @@ -8,8 +8,8 @@ using Volo.Abp.Identity.EntityFrameworkCore; namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations { [DbContext(typeof(IdentityDbContext))] - [Migration("20170123063841_Remove_Unique_Index_Constraints")] - partial class Remove_Unique_Index_Constraints + [Migration("20170123121521_Identity_Initial")] + partial class Identity_Initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) { @@ -33,8 +33,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations b.HasKey("Id"); - b.HasIndex("NormalizedName") - .HasName("RoleNameIndex"); + b.HasIndex("NormalizedName"); b.ToTable("IdentityRoles"); }); @@ -44,9 +43,12 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations b.Property("Id") .ValueGeneratedOnAdd(); - b.Property("ClaimType"); + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(256); - b.Property("ClaimValue"); + b.Property("ClaimValue") + .HasMaxLength(1024); b.Property("RoleId"); @@ -62,7 +64,9 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations b.Property("Id") .ValueGeneratedOnAdd(); - b.Property("AccessFailedCount"); + b.Property("AccessFailedCount") + .ValueGeneratedOnAdd() + .HasDefaultValue(0); b.Property("ConcurrencyStamp") .IsConcurrencyToken(); @@ -70,9 +74,13 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations b.Property("Email") .HasMaxLength(256); - b.Property("EmailConfirmed"); + b.Property("EmailConfirmed") + .ValueGeneratedOnAdd() + .HasDefaultValue(false); - b.Property("LockoutEnabled"); + b.Property("LockoutEnabled") + .ValueGeneratedOnAdd() + .HasDefaultValue(false); b.Property("LockoutEnd"); @@ -86,22 +94,24 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations b.Property("PhoneNumber"); - b.Property("PhoneNumberConfirmed"); + b.Property("PhoneNumberConfirmed") + .ValueGeneratedOnAdd() + .HasDefaultValue(false); b.Property("SecurityStamp"); - b.Property("TwoFactorEnabled"); + b.Property("TwoFactorEnabled") + .ValueGeneratedOnAdd() + .HasDefaultValue(false); b.Property("UserName") .HasMaxLength(256); b.HasKey("Id"); - b.HasIndex("NormalizedEmail") - .HasName("EmailIndex"); + b.HasIndex("NormalizedEmail"); - b.HasIndex("NormalizedUserName") - .HasName("UserNameIndex"); + b.HasIndex("NormalizedUserName"); b.ToTable("IdentityUsers"); }); @@ -111,9 +121,12 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations b.Property("Id") .ValueGeneratedOnAdd(); - b.Property("ClaimType"); + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(256); - b.Property("ClaimValue"); + b.Property("ClaimValue") + .HasMaxLength(1024); b.Property("UserId"); @@ -129,16 +142,23 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations b.Property("Id") .ValueGeneratedOnAdd(); - b.Property("LoginProvider"); + b.Property("LoginProvider") + .IsRequired() + .HasMaxLength(64); - b.Property("ProviderDisplayName"); + b.Property("ProviderDisplayName") + .HasMaxLength(128); - b.Property("ProviderKey"); + b.Property("ProviderKey") + .IsRequired() + .HasMaxLength(256); b.Property("UserId"); b.HasKey("Id"); + b.HasIndex("LoginProvider", "ProviderKey"); + b.HasIndex("UserId", "LoginProvider", "ProviderKey"); b.ToTable("IdentityUserLogins"); @@ -149,13 +169,17 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations b.Property("Id") .ValueGeneratedOnAdd(); + b.Property("IdentityUserId1"); + b.Property("RoleId"); b.Property("UserId"); b.HasKey("Id"); - b.HasIndex("RoleId"); + b.HasIndex("IdentityUserId1"); + + b.HasIndex("RoleId", "UserId"); b.HasIndex("UserId", "RoleId"); @@ -167,7 +191,9 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations b.Property("Id") .ValueGeneratedOnAdd(); - b.Property("LoginProvider"); + b.Property("LoginProvider") + .IsRequired() + .HasMaxLength(64); b.Property("Name"); @@ -208,13 +234,17 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations modelBuilder.Entity("Volo.Abp.Identity.IdentityUserRole", b => { + b.HasOne("Volo.Abp.Identity.IdentityUser") + .WithMany("Roles") + .HasForeignKey("IdentityUserId1"); + b.HasOne("Volo.Abp.Identity.IdentityRole") .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade); b.HasOne("Volo.Abp.Identity.IdentityUser") - .WithMany("Roles") + .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade); }); diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20170119175536_Initial_Abp_Identity.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20170123121521_Identity_Initial.cs similarity index 79% rename from src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20170119175536_Initial_Abp_Identity.cs rename to src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20170123121521_Identity_Initial.cs index d52557901e..542433da24 100644 --- a/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20170119175536_Initial_Abp_Identity.cs +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/20170123121521_Identity_Initial.cs @@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations { - public partial class Initial_Abp_Identity : Migration + public partial class Identity_Initial : Migration { protected override void Up(MigrationBuilder migrationBuilder) { @@ -27,19 +27,19 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations columns: table => new { Id = table.Column(nullable: false), - AccessFailedCount = table.Column(nullable: false), + AccessFailedCount = table.Column(nullable: false, defaultValue: 0), ConcurrencyStamp = table.Column(nullable: true), Email = table.Column(maxLength: 256, nullable: true), - EmailConfirmed = table.Column(nullable: false), - LockoutEnabled = table.Column(nullable: false), + EmailConfirmed = table.Column(nullable: false, defaultValue: false), + LockoutEnabled = table.Column(nullable: false, defaultValue: false), LockoutEnd = table.Column(nullable: true), NormalizedEmail = table.Column(maxLength: 256, nullable: true), NormalizedUserName = table.Column(maxLength: 256, nullable: true), PasswordHash = table.Column(nullable: true), PhoneNumber = table.Column(nullable: true), - PhoneNumberConfirmed = table.Column(nullable: false), + PhoneNumberConfirmed = table.Column(nullable: false, defaultValue: false), SecurityStamp = table.Column(nullable: true), - TwoFactorEnabled = table.Column(nullable: false), + TwoFactorEnabled = table.Column(nullable: false, defaultValue: false), UserName = table.Column(maxLength: 256, nullable: true) }, constraints: table => @@ -52,8 +52,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations columns: table => new { Id = table.Column(nullable: false), - ClaimType = table.Column(nullable: true), - ClaimValue = table.Column(nullable: true), + ClaimType = table.Column(maxLength: 256, nullable: false), + ClaimValue = table.Column(maxLength: 1024, nullable: true), RoleId = table.Column(nullable: false) }, constraints: table => @@ -72,8 +72,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations columns: table => new { Id = table.Column(nullable: false), - ClaimType = table.Column(nullable: true), - ClaimValue = table.Column(nullable: true), + ClaimType = table.Column(maxLength: 256, nullable: false), + ClaimValue = table.Column(maxLength: 1024, nullable: true), UserId = table.Column(nullable: false) }, constraints: table => @@ -92,9 +92,9 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations columns: table => new { Id = table.Column(nullable: false), - LoginProvider = table.Column(nullable: true), - ProviderDisplayName = table.Column(nullable: true), - ProviderKey = table.Column(nullable: true), + LoginProvider = table.Column(maxLength: 64, nullable: false), + ProviderDisplayName = table.Column(maxLength: 128, nullable: true), + ProviderKey = table.Column(maxLength: 256, nullable: false), UserId = table.Column(nullable: false) }, constraints: table => @@ -113,12 +113,19 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations columns: table => new { Id = table.Column(nullable: false), + IdentityUserId1 = table.Column(nullable: true), RoleId = table.Column(nullable: false), UserId = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_IdentityUserRoles", x => x.Id); + table.ForeignKey( + name: "FK_IdentityUserRoles_IdentityUsers_IdentityUserId1", + column: x => x.IdentityUserId1, + principalTable: "IdentityUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_IdentityUserRoles_IdentityRoles_RoleId", column: x => x.RoleId, @@ -138,7 +145,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations columns: table => new { Id = table.Column(nullable: false), - LoginProvider = table.Column(nullable: true), + LoginProvider = table.Column(maxLength: 64, nullable: false), Name = table.Column(nullable: true), UserId = table.Column(nullable: false), Value = table.Column(nullable: true) @@ -155,10 +162,9 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations }); migrationBuilder.CreateIndex( - name: "RoleNameIndex", + name: "IX_IdentityRoles_NormalizedName", table: "IdentityRoles", - column: "NormalizedName", - unique: true); + column: "NormalizedName"); migrationBuilder.CreateIndex( name: "IX_IdentityRoleClaims_RoleId", @@ -166,43 +172,49 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations column: "RoleId"); migrationBuilder.CreateIndex( - name: "EmailIndex", + name: "IX_IdentityUsers_NormalizedEmail", table: "IdentityUsers", column: "NormalizedEmail"); migrationBuilder.CreateIndex( - name: "UserNameIndex", + name: "IX_IdentityUsers_NormalizedUserName", table: "IdentityUsers", - column: "NormalizedUserName", - unique: true); + column: "NormalizedUserName"); migrationBuilder.CreateIndex( name: "IX_IdentityUserClaims_UserId", table: "IdentityUserClaims", column: "UserId"); + migrationBuilder.CreateIndex( + name: "IX_IdentityUserLogins_LoginProvider_ProviderKey", + table: "IdentityUserLogins", + columns: new[] { "LoginProvider", "ProviderKey" }); + migrationBuilder.CreateIndex( name: "IX_IdentityUserLogins_UserId_LoginProvider_ProviderKey", table: "IdentityUserLogins", - columns: new[] { "UserId", "LoginProvider", "ProviderKey" }, - unique: true); + columns: new[] { "UserId", "LoginProvider", "ProviderKey" }); migrationBuilder.CreateIndex( - name: "IX_IdentityUserRoles_RoleId", + name: "IX_IdentityUserRoles_IdentityUserId1", table: "IdentityUserRoles", - column: "RoleId"); + column: "IdentityUserId1"); + + migrationBuilder.CreateIndex( + name: "IX_IdentityUserRoles_RoleId_UserId", + table: "IdentityUserRoles", + columns: new[] { "RoleId", "UserId" }); migrationBuilder.CreateIndex( name: "IX_IdentityUserRoles_UserId_RoleId", table: "IdentityUserRoles", - columns: new[] { "UserId", "RoleId" }, - unique: true); + columns: new[] { "UserId", "RoleId" }); migrationBuilder.CreateIndex( name: "IX_IdentityUserTokens_UserId_LoginProvider_Name", table: "IdentityUserTokens", - columns: new[] { "UserId", "LoginProvider", "Name" }, - unique: true); + columns: new[] { "UserId", "LoginProvider", "Name" }); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/IdentityDbContextModelSnapshot.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/IdentityDbContextModelSnapshot.cs index 4d71ec0d7d..dbb50e9b1f 100644 --- a/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/IdentityDbContextModelSnapshot.cs +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Migrations/IdentityDbContextModelSnapshot.cs @@ -32,8 +32,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations b.HasKey("Id"); - b.HasIndex("NormalizedName") - .HasName("RoleNameIndex"); + b.HasIndex("NormalizedName"); b.ToTable("IdentityRoles"); }); @@ -43,9 +42,12 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations b.Property("Id") .ValueGeneratedOnAdd(); - b.Property("ClaimType"); + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(256); - b.Property("ClaimValue"); + b.Property("ClaimValue") + .HasMaxLength(1024); b.Property("RoleId"); @@ -61,7 +63,9 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations b.Property("Id") .ValueGeneratedOnAdd(); - b.Property("AccessFailedCount"); + b.Property("AccessFailedCount") + .ValueGeneratedOnAdd() + .HasDefaultValue(0); b.Property("ConcurrencyStamp") .IsConcurrencyToken(); @@ -69,9 +73,13 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations b.Property("Email") .HasMaxLength(256); - b.Property("EmailConfirmed"); + b.Property("EmailConfirmed") + .ValueGeneratedOnAdd() + .HasDefaultValue(false); - b.Property("LockoutEnabled"); + b.Property("LockoutEnabled") + .ValueGeneratedOnAdd() + .HasDefaultValue(false); b.Property("LockoutEnd"); @@ -85,22 +93,24 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations b.Property("PhoneNumber"); - b.Property("PhoneNumberConfirmed"); + b.Property("PhoneNumberConfirmed") + .ValueGeneratedOnAdd() + .HasDefaultValue(false); b.Property("SecurityStamp"); - b.Property("TwoFactorEnabled"); + b.Property("TwoFactorEnabled") + .ValueGeneratedOnAdd() + .HasDefaultValue(false); b.Property("UserName") .HasMaxLength(256); b.HasKey("Id"); - b.HasIndex("NormalizedEmail") - .HasName("EmailIndex"); + b.HasIndex("NormalizedEmail"); - b.HasIndex("NormalizedUserName") - .HasName("UserNameIndex"); + b.HasIndex("NormalizedUserName"); b.ToTable("IdentityUsers"); }); @@ -110,9 +120,12 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations b.Property("Id") .ValueGeneratedOnAdd(); - b.Property("ClaimType"); + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(256); - b.Property("ClaimValue"); + b.Property("ClaimValue") + .HasMaxLength(1024); b.Property("UserId"); @@ -128,16 +141,23 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations b.Property("Id") .ValueGeneratedOnAdd(); - b.Property("LoginProvider"); + b.Property("LoginProvider") + .IsRequired() + .HasMaxLength(64); - b.Property("ProviderDisplayName"); + b.Property("ProviderDisplayName") + .HasMaxLength(128); - b.Property("ProviderKey"); + b.Property("ProviderKey") + .IsRequired() + .HasMaxLength(256); b.Property("UserId"); b.HasKey("Id"); + b.HasIndex("LoginProvider", "ProviderKey"); + b.HasIndex("UserId", "LoginProvider", "ProviderKey"); b.ToTable("IdentityUserLogins"); @@ -148,13 +168,17 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations b.Property("Id") .ValueGeneratedOnAdd(); + b.Property("IdentityUserId1"); + b.Property("RoleId"); b.Property("UserId"); b.HasKey("Id"); - b.HasIndex("RoleId"); + b.HasIndex("IdentityUserId1"); + + b.HasIndex("RoleId", "UserId"); b.HasIndex("UserId", "RoleId"); @@ -166,7 +190,9 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations b.Property("Id") .ValueGeneratedOnAdd(); - b.Property("LoginProvider"); + b.Property("LoginProvider") + .IsRequired() + .HasMaxLength(64); b.Property("Name"); @@ -207,13 +233,17 @@ namespace Volo.Abp.Identity.EntityFrameworkCore.Migrations modelBuilder.Entity("Volo.Abp.Identity.IdentityUserRole", b => { + b.HasOne("Volo.Abp.Identity.IdentityUser") + .WithMany("Roles") + .HasForeignKey("IdentityUserId1"); + b.HasOne("Volo.Abp.Identity.IdentityRole") .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade); b.HasOne("Volo.Abp.Identity.IdentityUser") - .WithMany("Roles") + .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade); }); diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContext.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContext.cs index 9b87563bd4..7f1c4ebdb1 100644 --- a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContext.cs +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContext.cs @@ -63,49 +63,62 @@ namespace Volo.Abp.Identity.EntityFrameworkCore { base.OnModelCreating(builder); + //Split configuration to dedicated classes + //TODO: Set Default Values for properties - //TODO: Split configuration to dedicated classes. builder.Entity(b => { b.ToTable("IdentityUsers"); - b.Property(u => u.UserName).HasMaxLength(256); - b.Property(u => u.NormalizedUserName).HasMaxLength(256); - b.Property(u => u.Email).HasMaxLength(256); - b.Property(u => u.NormalizedEmail).HasMaxLength(256); + b.Property(u => u.UserName).HasMaxLength(IdentityUser.MaxUserNameLength); + b.Property(u => u.NormalizedUserName).HasMaxLength(IdentityUser.MaxNormalizedUserNameLength); + b.Property(u => u.Email).HasMaxLength(IdentityUser.MaxEmailLength); + b.Property(u => u.NormalizedEmail).HasMaxLength(IdentityUser.MaxNormalizedEmailLength); + b.Property(u => u.EmailConfirmed).HasDefaultValue(false); + b.Property(u => u.PhoneNumberConfirmed).HasDefaultValue(false); + b.Property(u => u.TwoFactorEnabled).HasDefaultValue(false); + b.Property(u => u.LockoutEnabled).HasDefaultValue(false); + b.Property(u => u.AccessFailedCount).HasDefaultValue(0); b.HasMany(u => u.Claims).WithOne().HasForeignKey(uc => uc.UserId).IsRequired(); b.HasMany(u => u.Logins).WithOne().HasForeignKey(ul => ul.UserId).IsRequired(); b.HasMany(u => u.Roles).WithOne().HasForeignKey(ur => ur.UserId).IsRequired(); b.HasMany(u => u.Tokens).WithOne().HasForeignKey(ur => ur.UserId).IsRequired(); - b.HasIndex(u => u.NormalizedUserName).HasName("UserNameIndex"); - b.HasIndex(u => u.NormalizedEmail).HasName("EmailIndex"); + b.HasIndex(u => u.NormalizedUserName); + b.HasIndex(u => u.NormalizedEmail); }); builder.Entity(b => { b.ToTable("IdentityRoles"); - b.Property(r => r.ConcurrencyStamp).IsConcurrencyToken(); - b.Property(u => u.Name).HasMaxLength(256); - b.Property(u => u.NormalizedName).HasMaxLength(256); + b.Property(u => u.Name).HasMaxLength(IdentityRole.MaxNameLength); + b.Property(u => u.NormalizedName).HasMaxLength(IdentityRole.MaxNormalizedNameLength); - //TODO: Relation & Foreign Key! - //b.HasMany(r => r.Users).WithOne().HasForeignKey(ur => ur.RoleId).IsRequired(); b.HasMany(r => r.Claims).WithOne().HasForeignKey(rc => rc.RoleId).IsRequired(); - b.HasIndex(r => r.NormalizedName).HasName("RoleNameIndex"); + b.HasIndex(r => r.NormalizedName); }); builder.Entity(b => { b.ToTable("IdentityUserClaims"); + + b.Property(uc => uc.ClaimType).HasMaxLength(IdentityUserClaim.MaxClaimTypeLength).IsRequired(); + b.Property(uc => uc.ClaimValue).HasMaxLength(IdentityUserClaim.MaxClaimValueLength); + + b.HasIndex(uc => uc.UserId); }); builder.Entity(b => { b.ToTable("IdentityRoleClaims"); + + b.Property(uc => uc.ClaimType).HasMaxLength(IdentityRoleClaim.MaxClaimTypeLength).IsRequired(); + b.Property(uc => uc.ClaimValue).HasMaxLength(IdentityRoleClaim.MaxClaimValueLength); + + b.HasIndex(uc => uc.RoleId); }); builder.Entity(b => @@ -113,21 +126,30 @@ namespace Volo.Abp.Identity.EntityFrameworkCore b.ToTable("IdentityUserRoles"); b.HasOne().WithMany().HasForeignKey(ur => ur.RoleId).IsRequired(); + b.HasOne().WithMany().HasForeignKey(ur => ur.UserId).IsRequired(); b.HasIndex(r => new { r.UserId, r.RoleId }); + b.HasIndex(r => new { r.RoleId, r.UserId }); }); builder.Entity(b => { b.ToTable("IdentityUserLogins"); + b.Property(ul => ul.LoginProvider).HasMaxLength(IdentityUserLogin.MaxLoginProviderLength).IsRequired(); + b.Property(ul => ul.ProviderKey).HasMaxLength(IdentityUserLogin.MaxProviderKeyLength).IsRequired(); + b.Property(ul => ul.ProviderDisplayName).HasMaxLength(IdentityUserLogin.MaxProviderDisplayNameLength); + b.HasIndex(l => new { l.UserId, l.LoginProvider, l.ProviderKey }); + b.HasIndex(l => new { l.LoginProvider, l.ProviderKey }); }); builder.Entity(b => { b.ToTable("IdentityUserTokens"); + b.Property(ul => ul.LoginProvider).HasMaxLength(IdentityUserToken.MaxLoginProviderLength).IsRequired(); + b.HasIndex(l => new { l.UserId, l.LoginProvider, l.Name }); }); } diff --git a/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityRole.cs b/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityRole.cs index 72fe231174..8d0e73a2f1 100644 --- a/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityRole.cs +++ b/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityRole.cs @@ -15,6 +15,9 @@ namespace Volo.Abp.Identity /// public class IdentityRole : AggregateRoot, IHasConcurrencyStamp { + public const int MaxNameLength = 256; + public const int MaxNormalizedNameLength = MaxNameLength; + /// /// Gets or sets the name for this role. /// @@ -33,7 +36,7 @@ namespace Volo.Abp.Identity /// /// A random value that should change whenever a role is persisted to the store /// - public virtual string ConcurrencyStamp { get; set; } = Guid.NewGuid().ToString(); + public virtual string ConcurrencyStamp { get; set; } /// /// Initializes a new instance of . @@ -51,6 +54,7 @@ namespace Volo.Abp.Identity Id = id; Name = name; + ConcurrencyStamp = Guid.NewGuid().ToString(); } public void AddClaim([NotNull] Claim claim) diff --git a/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityRoleClaim.cs b/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityRoleClaim.cs index e831db3642..07d725b4a5 100644 --- a/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityRoleClaim.cs +++ b/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityRoleClaim.cs @@ -10,6 +10,9 @@ namespace Volo.Abp.Identity /// public class IdentityRoleClaim : Entity { + public const int MaxClaimTypeLength = IdentityUserClaim.MaxClaimTypeLength; + public const int MaxClaimValueLength = IdentityUserClaim.MaxClaimValueLength; + /// /// Gets or sets the of the primary key of the role associated with this claim. /// @@ -27,11 +30,13 @@ namespace Volo.Abp.Identity protected IdentityRoleClaim() { - + } public IdentityRoleClaim(Guid roleId, [NotNull] Claim claim) { + //TODO: Where to set Id? + Check.NotNull(claim, nameof(claim)); RoleId = roleId; @@ -41,7 +46,6 @@ namespace Volo.Abp.Identity public IdentityRoleClaim(Guid roleId, [NotNull] string claimType, string claimValue) { - Check.NotNull(roleId, nameof(roleId)); Check.NotNull(claimType, nameof(claimType)); RoleId = roleId; diff --git a/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUser.cs b/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUser.cs index 79858fdb7c..7074f1dc44 100644 --- a/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUser.cs +++ b/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUser.cs @@ -15,6 +15,11 @@ namespace Volo.Abp.Identity public class IdentityUser : AggregateRoot, IHasConcurrencyStamp { + public const int MaxUserNameLength = 256; + public const int MaxNormalizedUserNameLength = MaxUserNameLength; + public const int MaxEmailLength = 256; + public const int MaxNormalizedEmailLength = MaxEmailLength; + /// /// Gets or sets the user name for this user. /// @@ -54,7 +59,7 @@ namespace Volo.Abp.Identity /// /// A random value that must change whenever a user is persisted to the store /// - public virtual string ConcurrencyStamp { get; set; } = Guid.NewGuid().ToString(); + public virtual string ConcurrencyStamp { get; set; } /// /// Gets or sets a telephone number for the user. @@ -125,9 +130,10 @@ namespace Volo.Abp.Identity Id = id; UserName = userName; + ConcurrencyStamp = Guid.NewGuid().ToString(); } - public void AddRole([NotNull] Guid roleId) + public void AddRole(Guid roleId) { Check.NotNull(roleId, nameof(roleId)); diff --git a/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserClaim.cs b/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserClaim.cs index 6dd7a56020..e0100f809a 100644 --- a/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserClaim.cs +++ b/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserClaim.cs @@ -10,6 +10,9 @@ namespace Volo.Abp.Identity /// public class IdentityUserClaim : Entity { + public const int MaxClaimTypeLength = 256; + public const int MaxClaimValueLength = 1024; + /// /// Gets or sets the primary key of the user associated with this claim. /// @@ -32,6 +35,8 @@ namespace Volo.Abp.Identity public IdentityUserClaim(Guid userId, [NotNull] Claim claim) { + //TODO: Where to set Id? + Check.NotNull(claim, nameof(claim)); UserId = userId; diff --git a/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserLogin.cs b/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserLogin.cs index eb32b92c9b..c84edd1546 100644 --- a/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserLogin.cs +++ b/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserLogin.cs @@ -12,6 +12,10 @@ namespace Volo.Abp.Identity /// public class IdentityUserLogin : Entity { + public const int MaxLoginProviderLength = 64; + public const int MaxProviderKeyLength = 256; + public const int MaxProviderDisplayNameLength = 128; + /// /// Gets or sets the of the primary key of the user associated with this login. /// @@ -42,6 +46,8 @@ namespace Volo.Abp.Identity Check.NotNull(loginProvider, nameof(loginProvider)); Check.NotNull(providerKey, nameof(providerKey)); + //TODO: Where to set Id? + UserId = userId; LoginProvider = loginProvider; ProviderKey = providerKey; diff --git a/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserRole.cs b/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserRole.cs index 8f8a591bc1..798dc6fb64 100644 --- a/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserRole.cs +++ b/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserRole.cs @@ -25,6 +25,8 @@ namespace Volo.Abp.Identity public IdentityUserRole(Guid userId, Guid roleId) { + //TODO: Where to set Id? + UserId = userId; RoleId = roleId; } diff --git a/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserToken.cs b/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserToken.cs index fd750d851b..0ea06323be 100644 --- a/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserToken.cs +++ b/src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserToken.cs @@ -9,6 +9,8 @@ namespace Volo.Abp.Identity /// public class IdentityUserToken : Entity { + public const int MaxLoginProviderLength = 64; + /// /// Gets or sets the primary key of the user that the token belongs to. /// @@ -34,12 +36,13 @@ namespace Volo.Abp.Identity } - public IdentityUserToken(Guid userId, [NotNull] string loginProvider, [NotNull] string name, string value) //TODO: Can value be null? + public IdentityUserToken(Guid userId, [NotNull] string loginProvider, [NotNull] string name, string value) { - Check.NotNull(userId, nameof(userId)); Check.NotNull(loginProvider, nameof(loginProvider)); Check.NotNull(name, nameof(name)); + //TODO: Where to set Id? + UserId = userId; LoginProvider = loginProvider; Name = name;