diff --git a/back/Infrastructure/Migrations/20241126185002_AddChangeRecord.Designer.cs b/back/Infrastructure/Migrations/20241126185002_AddChangeRecord.Designer.cs new file mode 100644 index 0000000..fc60907 --- /dev/null +++ b/back/Infrastructure/Migrations/20241126185002_AddChangeRecord.Designer.cs @@ -0,0 +1,134 @@ +// +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 + { + /// + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ChangedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("SpendingGroupId") + .HasColumnType("uuid"); + + b.Property("Sum") + .HasColumnType("numeric"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SpendingGroupId"); + + b.HasIndex("UserId"); + + b.ToTable("ChangeRecords"); + }); + + modelBuilder.Entity("Infrastructure.Models.SpendingGroup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("SpendingGroups"); + }); + + modelBuilder.Entity("Infrastructure.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Balance") + .HasColumnType("numeric"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("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 + } + } +} diff --git a/back/Infrastructure/Migrations/20241126185002_AddChangeRecord.cs b/back/Infrastructure/Migrations/20241126185002_AddChangeRecord.cs new file mode 100644 index 0000000..0f8a61d --- /dev/null +++ b/back/Infrastructure/Migrations/20241126185002_AddChangeRecord.cs @@ -0,0 +1,59 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Infrastructure.Migrations +{ + /// + public partial class AddChangeRecord : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "ChangeRecords", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Sum = table.Column(type: "numeric", nullable: false), + ChangedAt = table.Column(type: "timestamp with time zone", nullable: false), + UserId = table.Column(type: "uuid", nullable: false), + SpendingGroupId = table.Column(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"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ChangeRecords"); + } + } +} diff --git a/back/Infrastructure/Migrations/DatabaseContextModelSnapshot.cs b/back/Infrastructure/Migrations/DatabaseContextModelSnapshot.cs index 201a211..82c6874 100644 --- a/back/Infrastructure/Migrations/DatabaseContextModelSnapshot.cs +++ b/back/Infrastructure/Migrations/DatabaseContextModelSnapshot.cs @@ -22,6 +22,33 @@ namespace Infrastructure.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + modelBuilder.Entity("Infrastructure.Models.ChangeRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ChangedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("SpendingGroupId") + .HasColumnType("uuid"); + + b.Property("Sum") + .HasColumnType("numeric"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SpendingGroupId"); + + b.HasIndex("UserId"); + + b.ToTable("ChangeRecords"); + }); + modelBuilder.Entity("Infrastructure.Models.SpendingGroup", b => { b.Property("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")