Skip to content

Commit

Permalink
Feat: add first Migration
Browse files Browse the repository at this point in the history
  • Loading branch information
srCochayuyo committed Sep 21, 2024
1 parent 86c6472 commit 7be9420
Show file tree
Hide file tree
Showing 3 changed files with 311 additions and 0 deletions.
111 changes: 111 additions & 0 deletions src/Data/Migrations/20240921185341_firstMigration.Designer.cs

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

92 changes: 92 additions & 0 deletions src/Data/Migrations/20240921185341_firstMigration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace ayudantis1.src.Data.Migrations
{
/// <inheritdoc />
public partial class firstMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Products",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false),
Price = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Products", x => x.Id);
});

migrationBuilder.CreateTable(
name: "Roles",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Roles", x => x.Id);
});

migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Rut = table.Column<string>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: false),
Email = table.Column<string>(type: "TEXT", nullable: false),
RoleId = table.Column<int>(type: "INTEGER", nullable: false),
ProductId = table.Column<int>(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
table.ForeignKey(
name: "FK_Users_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Users_Roles_RoleId",
column: x => x.RoleId,
principalTable: "Roles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.CreateIndex(
name: "IX_Users_ProductId",
table: "Users",
column: "ProductId");

migrationBuilder.CreateIndex(
name: "IX_Users_RoleId",
table: "Users",
column: "RoleId");
}

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

migrationBuilder.DropTable(
name: "Products");

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

#nullable disable

namespace ayudantis1.src.Data.Migrations
{
[DbContext(typeof(ApplicationDBContext))]
partial class ApplicationDBContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.4");

modelBuilder.Entity("ayudantis1.src.models.Product", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Price")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.ToTable("Products");
});

modelBuilder.Entity("ayudantis1.src.models.Role", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Roles");
});

modelBuilder.Entity("ayudantis1.src.models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int?>("ProductId")
.HasColumnType("INTEGER");
b.Property<int>("RoleId")
.HasColumnType("INTEGER");
b.Property<string>("Rut")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("RoleId");
b.ToTable("Users");
});

modelBuilder.Entity("ayudantis1.src.models.User", b =>
{
b.HasOne("ayudantis1.src.models.Product", null)
.WithMany("Users")
.HasForeignKey("ProductId");
b.HasOne("ayudantis1.src.models.Role", "Role")
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Role");
});

modelBuilder.Entity("ayudantis1.src.models.Product", b =>
{
b.Navigation("Users");
});
#pragma warning restore 612, 618
}
}
}

0 comments on commit 7be9420

Please sign in to comment.