using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace LiteCharms.Features.MidrandBooks.Postgres.Migrations { /// public sealed partial class AddedPaymentObjects : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Gateways", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true), Name = table.Column(type: "text", nullable: false), Website = table.Column(type: "text", nullable: true), MerchantId = table.Column(type: "text", nullable: false), MerchantKey = table.Column(type: "text", nullable: false), Passphrase = table.Column(type: "text", nullable: false), IsSandbox = table.Column(type: "boolean", nullable: false), Enabled = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Gateways", x => x.Id); }); migrationBuilder.CreateTable( name: "Inventories", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), Status = table.Column(type: "integer", nullable: false), ProductId = table.Column(type: "bigint", nullable: false), ProductPriceId = table.Column(type: "bigint", nullable: false), TotalAllocated = table.Column(type: "integer", nullable: false), TotalReserved = table.Column(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(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true), Amount = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false), OrderId = table.Column(type: "bigint", nullable: false), Reference = table.Column(type: "text", nullable: false), Status = table.Column(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(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), Status = table.Column(type: "integer", nullable: false), OrderId = table.Column(type: "bigint", nullable: false), PaymentId = table.Column(type: "bigint", nullable: false), CustomerId = table.Column(type: "bigint", nullable: false), PaymentGatewayReference = table.Column(type: "text", nullable: true), PaymentGatewayId = table.Column(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"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Inventories"); migrationBuilder.DropTable( name: "Ledger"); migrationBuilder.DropTable( name: "Gateways"); migrationBuilder.DropTable( name: "Payments"); } } }