Skip to content

Commit

Permalink
Many signatures for one dispenser (#47)
Browse files Browse the repository at this point in the history
* Many signatures for one dispenser

* - add migration
  • Loading branch information
ArdenHide authored Dec 24, 2024
1 parent 0a5b22f commit 06c5db1
Show file tree
Hide file tree
Showing 6 changed files with 352 additions and 30 deletions.
5 changes: 2 additions & 3 deletions src/DispenserProvider.DataBase/DispenserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
x => new EthereumAddress(x)
);

entity.HasOne(e => e.UserSignature)
entity.HasMany(e => e.UserSignatures)
.WithOne(e => e.Dispenser)
.HasForeignKey<DispenserDTO>(e => e.Signature)
.IsRequired(false)
.HasForeignKey(e => e.DispenserId)
.OnDelete(DeleteBehavior.Restrict);

entity.HasOne(e => e.WithdrawalDetail)
Expand Down
4 changes: 1 addition & 3 deletions src/DispenserProvider.DataBase/Models/DispenserDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public class DispenserDTO
[Column(TypeName = "datetime2(0)")]
public DateTime? RefundFinishTime { get; set; }

[Column(TypeName = "nvarchar(132)")]
public string? Signature { get; set; }
public virtual SignatureDTO? UserSignature { get; set; } = null!;
public virtual List<SignatureDTO> UserSignatures { get; set; } = [];

public long WithdrawalDetailId { get; set; }
public virtual TransactionDetailDTO WithdrawalDetail { get; set; } = null!;
Expand Down
2 changes: 2 additions & 0 deletions src/DispenserProvider.DataBase/Models/SignatureDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public class SignatureDTO

public bool IsRefund { get; set; }

[Column(TypeName = "nvarchar(64)")]
public string DispenserId { get; set; } = null!;
public virtual DispenserDTO Dispenser { get; set; } = null!;
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace DispenserProvider.DataBase.Migrations
{
/// <inheritdoc />
public partial class ManySignaturesToOneDispenser : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Dispenser_Signatures_Signature",
table: "Dispenser");

migrationBuilder.DropIndex(
name: "IX_Dispenser_Signature",
table: "Dispenser");

migrationBuilder.DropColumn(
name: "Signature",
table: "Dispenser");

migrationBuilder.AddColumn<string>(
name: "DispenserId",
table: "Signatures",
type: "nvarchar(64)",
nullable: false,
defaultValue: "");

migrationBuilder.CreateIndex(
name: "IX_Signatures_DispenserId",
table: "Signatures",
column: "DispenserId");

migrationBuilder.AddForeignKey(
name: "FK_Signatures_Dispenser_DispenserId",
table: "Signatures",
column: "DispenserId",
principalTable: "Dispenser",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Signatures_Dispenser_DispenserId",
table: "Signatures");

migrationBuilder.DropIndex(
name: "IX_Signatures_DispenserId",
table: "Signatures");

migrationBuilder.DropColumn(
name: "DispenserId",
table: "Signatures");

migrationBuilder.AddColumn<string>(
name: "Signature",
table: "Dispenser",
type: "nvarchar(132)",
nullable: true);

migrationBuilder.CreateIndex(
name: "IX_Dispenser_Signature",
table: "Dispenser",
column: "Signature",
unique: true,
filter: "[Signature] IS NOT NULL");

migrationBuilder.AddForeignKey(
name: "FK_Dispenser_Signatures_Signature",
table: "Dispenser",
column: "Signature",
principalTable: "Signatures",
principalColumn: "Signature",
onDelete: ReferentialAction.Restrict);
}
}
}
Loading

0 comments on commit 06c5db1

Please sign in to comment.