backend phase 10

This commit is contained in:
hamid
2026-07-06 21:17:00 +03:30
parent 12c7e51c32
commit aae056b4e5
70 changed files with 8124 additions and 73 deletions
@@ -0,0 +1,265 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Baya.Infrastructure.Persistence.Migrations
{
/// <inheritdoc />
public partial class PaymentsCoreLedger : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "payments");
migrationBuilder.CreateTable(
name: "LedgerEntries",
schema: "payments",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
TransactionGroupId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
AccountType = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
NurseId = table.Column<long>(type: "bigint", nullable: true),
Direction = table.Column<string>(type: "nvarchar(6)", maxLength: 6, nullable: false),
AmountIrr = table.Column<long>(type: "bigint", nullable: false),
BookingId = table.Column<long>(type: "bigint", nullable: true),
SourceRefType = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
SourceRefId = table.Column<long>(type: "bigint", nullable: false),
Memo = table.Column<string>(type: "nvarchar(300)", maxLength: 300, nullable: true),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_LedgerEntries", x => x.Id);
table.ForeignKey(
name: "FK_LedgerEntries_Bookings_BookingId",
column: x => x.BookingId,
principalSchema: "booking",
principalTable: "Bookings",
principalColumn: "Id");
table.ForeignKey(
name: "FK_LedgerEntries_NurseProfiles_NurseId",
column: x => x.NurseId,
principalSchema: "usr",
principalTable: "NurseProfiles",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "PaymentGateways",
schema: "payments",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ProviderCode = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
Type = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
DisplayName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
ConfigJson = table.Column<string>(type: "nvarchar(max)", nullable: false),
IsActive = table.Column<bool>(type: "bit", nullable: false),
Priority = table.Column<int>(type: "int", nullable: false),
DeletedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
CreatedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
ModifiedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
CreatedById = table.Column<int>(type: "int", nullable: true),
ModifiedById = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PaymentGateways", x => x.Id);
});
migrationBuilder.CreateTable(
name: "PaymentWebhookEvents",
schema: "payments",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ProviderCode = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
ExternalEventId = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
EventType = table.Column<string>(type: "nvarchar(80)", maxLength: 80, nullable: false),
SignatureValid = table.Column<bool>(type: "bit", nullable: false),
PayloadJson = table.Column<string>(type: "nvarchar(max)", nullable: false),
ProcessingStatus = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
RelatedPaymentTransactionId = table.Column<long>(type: "bigint", nullable: true),
ReceivedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
ProcessedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
CreatedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
ModifiedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
CreatedById = table.Column<int>(type: "int", nullable: true),
ModifiedById = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PaymentWebhookEvents", x => x.Id);
});
migrationBuilder.CreateTable(
name: "PaymentTransactions",
schema: "payments",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
BookingRequestId = table.Column<long>(type: "bigint", nullable: false),
BookingId = table.Column<long>(type: "bigint", nullable: true),
CustomerId = table.Column<long>(type: "bigint", nullable: false),
GatewayId = table.Column<long>(type: "bigint", nullable: false),
Amount = table.Column<long>(type: "bigint", nullable: false),
Currency = table.Column<string>(type: "nvarchar(3)", maxLength: 3, nullable: false),
Status = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
GatewayTransactionId = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
GatewayReferenceCode = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
GatewayResponseCode = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
GatewayResponseJson = table.Column<string>(type: "nvarchar(max)", nullable: true),
IsInstallment = table.Column<bool>(type: "bit", nullable: false),
IpAddress = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
UserAgent = table.Column<string>(type: "nvarchar(400)", maxLength: 400, nullable: true),
DeletedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
CreatedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
ModifiedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
CreatedById = table.Column<int>(type: "int", nullable: true),
ModifiedById = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PaymentTransactions", x => x.Id);
table.ForeignKey(
name: "FK_PaymentTransactions_BookingRequests_BookingRequestId",
column: x => x.BookingRequestId,
principalSchema: "booking",
principalTable: "BookingRequests",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_PaymentTransactions_Bookings_BookingId",
column: x => x.BookingId,
principalSchema: "booking",
principalTable: "Bookings",
principalColumn: "Id");
table.ForeignKey(
name: "FK_PaymentTransactions_CustomerProfiles_CustomerId",
column: x => x.CustomerId,
principalSchema: "usr",
principalTable: "CustomerProfiles",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_PaymentTransactions_PaymentGateways_GatewayId",
column: x => x.GatewayId,
principalSchema: "payments",
principalTable: "PaymentGateways",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_LedgerEntries_AccountType_NurseId",
schema: "payments",
table: "LedgerEntries",
columns: new[] { "AccountType", "NurseId" });
migrationBuilder.CreateIndex(
name: "IX_LedgerEntries_BookingId",
schema: "payments",
table: "LedgerEntries",
column: "BookingId");
migrationBuilder.CreateIndex(
name: "IX_LedgerEntries_NurseId",
schema: "payments",
table: "LedgerEntries",
column: "NurseId");
migrationBuilder.CreateIndex(
name: "IX_LedgerEntries_SourceRefType_SourceRefId",
schema: "payments",
table: "LedgerEntries",
columns: new[] { "SourceRefType", "SourceRefId" });
migrationBuilder.CreateIndex(
name: "IX_LedgerEntries_TransactionGroupId",
schema: "payments",
table: "LedgerEntries",
column: "TransactionGroupId");
migrationBuilder.CreateIndex(
name: "IX_PaymentGateways_Type_IsActive_Priority",
schema: "payments",
table: "PaymentGateways",
columns: new[] { "Type", "IsActive", "Priority" });
migrationBuilder.CreateIndex(
name: "IX_PaymentTransactions_BookingId",
schema: "payments",
table: "PaymentTransactions",
column: "BookingId",
unique: true,
filter: "[Status] = 'succeeded' AND [BookingId] IS NOT NULL");
migrationBuilder.CreateIndex(
name: "IX_PaymentTransactions_BookingId_Status",
schema: "payments",
table: "PaymentTransactions",
columns: new[] { "BookingId", "Status" });
migrationBuilder.CreateIndex(
name: "IX_PaymentTransactions_BookingRequestId_Status",
schema: "payments",
table: "PaymentTransactions",
columns: new[] { "BookingRequestId", "Status" });
migrationBuilder.CreateIndex(
name: "IX_PaymentTransactions_CustomerId",
schema: "payments",
table: "PaymentTransactions",
column: "CustomerId");
migrationBuilder.CreateIndex(
name: "IX_PaymentTransactions_GatewayId",
schema: "payments",
table: "PaymentTransactions",
column: "GatewayId");
migrationBuilder.CreateIndex(
name: "IX_PaymentTransactions_GatewayReferenceCode",
schema: "payments",
table: "PaymentTransactions",
column: "GatewayReferenceCode",
unique: true,
filter: "[GatewayReferenceCode] IS NOT NULL");
migrationBuilder.CreateIndex(
name: "IX_PaymentWebhookEvents_ProviderCode_ExternalEventId",
schema: "payments",
table: "PaymentWebhookEvents",
columns: new[] { "ProviderCode", "ExternalEventId" },
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "LedgerEntries",
schema: "payments");
migrationBuilder.DropTable(
name: "PaymentTransactions",
schema: "payments");
migrationBuilder.DropTable(
name: "PaymentWebhookEvents",
schema: "payments");
migrationBuilder.DropTable(
name: "PaymentGateways",
schema: "payments");
}
}
}
@@ -2675,6 +2675,280 @@ namespace Baya.Infrastructure.Persistence.Migrations
b.ToTable("Notifications", "ops");
});
modelBuilder.Entity("Baya.Domain.Entities.Payments.LedgerEntry", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
b.Property<string>("AccountType")
.IsRequired()
.HasMaxLength(40)
.HasColumnType("nvarchar(40)");
b.Property<long>("AmountIrr")
.HasColumnType("bigint");
b.Property<long?>("BookingId")
.HasColumnType("bigint");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<string>("Direction")
.IsRequired()
.HasMaxLength(6)
.HasColumnType("nvarchar(6)");
b.Property<string>("Memo")
.HasMaxLength(300)
.HasColumnType("nvarchar(300)");
b.Property<long?>("NurseId")
.HasColumnType("bigint");
b.Property<long>("SourceRefId")
.HasColumnType("bigint");
b.Property<string>("SourceRefType")
.IsRequired()
.HasMaxLength(40)
.HasColumnType("nvarchar(40)");
b.Property<Guid>("TransactionGroupId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.HasIndex("BookingId");
b.HasIndex("NurseId");
b.HasIndex("TransactionGroupId");
b.HasIndex("AccountType", "NurseId");
b.HasIndex("SourceRefType", "SourceRefId");
b.ToTable("LedgerEntries", "payments");
});
modelBuilder.Entity("Baya.Domain.Entities.Payments.PaymentGateway", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
b.Property<string>("ConfigJson")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("datetimeoffset");
b.Property<int?>("CreatedById")
.HasColumnType("int");
b.Property<DateTimeOffset?>("DeletedAt")
.HasColumnType("datetimeoffset");
b.Property<string>("DisplayName")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");
b.Property<bool>("IsActive")
.HasColumnType("bit");
b.Property<DateTimeOffset?>("ModifiedAt")
.HasColumnType("datetimeoffset");
b.Property<int?>("ModifiedById")
.HasColumnType("int");
b.Property<int>("Priority")
.HasColumnType("int");
b.Property<string>("ProviderCode")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<string>("Type")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("nvarchar(20)");
b.HasKey("Id");
b.HasIndex("Type", "IsActive", "Priority");
b.ToTable("PaymentGateways", "payments");
});
modelBuilder.Entity("Baya.Domain.Entities.Payments.PaymentTransaction", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
b.Property<long>("Amount")
.HasColumnType("bigint");
b.Property<long?>("BookingId")
.HasColumnType("bigint");
b.Property<long>("BookingRequestId")
.HasColumnType("bigint");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("datetimeoffset");
b.Property<int?>("CreatedById")
.HasColumnType("int");
b.Property<string>("Currency")
.IsRequired()
.HasMaxLength(3)
.HasColumnType("nvarchar(3)");
b.Property<long>("CustomerId")
.HasColumnType("bigint");
b.Property<DateTimeOffset?>("DeletedAt")
.HasColumnType("datetimeoffset");
b.Property<long>("GatewayId")
.HasColumnType("bigint");
b.Property<string>("GatewayReferenceCode")
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<string>("GatewayResponseCode")
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<string>("GatewayResponseJson")
.HasColumnType("nvarchar(max)");
b.Property<string>("GatewayTransactionId")
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<string>("IpAddress")
.HasMaxLength(64)
.HasColumnType("nvarchar(64)");
b.Property<bool>("IsInstallment")
.HasColumnType("bit");
b.Property<DateTimeOffset?>("ModifiedAt")
.HasColumnType("datetimeoffset");
b.Property<int?>("ModifiedById")
.HasColumnType("int");
b.Property<string>("Status")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("nvarchar(20)");
b.Property<string>("UserAgent")
.HasMaxLength(400)
.HasColumnType("nvarchar(400)");
b.HasKey("Id");
b.HasIndex("BookingId")
.IsUnique()
.HasFilter("[Status] = 'succeeded' AND [BookingId] IS NOT NULL");
b.HasIndex("CustomerId");
b.HasIndex("GatewayId");
b.HasIndex("GatewayReferenceCode")
.IsUnique()
.HasFilter("[GatewayReferenceCode] IS NOT NULL");
b.HasIndex("BookingId", "Status");
b.HasIndex("BookingRequestId", "Status");
b.ToTable("PaymentTransactions", "payments");
});
modelBuilder.Entity("Baya.Domain.Entities.Payments.PaymentWebhookEvent", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("datetimeoffset");
b.Property<int?>("CreatedById")
.HasColumnType("int");
b.Property<string>("EventType")
.IsRequired()
.HasMaxLength(80)
.HasColumnType("nvarchar(80)");
b.Property<string>("ExternalEventId")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<DateTimeOffset?>("ModifiedAt")
.HasColumnType("datetimeoffset");
b.Property<int?>("ModifiedById")
.HasColumnType("int");
b.Property<string>("PayloadJson")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime?>("ProcessedAt")
.HasColumnType("datetime2");
b.Property<string>("ProcessingStatus")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("nvarchar(20)");
b.Property<string>("ProviderCode")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<DateTime>("ReceivedAt")
.HasColumnType("datetime2");
b.Property<long?>("RelatedPaymentTransactionId")
.HasColumnType("bigint");
b.Property<bool>("SignatureValid")
.HasColumnType("bit");
b.HasKey("Id");
b.HasIndex("ProviderCode", "ExternalEventId")
.IsUnique();
b.ToTable("PaymentWebhookEvents", "payments");
});
modelBuilder.Entity("Baya.Domain.Entities.Search.NurseSearchIndex", b =>
{
b.Property<long>("Id")
@@ -3921,6 +4195,42 @@ namespace Baya.Infrastructure.Persistence.Migrations
.IsRequired();
});
modelBuilder.Entity("Baya.Domain.Entities.Payments.LedgerEntry", b =>
{
b.HasOne("Baya.Domain.Entities.Booking.Booking", null)
.WithMany()
.HasForeignKey("BookingId");
b.HasOne("Baya.Domain.Entities.Identity.NurseProfile", null)
.WithMany()
.HasForeignKey("NurseId");
});
modelBuilder.Entity("Baya.Domain.Entities.Payments.PaymentTransaction", b =>
{
b.HasOne("Baya.Domain.Entities.Booking.Booking", null)
.WithMany()
.HasForeignKey("BookingId");
b.HasOne("Baya.Domain.Entities.Booking.BookingRequest", null)
.WithMany()
.HasForeignKey("BookingRequestId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("Baya.Domain.Entities.Identity.CustomerProfile", null)
.WithMany()
.HasForeignKey("CustomerId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("Baya.Domain.Entities.Payments.PaymentGateway", null)
.WithMany()
.HasForeignKey("GatewayId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
});
modelBuilder.Entity("Baya.Domain.Entities.Search.NurseSearchIndex", b =>
{
b.HasOne("Baya.Domain.Entities.Identity.NurseProfile", null)