Skip to content

Commit ba69490

Browse files
committed
feat(Migrations): cria migração inicial do banco de dados
1 parent 950fecf commit ba69490

File tree

3 files changed

+238
-0
lines changed

3 files changed

+238
-0
lines changed

src/BlazingShop/Data/Migrations/20240625194144_CreateDatabase.Designer.cs

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using Microsoft.EntityFrameworkCore.Migrations;
2+
3+
#nullable disable
4+
5+
namespace BlazingShop.Data.Migrations
6+
{
7+
/// <inheritdoc />
8+
public partial class CreateDatabase : Migration
9+
{
10+
/// <inheritdoc />
11+
protected override void Up(MigrationBuilder migrationBuilder)
12+
{
13+
migrationBuilder.CreateTable(
14+
name: "Category",
15+
columns: table => new
16+
{
17+
Id = table.Column<int>(type: "INTEGER", nullable: false)
18+
.Annotation("Sqlite:Autoincrement", true),
19+
Title = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false)
20+
},
21+
constraints: table =>
22+
{
23+
table.PrimaryKey("PK_Category", x => x.Id);
24+
});
25+
26+
migrationBuilder.CreateTable(
27+
name: "Product",
28+
columns: table => new
29+
{
30+
Id = table.Column<int>(type: "INTEGER", nullable: false)
31+
.Annotation("Sqlite:Autoincrement", true),
32+
CategoryId = table.Column<int>(type: "INTEGER", nullable: false),
33+
Description = table.Column<string>(type: "TEXT", nullable: false),
34+
Image = table.Column<string>(type: "TEXT", nullable: false),
35+
Price = table.Column<decimal>(type: "TEXT", nullable: false),
36+
Title = table.Column<string>(type: "TEXT", maxLength: 150, nullable: false)
37+
},
38+
constraints: table =>
39+
{
40+
table.PrimaryKey("PK_Product", x => x.Id);
41+
table.ForeignKey(
42+
name: "FK_Product_Category_CategoryId",
43+
column: x => x.CategoryId,
44+
principalTable: "Category",
45+
principalColumn: "Id",
46+
onDelete: ReferentialAction.Cascade);
47+
});
48+
49+
migrationBuilder.CreateIndex(
50+
name: "IX_Product_CategoryId",
51+
table: "Product",
52+
column: "CategoryId");
53+
}
54+
55+
/// <inheritdoc />
56+
protected override void Down(MigrationBuilder migrationBuilder)
57+
{
58+
migrationBuilder.DropTable(
59+
name: "Product");
60+
61+
migrationBuilder.DropTable(
62+
name: "Category");
63+
}
64+
}
65+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// <auto-generated />
2+
using BlazingShop.Data;
3+
using Microsoft.EntityFrameworkCore;
4+
using Microsoft.EntityFrameworkCore.Infrastructure;
5+
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
6+
7+
#nullable disable
8+
9+
namespace BlazingShop.Data.Migrations
10+
{
11+
[DbContext(typeof(AppDbContext))]
12+
partial class AppDbContextModelSnapshot : ModelSnapshot
13+
{
14+
protected override void BuildModel(ModelBuilder modelBuilder)
15+
{
16+
#pragma warning disable 612, 618
17+
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
18+
19+
modelBuilder.Entity("BlazingShop.Models.Category", b =>
20+
{
21+
b.Property<int>("Id")
22+
.ValueGeneratedOnAdd()
23+
.HasColumnType("INTEGER");
24+
25+
b.Property<string>("Title")
26+
.IsRequired()
27+
.HasMaxLength(50)
28+
.HasColumnType("TEXT");
29+
30+
b.HasKey("Id");
31+
32+
b.ToTable("Category", (string)null);
33+
});
34+
35+
modelBuilder.Entity("BlazingShop.Models.Product", b =>
36+
{
37+
b.Property<int>("Id")
38+
.ValueGeneratedOnAdd()
39+
.HasColumnType("INTEGER");
40+
41+
b.Property<int>("CategoryId")
42+
.HasColumnType("INTEGER");
43+
44+
b.Property<string>("Description")
45+
.IsRequired()
46+
.HasColumnType("TEXT");
47+
48+
b.Property<string>("Image")
49+
.IsRequired()
50+
.HasColumnType("TEXT");
51+
52+
b.Property<decimal>("Price")
53+
.HasColumnType("TEXT");
54+
55+
b.Property<string>("Title")
56+
.IsRequired()
57+
.HasMaxLength(150)
58+
.HasColumnType("TEXT");
59+
60+
b.HasKey("Id");
61+
62+
b.HasIndex("CategoryId");
63+
64+
b.ToTable("Product", (string)null);
65+
});
66+
67+
modelBuilder.Entity("BlazingShop.Models.Product", b =>
68+
{
69+
b.HasOne("BlazingShop.Models.Category", "Category")
70+
.WithMany("Products")
71+
.HasForeignKey("CategoryId")
72+
.OnDelete(DeleteBehavior.Cascade)
73+
.IsRequired();
74+
75+
b.Navigation("Category");
76+
});
77+
78+
modelBuilder.Entity("BlazingShop.Models.Category", b =>
79+
{
80+
b.Navigation("Products");
81+
});
82+
#pragma warning restore 612, 618
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)