Browse Source

Add ef migrations to the monolithic application

pull/73/head
dsanz 8 years ago
parent
commit
817edc8791
5 changed files with 307 additions and 3 deletions
  1. +1
    -2
      src/Web/WebMonolithic/eShopWeb/Infrastructure/CatalogContextSeed.cs
  2. +99
    -0
      src/Web/WebMonolithic/eShopWeb/Infrastructure/Migrations/20170302162241_Initial.Designer.cs
  3. +108
    -0
      src/Web/WebMonolithic/eShopWeb/Infrastructure/Migrations/20170302162241_Initial.cs
  4. +98
    -0
      src/Web/WebMonolithic/eShopWeb/Infrastructure/Migrations/CatalogContextModelSnapshot.cs
  5. +1
    -1
      src/Web/WebMonolithic/eShopWeb/eShopWeb.csproj

+ 1
- 2
src/Web/WebMonolithic/eShopWeb/Infrastructure/CatalogContextSeed.cs View File

@ -19,8 +19,7 @@
var context = (CatalogContext)applicationBuilder var context = (CatalogContext)applicationBuilder
.ApplicationServices.GetService(typeof(CatalogContext)); .ApplicationServices.GetService(typeof(CatalogContext));
//context.Database.Migrate();
context.Database.EnsureCreated();
context.Database.Migrate();
if (!context.CatalogBrands.Any()) if (!context.CatalogBrands.Any())
{ {


+ 99
- 0
src/Web/WebMonolithic/eShopWeb/Infrastructure/Migrations/20170302162241_Initial.Designer.cs View File

@ -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<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("Brand")
.IsRequired()
.HasMaxLength(100);
b.HasKey("Id");
b.ToTable("CatalogBrand");
});
modelBuilder.Entity("eShopWeb.Models.CatalogItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<int>("CatalogBrandId");
b.Property<int>("CatalogTypeId");
b.Property<string>("Description");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50);
b.Property<string>("PictureUri");
b.Property<decimal>("Price");
b.HasKey("Id");
b.HasIndex("CatalogBrandId");
b.HasIndex("CatalogTypeId");
b.ToTable("Catalog");
});
modelBuilder.Entity("eShopWeb.Models.CatalogType", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("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);
});
}
}
}

+ 108
- 0
src/Web/WebMonolithic/eShopWeb/Infrastructure/Migrations/20170302162241_Initial.cs View File

@ -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<int>(nullable: false),
Brand = table.Column<string>(maxLength: 100, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_CatalogBrand", x => x.Id);
});
migrationBuilder.CreateTable(
name: "CatalogType",
columns: table => new
{
Id = table.Column<int>(nullable: false),
Type = table.Column<string>(maxLength: 100, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_CatalogType", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Catalog",
columns: table => new
{
Id = table.Column<int>(nullable: false),
CatalogBrandId = table.Column<int>(nullable: false),
CatalogTypeId = table.Column<int>(nullable: false),
Description = table.Column<string>(nullable: true),
Name = table.Column<string>(maxLength: 50, nullable: false),
PictureUri = table.Column<string>(nullable: true),
Price = table.Column<decimal>(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");
}
}
}

+ 98
- 0
src/Web/WebMonolithic/eShopWeb/Infrastructure/Migrations/CatalogContextModelSnapshot.cs View File

@ -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<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("Brand")
.IsRequired()
.HasMaxLength(100);
b.HasKey("Id");
b.ToTable("CatalogBrand");
});
modelBuilder.Entity("eShopWeb.Models.CatalogItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<int>("CatalogBrandId");
b.Property<int>("CatalogTypeId");
b.Property<string>("Description");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50);
b.Property<string>("PictureUri");
b.Property<decimal>("Price");
b.HasKey("Id");
b.HasIndex("CatalogBrandId");
b.HasIndex("CatalogTypeId");
b.ToTable("Catalog");
});
modelBuilder.Entity("eShopWeb.Models.CatalogType", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("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);
});
}
}
}

+ 1
- 1
src/Web/WebMonolithic/eShopWeb/eShopWeb.csproj View File

@ -25,11 +25,11 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0-msbuild3-final" /> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0-msbuild3-final" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0-msbuild3-final" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Models\" /> <Folder Include="Models\" />
<Folder Include="Pics\" /> <Folder Include="Pics\" />
<Folder Include="Infrastructure\" />
<Folder Include="Views\Catalog\" /> <Folder Include="Views\Catalog\" />
<Folder Include="wwwroot\css\catalog\" /> <Folder Include="wwwroot\css\catalog\" />
<Folder Include="wwwroot\fonts\" /> <Folder Include="wwwroot\fonts\" />


Loading…
Cancel
Save