Skip to content

Commit

Permalink
feat(Migrations): cria migração inicial do banco de dados
Browse files Browse the repository at this point in the history
  • Loading branch information
renebentes committed Jun 25, 2024
1 parent 950fecf commit ba69490
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions src/BlazingShop/Data/Migrations/20240625194144_CreateDatabase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace BlazingShop.Data.Migrations
{
/// <inheritdoc />
public partial class CreateDatabase : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Category",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Title = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Category", x => x.Id);
});

migrationBuilder.CreateTable(
name: "Product",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
CategoryId = table.Column<int>(type: "INTEGER", nullable: false),
Description = table.Column<string>(type: "TEXT", nullable: false),
Image = table.Column<string>(type: "TEXT", nullable: false),
Price = table.Column<decimal>(type: "TEXT", nullable: false),
Title = table.Column<string>(type: "TEXT", maxLength: 150, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Product", x => x.Id);
table.ForeignKey(
name: "FK_Product_Category_CategoryId",
column: x => x.CategoryId,
principalTable: "Category",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.CreateIndex(
name: "IX_Product_CategoryId",
table: "Product",
column: "CategoryId");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Product");

migrationBuilder.DropTable(
name: "Category");
}
}
}
85 changes: 85 additions & 0 deletions src/BlazingShop/Data/Migrations/AppDbContextModelSnapshot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// <auto-generated />
using BlazingShop.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

#nullable disable

namespace BlazingShop.Data.Migrations
{
[DbContext(typeof(AppDbContext))]
partial class AppDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");

modelBuilder.Entity("BlazingShop.Models.Category", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Category", (string)null);
});

modelBuilder.Entity("BlazingShop.Models.Product", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CategoryId")
.HasColumnType("INTEGER");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Image")
.IsRequired()
.HasColumnType("TEXT");
b.Property<decimal>("Price")
.HasColumnType("TEXT");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(150)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("CategoryId");
b.ToTable("Product", (string)null);
});

modelBuilder.Entity("BlazingShop.Models.Product", b =>
{
b.HasOne("BlazingShop.Models.Category", "Category")
.WithMany("Products")
.HasForeignKey("CategoryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Category");
});

modelBuilder.Entity("BlazingShop.Models.Category", b =>
{
b.Navigation("Products");
});
#pragma warning restore 612, 618
}
}
}

0 comments on commit ba69490

Please sign in to comment.