Files
components/LiteCharms.Features.MidrandBooks/Postgres/Migrations/20260531094401_AddedPaymentObjects.cs
T
2026-05-31 12:05:59 +02:00

186 lines
8.6 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace LiteCharms.Features.MidrandBooks.Postgres.Migrations
{
/// <inheritdoc />
public partial class AddedPaymentObjects : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Gateways",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
Name = table.Column<string>(type: "text", nullable: false),
Website = table.Column<string>(type: "text", nullable: true),
MerchantId = table.Column<string>(type: "text", nullable: false),
MerchantKey = table.Column<string>(type: "text", nullable: false),
Passphrase = table.Column<string>(type: "text", nullable: false),
IsSandbox = table.Column<bool>(type: "boolean", nullable: false),
Enabled = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Gateways", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Inventories",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
Status = table.Column<int>(type: "integer", nullable: false),
ProductId = table.Column<long>(type: "bigint", nullable: false),
ProductPriceId = table.Column<long>(type: "bigint", nullable: false),
TotalAllocated = table.Column<int>(type: "integer", nullable: false),
TotalReserved = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Inventories", x => x.Id);
table.ForeignKey(
name: "FK_Inventories_Prices_ProductPriceId",
column: x => x.ProductPriceId,
principalTable: "Prices",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Inventories_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Payments",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
Amount = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false),
OrderId = table.Column<long>(type: "bigint", nullable: false),
Reference = table.Column<string>(type: "text", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Payments", x => x.Id);
table.ForeignKey(
name: "FK_Payments_Orders_OrderId",
column: x => x.OrderId,
principalTable: "Orders",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Ledger",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
Status = table.Column<int>(type: "integer", nullable: false),
OrderId = table.Column<long>(type: "bigint", nullable: false),
PaymentId = table.Column<long>(type: "bigint", nullable: false),
CustomerId = table.Column<long>(type: "bigint", nullable: false),
PaymentGatewayReference = table.Column<string>(type: "text", nullable: true),
PaymentGatewayId = table.Column<long>(type: "bigint", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Ledger", x => x.Id);
table.ForeignKey(
name: "FK_Ledger_Customers_CustomerId",
column: x => x.CustomerId,
principalTable: "Customers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Ledger_Gateways_PaymentGatewayId",
column: x => x.PaymentGatewayId,
principalTable: "Gateways",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Ledger_Orders_OrderId",
column: x => x.OrderId,
principalTable: "Orders",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Ledger_Payments_PaymentId",
column: x => x.PaymentId,
principalTable: "Payments",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Inventories_ProductId",
table: "Inventories",
column: "ProductId");
migrationBuilder.CreateIndex(
name: "IX_Inventories_ProductPriceId",
table: "Inventories",
column: "ProductPriceId");
migrationBuilder.CreateIndex(
name: "IX_Ledger_CustomerId",
table: "Ledger",
column: "CustomerId");
migrationBuilder.CreateIndex(
name: "IX_Ledger_OrderId",
table: "Ledger",
column: "OrderId");
migrationBuilder.CreateIndex(
name: "IX_Ledger_PaymentGatewayId",
table: "Ledger",
column: "PaymentGatewayId");
migrationBuilder.CreateIndex(
name: "IX_Ledger_PaymentId",
table: "Ledger",
column: "PaymentId");
migrationBuilder.CreateIndex(
name: "IX_Payments_OrderId",
table: "Payments",
column: "OrderId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Inventories");
migrationBuilder.DropTable(
name: "Ledger");
migrationBuilder.DropTable(
name: "Gateways");
migrationBuilder.DropTable(
name: "Payments");
}
}
}