Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many signatures for one dispenser #47

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading