From 4b2780850c7c139e1e321f718d1e0baeea1c6540 Mon Sep 17 00:00:00 2001 From: Stanislav Vysotskyi <66203238+ArdenHide@users.noreply.github.com> Date: Mon, 30 Dec 2024 16:38:59 +0300 Subject: [PATCH] `bool` flags instead of `enum OperationType` in `LogDTO` (#52) --- .../DispenserContext.cs | 5 - .../Models/LogDTO.cs | 9 +- .../Models/Types/OperationType.cs | 7 - ...peration-To-IsCreation-In-Logs.Designer.cs | 275 ++++++++++++++++++ ..._Update-Operation-To-IsCreation-In-Logs.cs | 40 +++ .../DispenserContextModelSnapshot.cs | 5 +- 6 files changed, 322 insertions(+), 19 deletions(-) delete mode 100644 src/DispenserProvider.DataBase/Models/Types/OperationType.cs create mode 100644 src/DispenserProvider.Migrations/Migrations/20241230133714_Update-Operation-To-IsCreation-In-Logs.Designer.cs create mode 100644 src/DispenserProvider.Migrations/Migrations/20241230133714_Update-Operation-To-IsCreation-In-Logs.cs diff --git a/src/DispenserProvider.DataBase/DispenserContext.cs b/src/DispenserProvider.DataBase/DispenserContext.cs index eb4675c..5189058 100644 --- a/src/DispenserProvider.DataBase/DispenserContext.cs +++ b/src/DispenserProvider.DataBase/DispenserContext.cs @@ -3,8 +3,6 @@ using DispenserProvider.DataBase.Models; using ConfiguredSqlConnection.Extensions; using Net.Web3.EthereumWallet.Extensions; -using DispenserProvider.DataBase.Models.Types; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace DispenserProvider.DataBase; @@ -102,9 +100,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) { entity.HasKey(e => e.Signature); - entity.Property(e => e.Operation) - .HasConversion(new EnumToStringConverter()); - entity.HasMany(e => e.CreationDispensers) .WithOne(e => e.CreationLog) .HasForeignKey(e => e.CreationLogSignature) diff --git a/src/DispenserProvider.DataBase/Models/LogDTO.cs b/src/DispenserProvider.DataBase/Models/LogDTO.cs index c41c463..2945e33 100644 --- a/src/DispenserProvider.DataBase/Models/LogDTO.cs +++ b/src/DispenserProvider.DataBase/Models/LogDTO.cs @@ -1,5 +1,4 @@ -using DispenserProvider.DataBase.Models.Types; -using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations.Schema; namespace DispenserProvider.DataBase.Models; @@ -11,8 +10,10 @@ public class LogDTO [Column(TypeName = "datetime2(0)")] public DateTime CreationTime { get; set; } - [Column(TypeName = "nvarchar(32)")] - public OperationType Operation { get; set; } + public bool IsCreation { get; set; } + + [NotMapped] + public bool IsDeletion => !IsCreation; public virtual List CreationDispensers { get; set; } = []; public virtual List DeletionDispensers { get; set; } = []; diff --git a/src/DispenserProvider.DataBase/Models/Types/OperationType.cs b/src/DispenserProvider.DataBase/Models/Types/OperationType.cs deleted file mode 100644 index 2078c98..0000000 --- a/src/DispenserProvider.DataBase/Models/Types/OperationType.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace DispenserProvider.DataBase.Models.Types; - -public enum OperationType -{ - Creation, - Deletion -} \ No newline at end of file diff --git a/src/DispenserProvider.Migrations/Migrations/20241230133714_Update-Operation-To-IsCreation-In-Logs.Designer.cs b/src/DispenserProvider.Migrations/Migrations/20241230133714_Update-Operation-To-IsCreation-In-Logs.Designer.cs new file mode 100644 index 0000000..d37b7e6 --- /dev/null +++ b/src/DispenserProvider.Migrations/Migrations/20241230133714_Update-Operation-To-IsCreation-In-Logs.Designer.cs @@ -0,0 +1,275 @@ +// +using System; +using DispenserProvider.DataBase; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DispenserProvider.DataBase.Migrations +{ + [DbContext(typeof(DispenserContext))] + [Migration("20241230133714_Update-Operation-To-IsCreation-In-Logs")] + partial class UpdateOperationToIsCreationInLogs + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.BuilderDTO", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FinishTime") + .HasColumnType("datetime2(0)"); + + b.Property("ProviderAddress") + .IsRequired() + .HasColumnType("nvarchar(42)"); + + b.Property("StartTime") + .HasColumnType("datetime2(0)"); + + b.Property("TransactionDetailId") + .HasColumnType("bigint"); + + b.Property("WeiAmount") + .IsRequired() + .HasColumnType("nvarchar(78)"); + + b.HasKey("Id"); + + b.HasIndex("TransactionDetailId"); + + b.ToTable("Builders"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.DispenserDTO", b => + { + b.Property("Id") + .HasColumnType("nvarchar(64)"); + + b.Property("CreationLogSignature") + .IsRequired() + .HasColumnType("nvarchar(132)"); + + b.Property("DeletionLogSignature") + .HasColumnType("nvarchar(132)"); + + b.Property("RefundDetailId") + .HasColumnType("bigint"); + + b.Property("RefundFinishTime") + .HasColumnType("datetime2(0)"); + + b.Property("UserAddress") + .IsRequired() + .HasColumnType("nvarchar(42)"); + + b.Property("WithdrawalDetailId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("CreationLogSignature"); + + b.HasIndex("DeletionLogSignature"); + + b.HasIndex("RefundDetailId") + .IsUnique() + .HasFilter("[RefundDetailId] IS NOT NULL"); + + b.HasIndex("WithdrawalDetailId") + .IsUnique(); + + b.ToTable("Dispenser"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.LogDTO", b => + { + b.Property("Signature") + .HasColumnType("nvarchar(132)"); + + b.Property("CreationTime") + .HasColumnType("datetime2(0)"); + + b.Property("IsCreation") + .HasColumnType("bit"); + + b.HasKey("Signature"); + + b.ToTable("Logs"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.SignatureDTO", b => + { + b.Property("Signature") + .HasColumnType("nvarchar(132)"); + + b.Property("DispenserId") + .IsRequired() + .HasColumnType("nvarchar(64)"); + + b.Property("IsRefund") + .HasColumnType("bit"); + + b.Property("ValidFrom") + .HasColumnType("datetime2(0)"); + + b.Property("ValidUntil") + .HasColumnType("datetime2(0)"); + + b.HasKey("Signature"); + + b.HasIndex("DispenserId"); + + b.ToTable("Signatures"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.TakenTrackDTO", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DispenserId") + .IsRequired() + .HasColumnType("nvarchar(64)"); + + b.Property("IsRefunded") + .HasColumnType("bit"); + + b.HasKey("Id"); + + b.HasIndex("DispenserId") + .IsUnique(); + + b.ToTable("TakenTrack"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.TransactionDetailDTO", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ChainId") + .HasColumnType("bigint"); + + b.Property("PoolId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.ToTable("TransactionDetails"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.BuilderDTO", b => + { + b.HasOne("DispenserProvider.DataBase.Models.TransactionDetailDTO", "TransactionDetail") + .WithMany("Builders") + .HasForeignKey("TransactionDetailId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("TransactionDetail"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.DispenserDTO", b => + { + b.HasOne("DispenserProvider.DataBase.Models.LogDTO", "CreationLog") + .WithMany("CreationDispensers") + .HasForeignKey("CreationLogSignature") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DispenserProvider.DataBase.Models.LogDTO", "DeletionLog") + .WithMany("DeletionDispensers") + .HasForeignKey("DeletionLogSignature") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("DispenserProvider.DataBase.Models.TransactionDetailDTO", "RefundDetail") + .WithOne("RefundDispenser") + .HasForeignKey("DispenserProvider.DataBase.Models.DispenserDTO", "RefundDetailId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("DispenserProvider.DataBase.Models.TransactionDetailDTO", "WithdrawalDetail") + .WithOne("WithdrawalDispenser") + .HasForeignKey("DispenserProvider.DataBase.Models.DispenserDTO", "WithdrawalDetailId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("CreationLog"); + + b.Navigation("DeletionLog"); + + b.Navigation("RefundDetail"); + + b.Navigation("WithdrawalDetail"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.SignatureDTO", b => + { + b.HasOne("DispenserProvider.DataBase.Models.DispenserDTO", "Dispenser") + .WithMany("UserSignatures") + .HasForeignKey("DispenserId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Dispenser"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.TakenTrackDTO", b => + { + b.HasOne("DispenserProvider.DataBase.Models.DispenserDTO", "Dispenser") + .WithOne("TakenTrack") + .HasForeignKey("DispenserProvider.DataBase.Models.TakenTrackDTO", "DispenserId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Dispenser"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.DispenserDTO", b => + { + b.Navigation("TakenTrack"); + + b.Navigation("UserSignatures"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.LogDTO", b => + { + b.Navigation("CreationDispensers"); + + b.Navigation("DeletionDispensers"); + }); + + modelBuilder.Entity("DispenserProvider.DataBase.Models.TransactionDetailDTO", b => + { + b.Navigation("Builders"); + + b.Navigation("RefundDispenser"); + + b.Navigation("WithdrawalDispenser"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/DispenserProvider.Migrations/Migrations/20241230133714_Update-Operation-To-IsCreation-In-Logs.cs b/src/DispenserProvider.Migrations/Migrations/20241230133714_Update-Operation-To-IsCreation-In-Logs.cs new file mode 100644 index 0000000..a40e879 --- /dev/null +++ b/src/DispenserProvider.Migrations/Migrations/20241230133714_Update-Operation-To-IsCreation-In-Logs.cs @@ -0,0 +1,40 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DispenserProvider.DataBase.Migrations +{ + /// + public partial class UpdateOperationToIsCreationInLogs : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Operation", + table: "Logs"); + + migrationBuilder.AddColumn( + name: "IsCreation", + table: "Logs", + type: "bit", + nullable: false, + defaultValue: false); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "IsCreation", + table: "Logs"); + + migrationBuilder.AddColumn( + name: "Operation", + table: "Logs", + type: "nvarchar(32)", + nullable: false, + defaultValue: ""); + } + } +} diff --git a/src/DispenserProvider.Migrations/Migrations/DispenserContextModelSnapshot.cs b/src/DispenserProvider.Migrations/Migrations/DispenserContextModelSnapshot.cs index af68492..58f76c8 100644 --- a/src/DispenserProvider.Migrations/Migrations/DispenserContextModelSnapshot.cs +++ b/src/DispenserProvider.Migrations/Migrations/DispenserContextModelSnapshot.cs @@ -103,9 +103,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("CreationTime") .HasColumnType("datetime2(0)"); - b.Property("Operation") - .IsRequired() - .HasColumnType("nvarchar(32)"); + b.Property("IsCreation") + .HasColumnType("bit"); b.HasKey("Signature");