add: миграция сущности записи изменения баланса

This commit is contained in:
mfnefd 2024-11-27 00:06:15 +04:00
parent 3684f1479c
commit af936e519c
3 changed files with 239 additions and 0 deletions

View File

@ -0,0 +1,134 @@
// <auto-generated />
using System;
using Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Infrastructure.Migrations
{
[DbContext(typeof(DatabaseContext))]
[Migration("20241126185002_AddChangeRecord")]
partial class AddChangeRecord
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Infrastructure.Models.ChangeRecord", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("ChangedAt")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("SpendingGroupId")
.HasColumnType("uuid");
b.Property<decimal>("Sum")
.HasColumnType("numeric");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SpendingGroupId");
b.HasIndex("UserId");
b.ToTable("ChangeRecords");
});
modelBuilder.Entity("Infrastructure.Models.SpendingGroup", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("SpendingGroups");
});
modelBuilder.Entity("Infrastructure.Models.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<decimal>("Balance")
.HasColumnType("numeric");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("Infrastructure.Models.ChangeRecord", b =>
{
b.HasOne("Infrastructure.Models.SpendingGroup", "SpendingGroup")
.WithMany()
.HasForeignKey("SpendingGroupId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Infrastructure.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("SpendingGroup");
b.Navigation("User");
});
modelBuilder.Entity("Infrastructure.Models.SpendingGroup", b =>
{
b.HasOne("Infrastructure.Models.User", "User")
.WithMany("SpendingGroups")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("Infrastructure.Models.User", b =>
{
b.Navigation("SpendingGroups");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,59 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Infrastructure.Migrations
{
/// <inheritdoc />
public partial class AddChangeRecord : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ChangeRecords",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Sum = table.Column<decimal>(type: "numeric", nullable: false),
ChangedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
UserId = table.Column<Guid>(type: "uuid", nullable: false),
SpendingGroupId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ChangeRecords", x => x.Id);
table.ForeignKey(
name: "FK_ChangeRecords_SpendingGroups_SpendingGroupId",
column: x => x.SpendingGroupId,
principalTable: "SpendingGroups",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ChangeRecords_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_ChangeRecords_SpendingGroupId",
table: "ChangeRecords",
column: "SpendingGroupId");
migrationBuilder.CreateIndex(
name: "IX_ChangeRecords_UserId",
table: "ChangeRecords",
column: "UserId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ChangeRecords");
}
}
}

View File

@ -22,6 +22,33 @@ namespace Infrastructure.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Infrastructure.Models.ChangeRecord", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("ChangedAt")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("SpendingGroupId")
.HasColumnType("uuid");
b.Property<decimal>("Sum")
.HasColumnType("numeric");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SpendingGroupId");
b.HasIndex("UserId");
b.ToTable("ChangeRecords");
});
modelBuilder.Entity("Infrastructure.Models.SpendingGroup", b =>
{
b.Property<Guid>("Id")
@ -64,6 +91,25 @@ namespace Infrastructure.Migrations
b.ToTable("Users");
});
modelBuilder.Entity("Infrastructure.Models.ChangeRecord", b =>
{
b.HasOne("Infrastructure.Models.SpendingGroup", "SpendingGroup")
.WithMany()
.HasForeignKey("SpendingGroupId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Infrastructure.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("SpendingGroup");
b.Navigation("User");
});
modelBuilder.Entity("Infrastructure.Models.SpendingGroup", b =>
{
b.HasOne("Infrastructure.Models.User", "User")