Skip to content

Commit 817edc8

Browse files
committed
Add ef migrations to the monolithic application
1 parent fb2da83 commit 817edc8

5 files changed

Lines changed: 307 additions & 3 deletions

File tree

src/Web/WebMonolithic/eShopWeb/Infrastructure/CatalogContextSeed.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ public static async Task SeedAsync(IApplicationBuilder applicationBuilder, ILogg
1919
var context = (CatalogContext)applicationBuilder
2020
.ApplicationServices.GetService(typeof(CatalogContext));
2121

22-
//context.Database.Migrate();
23-
context.Database.EnsureCreated();
22+
context.Database.Migrate();
2423

2524
if (!context.CatalogBrands.Any())
2625
{

src/Web/WebMonolithic/eShopWeb/Infrastructure/Migrations/20170302162241_Initial.Designer.cs

Lines changed: 99 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Microsoft.EntityFrameworkCore.Migrations;
4+
5+
namespace eShopWeb.Infrastructure.Migrations
6+
{
7+
public partial class Initial : Migration
8+
{
9+
protected override void Up(MigrationBuilder migrationBuilder)
10+
{
11+
migrationBuilder.CreateSequence(
12+
name: "catalog_brand_hilo",
13+
incrementBy: 10);
14+
15+
migrationBuilder.CreateSequence(
16+
name: "catalog_hilo",
17+
incrementBy: 10);
18+
19+
migrationBuilder.CreateSequence(
20+
name: "catalog_type_hilo",
21+
incrementBy: 10);
22+
23+
migrationBuilder.CreateTable(
24+
name: "CatalogBrand",
25+
columns: table => new
26+
{
27+
Id = table.Column<int>(nullable: false),
28+
Brand = table.Column<string>(maxLength: 100, nullable: false)
29+
},
30+
constraints: table =>
31+
{
32+
table.PrimaryKey("PK_CatalogBrand", x => x.Id);
33+
});
34+
35+
migrationBuilder.CreateTable(
36+
name: "CatalogType",
37+
columns: table => new
38+
{
39+
Id = table.Column<int>(nullable: false),
40+
Type = table.Column<string>(maxLength: 100, nullable: false)
41+
},
42+
constraints: table =>
43+
{
44+
table.PrimaryKey("PK_CatalogType", x => x.Id);
45+
});
46+
47+
migrationBuilder.CreateTable(
48+
name: "Catalog",
49+
columns: table => new
50+
{
51+
Id = table.Column<int>(nullable: false),
52+
CatalogBrandId = table.Column<int>(nullable: false),
53+
CatalogTypeId = table.Column<int>(nullable: false),
54+
Description = table.Column<string>(nullable: true),
55+
Name = table.Column<string>(maxLength: 50, nullable: false),
56+
PictureUri = table.Column<string>(nullable: true),
57+
Price = table.Column<decimal>(nullable: false)
58+
},
59+
constraints: table =>
60+
{
61+
table.PrimaryKey("PK_Catalog", x => x.Id);
62+
table.ForeignKey(
63+
name: "FK_Catalog_CatalogBrand_CatalogBrandId",
64+
column: x => x.CatalogBrandId,
65+
principalTable: "CatalogBrand",
66+
principalColumn: "Id",
67+
onDelete: ReferentialAction.Cascade);
68+
table.ForeignKey(
69+
name: "FK_Catalog_CatalogType_CatalogTypeId",
70+
column: x => x.CatalogTypeId,
71+
principalTable: "CatalogType",
72+
principalColumn: "Id",
73+
onDelete: ReferentialAction.Cascade);
74+
});
75+
76+
migrationBuilder.CreateIndex(
77+
name: "IX_Catalog_CatalogBrandId",
78+
table: "Catalog",
79+
column: "CatalogBrandId");
80+
81+
migrationBuilder.CreateIndex(
82+
name: "IX_Catalog_CatalogTypeId",
83+
table: "Catalog",
84+
column: "CatalogTypeId");
85+
}
86+
87+
protected override void Down(MigrationBuilder migrationBuilder)
88+
{
89+
migrationBuilder.DropTable(
90+
name: "Catalog");
91+
92+
migrationBuilder.DropTable(
93+
name: "CatalogBrand");
94+
95+
migrationBuilder.DropTable(
96+
name: "CatalogType");
97+
98+
migrationBuilder.DropSequence(
99+
name: "catalog_brand_hilo");
100+
101+
migrationBuilder.DropSequence(
102+
name: "catalog_hilo");
103+
104+
migrationBuilder.DropSequence(
105+
name: "catalog_type_hilo");
106+
}
107+
}
108+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using System;
2+
using Microsoft.EntityFrameworkCore;
3+
using Microsoft.EntityFrameworkCore.Infrastructure;
4+
using Microsoft.EntityFrameworkCore.Metadata;
5+
using Microsoft.EntityFrameworkCore.Migrations;
6+
using eShopWeb.Infrastructure;
7+
8+
namespace eShopWeb.Infrastructure.Migrations
9+
{
10+
[DbContext(typeof(CatalogContext))]
11+
partial class CatalogContextModelSnapshot : ModelSnapshot
12+
{
13+
protected override void BuildModel(ModelBuilder modelBuilder)
14+
{
15+
modelBuilder
16+
.HasAnnotation("ProductVersion", "1.1.0-rtm-22752")
17+
.HasAnnotation("SqlServer:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'")
18+
.HasAnnotation("SqlServer:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'")
19+
.HasAnnotation("SqlServer:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'")
20+
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
21+
22+
modelBuilder.Entity("eShopWeb.Models.CatalogBrand", b =>
23+
{
24+
b.Property<int>("Id")
25+
.ValueGeneratedOnAdd()
26+
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo")
27+
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
28+
29+
b.Property<string>("Brand")
30+
.IsRequired()
31+
.HasMaxLength(100);
32+
33+
b.HasKey("Id");
34+
35+
b.ToTable("CatalogBrand");
36+
});
37+
38+
modelBuilder.Entity("eShopWeb.Models.CatalogItem", b =>
39+
{
40+
b.Property<int>("Id")
41+
.ValueGeneratedOnAdd()
42+
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo")
43+
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
44+
45+
b.Property<int>("CatalogBrandId");
46+
47+
b.Property<int>("CatalogTypeId");
48+
49+
b.Property<string>("Description");
50+
51+
b.Property<string>("Name")
52+
.IsRequired()
53+
.HasMaxLength(50);
54+
55+
b.Property<string>("PictureUri");
56+
57+
b.Property<decimal>("Price");
58+
59+
b.HasKey("Id");
60+
61+
b.HasIndex("CatalogBrandId");
62+
63+
b.HasIndex("CatalogTypeId");
64+
65+
b.ToTable("Catalog");
66+
});
67+
68+
modelBuilder.Entity("eShopWeb.Models.CatalogType", b =>
69+
{
70+
b.Property<int>("Id")
71+
.ValueGeneratedOnAdd()
72+
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo")
73+
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
74+
75+
b.Property<string>("Type")
76+
.IsRequired()
77+
.HasMaxLength(100);
78+
79+
b.HasKey("Id");
80+
81+
b.ToTable("CatalogType");
82+
});
83+
84+
modelBuilder.Entity("eShopWeb.Models.CatalogItem", b =>
85+
{
86+
b.HasOne("eShopWeb.Models.CatalogBrand", "CatalogBrand")
87+
.WithMany()
88+
.HasForeignKey("CatalogBrandId")
89+
.OnDelete(DeleteBehavior.Cascade);
90+
91+
b.HasOne("eShopWeb.Models.CatalogType", "CatalogType")
92+
.WithMany()
93+
.HasForeignKey("CatalogTypeId")
94+
.OnDelete(DeleteBehavior.Cascade);
95+
});
96+
}
97+
}
98+
}

src/Web/WebMonolithic/eShopWeb/eShopWeb.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
</ItemGroup>
2626
<ItemGroup>
2727
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0-msbuild3-final" />
28+
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0-msbuild3-final" />
2829
</ItemGroup>
2930
<ItemGroup>
3031
<Folder Include="Models\" />
3132
<Folder Include="Pics\" />
32-
<Folder Include="Infrastructure\" />
3333
<Folder Include="Views\Catalog\" />
3434
<Folder Include="wwwroot\css\catalog\" />
3535
<Folder Include="wwwroot\fonts\" />

0 commit comments

Comments
 (0)