From eefc8170cbbfccaa2c121c311d4d47eb81bcf7d6 Mon Sep 17 00:00:00 2001 From: Steve Smith Date: Tue, 22 Aug 2017 17:58:53 -0400 Subject: [PATCH] Updating and testing migrations (#42) Updating readme to describe how to run migrations --- README.md | 49 +++- src/Infrastructure/Data/CatalogContext.cs | 4 + ...> 20170822214048_InitialModel.Designer.cs} | 61 ++++- ...tial.cs => 20170822214048_InitialModel.cs} | 49 +++- .../Migrations/CatalogContextModelSnapshot.cs | 58 ++++- ...822214310_InitialIdentityModel.Designer.cs | 215 ++++++++++++++++++ .../20170822214310_InitialIdentityModel.cs | 213 +++++++++++++++++ .../AppIdentityDbContextModelSnapshot.cs | 214 +++++++++++++++++ src/Infrastructure/Infrastructure.csproj | 1 + 9 files changed, 842 insertions(+), 22 deletions(-) rename src/Infrastructure/Data/Migrations/{20170302162241_Initial.Designer.cs => 20170822214048_InitialModel.Designer.cs} (61%) rename src/Infrastructure/Data/Migrations/{20170302162241_Initial.cs => 20170822214048_InitialModel.cs} (65%) create mode 100644 src/Infrastructure/Identity/Migrations/20170822214310_InitialIdentityModel.Designer.cs create mode 100644 src/Infrastructure/Identity/Migrations/20170822214310_InitialIdentityModel.cs create mode 100644 src/Infrastructure/Identity/Migrations/AppIdentityDbContextModelSnapshot.cs diff --git a/README.md b/README.md index a5c63ae..a6f8807 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,54 @@ The goal for this sample is to demonstrate some of the principles and patterns d After cloning or downloading the sample you should be able to run it using an In Memory database immediately. -If you wish to use the sample with a persistent database, you will need to run its Entity Framework Core migrations before you will be able to run the app. To do so, open a command prompt in the Web folder and execute the following commands: +If you wish to use the sample with a persistent database, you will need to run its Entity Framework Core migrations before you will be able to run the app, and update `ConfigureServices` method in `Startup.cs`. + +### Configuring the sample to use SQL Server + +1. Update `Startup.cs`'s `ConfigureServices` method as follows: + +``` +public void ConfigureServices(IServiceCollection services) +{ + // Requires LocalDB which can be installed with SQL Server Express 2016 + // https://www.microsoft.com/en-us/download/details.aspx?id=54284 + services.AddDbContext(c => + { + try + { + //c.UseInMemoryDatabase("Catalog"); + c.UseSqlServer(Configuration.GetConnectionString("CatalogConnection")); + c.ConfigureWarnings(wb => + { + //By default, in this application, we don't want to have client evaluations + wb.Log(RelationalEventId.QueryClientEvaluationWarning); + }); + } + catch (System.Exception ex ) + { + var message = ex.Message; + } + }); + + // Add Identity DbContext + services.AddDbContext(options => + //options.UseInMemoryDatabase("Identity")); + options.UseSqlServer(Configuration.GetConnectionString("IdentityConnection"))); + + +// leave the rest of the method as-is +``` +1. Ensure your connection strings in `appsettings.json` point to a local SQL Server instance. + +1. Open a command prompt in the Web folder and execute the following commands: ``` dotnet restore -dotnet ef database update --context Microsoft.eShopWeb.Infrastructure.CatalogContext +dotnet ef database update -c catalogcontext -p ../Infrastructure/Infrastructure.csproj -s Web.csproj +dotnet ef database update -c appidentitydbcontext -p ../Infrastructure/Infrastructure.csproj -s Web.csproj ``` -**NOTE** The application uses a separate DbContext for its authentication system, which is not yet complete. \ No newline at end of file +These commands will create two separate databases, one for the store's catalog data and shopping cart information, and one for the app's user credentials and identity data. + +1. Run the application. +The first time you run the application, it will seed both databases with data such that you should see products in the store, and you should be able to log in using the demouser@microsoft.com account. diff --git a/src/Infrastructure/Data/CatalogContext.cs b/src/Infrastructure/Data/CatalogContext.cs index 52becb7..da13128 100644 --- a/src/Infrastructure/Data/CatalogContext.cs +++ b/src/Infrastructure/Data/CatalogContext.cs @@ -12,6 +12,10 @@ namespace Infrastructure.Data public CatalogContext(DbContextOptions options) : base(options) { } + //public CatalogContext() + //{ + // // required by migrations + //} public DbSet Baskets { get; set; } public DbSet CatalogItems { get; set; } public DbSet CatalogBrands { get; set; } diff --git a/src/Infrastructure/Data/Migrations/20170302162241_Initial.Designer.cs b/src/Infrastructure/Data/Migrations/20170822214048_InitialModel.Designer.cs similarity index 61% rename from src/Infrastructure/Data/Migrations/20170302162241_Initial.Designer.cs rename to src/Infrastructure/Data/Migrations/20170822214048_InitialModel.Designer.cs index e546fbe..9c8b969 100644 --- a/src/Infrastructure/Data/Migrations/20170302162241_Initial.Designer.cs +++ b/src/Infrastructure/Data/Migrations/20170822214048_InitialModel.Designer.cs @@ -1,24 +1,58 @@ -using Microsoft.EntityFrameworkCore; +using System; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; +using Infrastructure.Data; namespace Infrastructure.Data.Migrations { [DbContext(typeof(CatalogContext))] - [Migration("20170302162241_Initial")] - partial class Initial + [Migration("20170822214048_InitialModel")] + partial class InitialModel { protected override void BuildTargetModel(ModelBuilder modelBuilder) { modelBuilder - .HasAnnotation("ProductVersion", "1.1.0-rtm-22752") + .HasAnnotation("ProductVersion", "1.1.2") .HasAnnotation("SqlServer:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'") .HasAnnotation("SqlServer:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'") .HasAnnotation("SqlServer:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - modelBuilder.Entity("eShopWeb.Models.CatalogBrand", b => + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.Basket", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BuyerId"); + + b.HasKey("Id"); + + b.ToTable("Baskets"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BasketId"); + + b.Property("CatalogItemId"); + + b.Property("Quantity"); + + b.Property("UnitPrice"); + + b.HasKey("Id"); + + b.HasIndex("BasketId"); + + b.ToTable("BasketItem"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogBrand", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -34,7 +68,7 @@ namespace Infrastructure.Data.Migrations b.ToTable("CatalogBrand"); }); - modelBuilder.Entity("eShopWeb.Models.CatalogItem", b => + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogItem", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -64,7 +98,7 @@ namespace Infrastructure.Data.Migrations b.ToTable("Catalog"); }); - modelBuilder.Entity("eShopWeb.Models.CatalogType", b => + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogType", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -80,14 +114,21 @@ namespace Infrastructure.Data.Migrations b.ToTable("CatalogType"); }); - modelBuilder.Entity("eShopWeb.Models.CatalogItem", b => + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketItem", b => { - b.HasOne("eShopWeb.Models.CatalogBrand", "CatalogBrand") + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.Basket") + .WithMany("Items") + .HasForeignKey("BasketId"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogItem", b => + { + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogBrand", "CatalogBrand") .WithMany() .HasForeignKey("CatalogBrandId") .OnDelete(DeleteBehavior.Cascade); - b.HasOne("eShopWeb.Models.CatalogType", "CatalogType") + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogType", "CatalogType") .WithMany() .HasForeignKey("CatalogTypeId") .OnDelete(DeleteBehavior.Cascade); diff --git a/src/Infrastructure/Data/Migrations/20170302162241_Initial.cs b/src/Infrastructure/Data/Migrations/20170822214048_InitialModel.cs similarity index 65% rename from src/Infrastructure/Data/Migrations/20170302162241_Initial.cs rename to src/Infrastructure/Data/Migrations/20170822214048_InitialModel.cs index 009daf6..ee87204 100644 --- a/src/Infrastructure/Data/Migrations/20170302162241_Initial.cs +++ b/src/Infrastructure/Data/Migrations/20170822214048_InitialModel.cs @@ -1,10 +1,11 @@ using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Metadata; namespace Infrastructure.Data.Migrations { - public partial class Initial : Migration + public partial class InitialModel : Migration { protected override void Up(MigrationBuilder migrationBuilder) { @@ -20,6 +21,19 @@ namespace Infrastructure.Data.Migrations name: "catalog_type_hilo", incrementBy: 10); + migrationBuilder.CreateTable( + name: "Baskets", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + BuyerId = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Baskets", x => x.Id); + }); + migrationBuilder.CreateTable( name: "CatalogBrand", columns: table => new @@ -44,6 +58,28 @@ namespace Infrastructure.Data.Migrations table.PrimaryKey("PK_CatalogType", x => x.Id); }); + migrationBuilder.CreateTable( + name: "BasketItem", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + BasketId = table.Column(nullable: true), + CatalogItemId = table.Column(nullable: false), + Quantity = table.Column(nullable: false), + UnitPrice = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_BasketItem", x => x.Id); + table.ForeignKey( + name: "FK_BasketItem_Baskets_BasketId", + column: x => x.BasketId, + principalTable: "Baskets", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + migrationBuilder.CreateTable( name: "Catalog", columns: table => new @@ -73,6 +109,11 @@ namespace Infrastructure.Data.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateIndex( + name: "IX_BasketItem_BasketId", + table: "BasketItem", + column: "BasketId"); + migrationBuilder.CreateIndex( name: "IX_Catalog_CatalogBrandId", table: "Catalog", @@ -86,9 +127,15 @@ namespace Infrastructure.Data.Migrations protected override void Down(MigrationBuilder migrationBuilder) { + migrationBuilder.DropTable( + name: "BasketItem"); + migrationBuilder.DropTable( name: "Catalog"); + migrationBuilder.DropTable( + name: "Baskets"); + migrationBuilder.DropTable( name: "CatalogBrand"); diff --git a/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs b/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs index 937b9ec..7bebf78 100644 --- a/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs +++ b/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs @@ -1,6 +1,9 @@ -using Microsoft.EntityFrameworkCore; +using System; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Infrastructure.Data; namespace Infrastructure.Data.Migrations { @@ -10,13 +13,45 @@ namespace Infrastructure.Data.Migrations protected override void BuildModel(ModelBuilder modelBuilder) { modelBuilder - .HasAnnotation("ProductVersion", "1.1.0-rtm-22752") + .HasAnnotation("ProductVersion", "1.1.2") .HasAnnotation("SqlServer:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'") .HasAnnotation("SqlServer:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'") .HasAnnotation("SqlServer:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - modelBuilder.Entity("eShopWeb.Models.CatalogBrand", b => + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.Basket", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BuyerId"); + + b.HasKey("Id"); + + b.ToTable("Baskets"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BasketId"); + + b.Property("CatalogItemId"); + + b.Property("Quantity"); + + b.Property("UnitPrice"); + + b.HasKey("Id"); + + b.HasIndex("BasketId"); + + b.ToTable("BasketItem"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogBrand", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -32,7 +67,7 @@ namespace Infrastructure.Data.Migrations b.ToTable("CatalogBrand"); }); - modelBuilder.Entity("eShopWeb.Models.CatalogItem", b => + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogItem", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -62,7 +97,7 @@ namespace Infrastructure.Data.Migrations b.ToTable("Catalog"); }); - modelBuilder.Entity("eShopWeb.Models.CatalogType", b => + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogType", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -78,14 +113,21 @@ namespace Infrastructure.Data.Migrations b.ToTable("CatalogType"); }); - modelBuilder.Entity("eShopWeb.Models.CatalogItem", b => + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketItem", b => { - b.HasOne("eShopWeb.Models.CatalogBrand", "CatalogBrand") + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.Basket") + .WithMany("Items") + .HasForeignKey("BasketId"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogItem", b => + { + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogBrand", "CatalogBrand") .WithMany() .HasForeignKey("CatalogBrandId") .OnDelete(DeleteBehavior.Cascade); - b.HasOne("eShopWeb.Models.CatalogType", "CatalogType") + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogType", "CatalogType") .WithMany() .HasForeignKey("CatalogTypeId") .OnDelete(DeleteBehavior.Cascade); diff --git a/src/Infrastructure/Identity/Migrations/20170822214310_InitialIdentityModel.Designer.cs b/src/Infrastructure/Identity/Migrations/20170822214310_InitialIdentityModel.Designer.cs new file mode 100644 index 0000000..7948c6f --- /dev/null +++ b/src/Infrastructure/Identity/Migrations/20170822214310_InitialIdentityModel.Designer.cs @@ -0,0 +1,215 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Infrastructure.Identity; + +namespace Infrastructure.Identity.Migrations +{ + [DbContext(typeof(AppIdentityDbContext))] + [Migration("20170822214310_InitialIdentityModel")] + partial class InitialIdentityModel + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.1.2") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Infrastructure.Identity.ApplicationUser", 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("AspNetUsers"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.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("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("RoleId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin", b => + { + b.Property("LoginProvider"); + + b.Property("ProviderKey"); + + b.Property("ProviderDisplayName"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole", b => + { + b.Property("UserId"); + + b.Property("RoleId"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken", b => + { + b.Property("UserId"); + + b.Property("LoginProvider"); + + b.Property("Name"); + + b.Property("Value"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole") + .WithMany("Claims") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim", b => + { + b.HasOne("Infrastructure.Identity.ApplicationUser") + .WithMany("Claims") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin", b => + { + b.HasOne("Infrastructure.Identity.ApplicationUser") + .WithMany("Logins") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole") + .WithMany("Users") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Infrastructure.Identity.ApplicationUser") + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + } + } +} diff --git a/src/Infrastructure/Identity/Migrations/20170822214310_InitialIdentityModel.cs b/src/Infrastructure/Identity/Migrations/20170822214310_InitialIdentityModel.cs new file mode 100644 index 0000000..0ab21dd --- /dev/null +++ b/src/Infrastructure/Identity/Migrations/20170822214310_InitialIdentityModel.cs @@ -0,0 +1,213 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Metadata; + +namespace Infrastructure.Identity.Migrations +{ + public partial class InitialIdentityModel : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AspNetUsers", + columns: table => new + { + Id = table.Column(nullable: false), + AccessFailedCount = table.Column(nullable: false), + ConcurrencyStamp = table.Column(nullable: true), + Email = table.Column(maxLength: 256, nullable: true), + EmailConfirmed = table.Column(nullable: false), + LockoutEnabled = table.Column(nullable: 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), + SecurityStamp = table.Column(nullable: true), + TwoFactorEnabled = table.Column(nullable: false), + UserName = table.Column(maxLength: 256, nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUsers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetRoles", + columns: table => new + { + Id = table.Column(nullable: false), + ConcurrencyStamp = table.Column(nullable: true), + Name = table.Column(maxLength: 256, nullable: true), + NormalizedName = table.Column(maxLength: 256, nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserTokens", + columns: table => new + { + UserId = table.Column(nullable: false), + LoginProvider = table.Column(nullable: false), + Name = table.Column(nullable: false), + Value = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserClaims", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + ClaimType = table.Column(nullable: true), + ClaimValue = table.Column(nullable: true), + UserId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetUserClaims_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserLogins", + columns: table => new + { + LoginProvider = table.Column(nullable: false), + ProviderKey = table.Column(nullable: false), + ProviderDisplayName = table.Column(nullable: true), + UserId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); + table.ForeignKey( + name: "FK_AspNetUserLogins_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetRoleClaims", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + ClaimType = table.Column(nullable: true), + ClaimValue = table.Column(nullable: true), + RoleId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserRoles", + columns: table => new + { + UserId = table.Column(nullable: false), + RoleId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "EmailIndex", + table: "AspNetUsers", + column: "NormalizedEmail"); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + table: "AspNetUsers", + column: "NormalizedUserName", + unique: true); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + table: "AspNetRoles", + column: "NormalizedName", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_AspNetRoleClaims_RoleId", + table: "AspNetRoleClaims", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserClaims_UserId", + table: "AspNetUserClaims", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserLogins_UserId", + table: "AspNetUserLogins", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserRoles_RoleId", + table: "AspNetUserRoles", + column: "RoleId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AspNetRoleClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserLogins"); + + migrationBuilder.DropTable( + name: "AspNetUserRoles"); + + migrationBuilder.DropTable( + name: "AspNetUserTokens"); + + migrationBuilder.DropTable( + name: "AspNetRoles"); + + migrationBuilder.DropTable( + name: "AspNetUsers"); + } + } +} diff --git a/src/Infrastructure/Identity/Migrations/AppIdentityDbContextModelSnapshot.cs b/src/Infrastructure/Identity/Migrations/AppIdentityDbContextModelSnapshot.cs new file mode 100644 index 0000000..5f56ae8 --- /dev/null +++ b/src/Infrastructure/Identity/Migrations/AppIdentityDbContextModelSnapshot.cs @@ -0,0 +1,214 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Infrastructure.Identity; + +namespace Infrastructure.Identity.Migrations +{ + [DbContext(typeof(AppIdentityDbContext))] + partial class AppIdentityDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.1.2") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Infrastructure.Identity.ApplicationUser", 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("AspNetUsers"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.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("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("RoleId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin", b => + { + b.Property("LoginProvider"); + + b.Property("ProviderKey"); + + b.Property("ProviderDisplayName"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole", b => + { + b.Property("UserId"); + + b.Property("RoleId"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken", b => + { + b.Property("UserId"); + + b.Property("LoginProvider"); + + b.Property("Name"); + + b.Property("Value"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole") + .WithMany("Claims") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim", b => + { + b.HasOne("Infrastructure.Identity.ApplicationUser") + .WithMany("Claims") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin", b => + { + b.HasOne("Infrastructure.Identity.ApplicationUser") + .WithMany("Logins") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole") + .WithMany("Users") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Infrastructure.Identity.ApplicationUser") + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + } + } +} diff --git a/src/Infrastructure/Infrastructure.csproj b/src/Infrastructure/Infrastructure.csproj index 7c14c05..06ff46f 100644 --- a/src/Infrastructure/Infrastructure.csproj +++ b/src/Infrastructure/Infrastructure.csproj @@ -23,6 +23,7 @@ +