From 817edc87915ba7117f4e849d0f26b566bfddfcbd Mon Sep 17 00:00:00 2001 From: dsanz Date: Thu, 2 Mar 2017 17:37:31 +0100 Subject: [PATCH] Add ef migrations to the monolithic application --- .../Infrastructure/CatalogContextSeed.cs | 3 +- .../20170302162241_Initial.Designer.cs | 99 ++++++++++++++++ .../Migrations/20170302162241_Initial.cs | 108 ++++++++++++++++++ .../Migrations/CatalogContextModelSnapshot.cs | 98 ++++++++++++++++ .../WebMonolithic/eShopWeb/eShopWeb.csproj | 2 +- 5 files changed, 307 insertions(+), 3 deletions(-) create mode 100644 src/Web/WebMonolithic/eShopWeb/Infrastructure/Migrations/20170302162241_Initial.Designer.cs create mode 100644 src/Web/WebMonolithic/eShopWeb/Infrastructure/Migrations/20170302162241_Initial.cs create mode 100644 src/Web/WebMonolithic/eShopWeb/Infrastructure/Migrations/CatalogContextModelSnapshot.cs diff --git a/src/Web/WebMonolithic/eShopWeb/Infrastructure/CatalogContextSeed.cs b/src/Web/WebMonolithic/eShopWeb/Infrastructure/CatalogContextSeed.cs index 66b9e50e6..5e5bd4be8 100644 --- a/src/Web/WebMonolithic/eShopWeb/Infrastructure/CatalogContextSeed.cs +++ b/src/Web/WebMonolithic/eShopWeb/Infrastructure/CatalogContextSeed.cs @@ -19,8 +19,7 @@ var context = (CatalogContext)applicationBuilder .ApplicationServices.GetService(typeof(CatalogContext)); - //context.Database.Migrate(); - context.Database.EnsureCreated(); + context.Database.Migrate(); if (!context.CatalogBrands.Any()) { diff --git a/src/Web/WebMonolithic/eShopWeb/Infrastructure/Migrations/20170302162241_Initial.Designer.cs b/src/Web/WebMonolithic/eShopWeb/Infrastructure/Migrations/20170302162241_Initial.Designer.cs new file mode 100644 index 000000000..05bea6db2 --- /dev/null +++ b/src/Web/WebMonolithic/eShopWeb/Infrastructure/Migrations/20170302162241_Initial.Designer.cs @@ -0,0 +1,99 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using eShopWeb.Infrastructure; + +namespace eShopWeb.Infrastructure.Migrations +{ + [DbContext(typeof(CatalogContext))] + [Migration("20170302162241_Initial")] + partial class Initial + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.1.0-rtm-22752") + .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 => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Brand") + .IsRequired() + .HasMaxLength(100); + + b.HasKey("Id"); + + b.ToTable("CatalogBrand"); + }); + + modelBuilder.Entity("eShopWeb.Models.CatalogItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("CatalogBrandId"); + + b.Property("CatalogTypeId"); + + b.Property("Description"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50); + + b.Property("PictureUri"); + + b.Property("Price"); + + b.HasKey("Id"); + + b.HasIndex("CatalogBrandId"); + + b.HasIndex("CatalogTypeId"); + + b.ToTable("Catalog"); + }); + + modelBuilder.Entity("eShopWeb.Models.CatalogType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Type") + .IsRequired() + .HasMaxLength(100); + + b.HasKey("Id"); + + b.ToTable("CatalogType"); + }); + + modelBuilder.Entity("eShopWeb.Models.CatalogItem", b => + { + b.HasOne("eShopWeb.Models.CatalogBrand", "CatalogBrand") + .WithMany() + .HasForeignKey("CatalogBrandId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("eShopWeb.Models.CatalogType", "CatalogType") + .WithMany() + .HasForeignKey("CatalogTypeId") + .OnDelete(DeleteBehavior.Cascade); + }); + } + } +} diff --git a/src/Web/WebMonolithic/eShopWeb/Infrastructure/Migrations/20170302162241_Initial.cs b/src/Web/WebMonolithic/eShopWeb/Infrastructure/Migrations/20170302162241_Initial.cs new file mode 100644 index 000000000..b27111cce --- /dev/null +++ b/src/Web/WebMonolithic/eShopWeb/Infrastructure/Migrations/20170302162241_Initial.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace eShopWeb.Infrastructure.Migrations +{ + public partial class Initial : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateSequence( + name: "catalog_brand_hilo", + incrementBy: 10); + + migrationBuilder.CreateSequence( + name: "catalog_hilo", + incrementBy: 10); + + migrationBuilder.CreateSequence( + name: "catalog_type_hilo", + incrementBy: 10); + + migrationBuilder.CreateTable( + name: "CatalogBrand", + columns: table => new + { + Id = table.Column(nullable: false), + Brand = table.Column(maxLength: 100, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CatalogBrand", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CatalogType", + columns: table => new + { + Id = table.Column(nullable: false), + Type = table.Column(maxLength: 100, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CatalogType", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Catalog", + columns: table => new + { + Id = table.Column(nullable: false), + CatalogBrandId = table.Column(nullable: false), + CatalogTypeId = table.Column(nullable: false), + Description = table.Column(nullable: true), + Name = table.Column(maxLength: 50, nullable: false), + PictureUri = table.Column(nullable: true), + Price = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Catalog", x => x.Id); + table.ForeignKey( + name: "FK_Catalog_CatalogBrand_CatalogBrandId", + column: x => x.CatalogBrandId, + principalTable: "CatalogBrand", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Catalog_CatalogType_CatalogTypeId", + column: x => x.CatalogTypeId, + principalTable: "CatalogType", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Catalog_CatalogBrandId", + table: "Catalog", + column: "CatalogBrandId"); + + migrationBuilder.CreateIndex( + name: "IX_Catalog_CatalogTypeId", + table: "Catalog", + column: "CatalogTypeId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Catalog"); + + migrationBuilder.DropTable( + name: "CatalogBrand"); + + migrationBuilder.DropTable( + name: "CatalogType"); + + migrationBuilder.DropSequence( + name: "catalog_brand_hilo"); + + migrationBuilder.DropSequence( + name: "catalog_hilo"); + + migrationBuilder.DropSequence( + name: "catalog_type_hilo"); + } + } +} diff --git a/src/Web/WebMonolithic/eShopWeb/Infrastructure/Migrations/CatalogContextModelSnapshot.cs b/src/Web/WebMonolithic/eShopWeb/Infrastructure/Migrations/CatalogContextModelSnapshot.cs new file mode 100644 index 000000000..64d6c1b7a --- /dev/null +++ b/src/Web/WebMonolithic/eShopWeb/Infrastructure/Migrations/CatalogContextModelSnapshot.cs @@ -0,0 +1,98 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using eShopWeb.Infrastructure; + +namespace eShopWeb.Infrastructure.Migrations +{ + [DbContext(typeof(CatalogContext))] + partial class CatalogContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.1.0-rtm-22752") + .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 => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Brand") + .IsRequired() + .HasMaxLength(100); + + b.HasKey("Id"); + + b.ToTable("CatalogBrand"); + }); + + modelBuilder.Entity("eShopWeb.Models.CatalogItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("CatalogBrandId"); + + b.Property("CatalogTypeId"); + + b.Property("Description"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50); + + b.Property("PictureUri"); + + b.Property("Price"); + + b.HasKey("Id"); + + b.HasIndex("CatalogBrandId"); + + b.HasIndex("CatalogTypeId"); + + b.ToTable("Catalog"); + }); + + modelBuilder.Entity("eShopWeb.Models.CatalogType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Type") + .IsRequired() + .HasMaxLength(100); + + b.HasKey("Id"); + + b.ToTable("CatalogType"); + }); + + modelBuilder.Entity("eShopWeb.Models.CatalogItem", b => + { + b.HasOne("eShopWeb.Models.CatalogBrand", "CatalogBrand") + .WithMany() + .HasForeignKey("CatalogBrandId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("eShopWeb.Models.CatalogType", "CatalogType") + .WithMany() + .HasForeignKey("CatalogTypeId") + .OnDelete(DeleteBehavior.Cascade); + }); + } + } +} diff --git a/src/Web/WebMonolithic/eShopWeb/eShopWeb.csproj b/src/Web/WebMonolithic/eShopWeb/eShopWeb.csproj index 5480f18bf..749087ce4 100644 --- a/src/Web/WebMonolithic/eShopWeb/eShopWeb.csproj +++ b/src/Web/WebMonolithic/eShopWeb/eShopWeb.csproj @@ -25,11 +25,11 @@ + -