using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace PowderCoating.Infrastructure.Migrations { /// public partial class AddGiftCertificates : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "GiftCertificateRedeemed", table: "Invoices", type: "decimal(18,2)", nullable: false, defaultValue: 0m); migrationBuilder.CreateTable( name: "GiftCertificates", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), CertificateCode = table.Column(type: "nvarchar(max)", nullable: false), OriginalAmount = table.Column(type: "decimal(18,2)", nullable: false), RedeemedAmount = table.Column(type: "decimal(18,2)", nullable: false), RecipientCustomerId = table.Column(type: "int", nullable: true), RecipientName = table.Column(type: "nvarchar(max)", nullable: true), RecipientEmail = table.Column(type: "nvarchar(max)", nullable: true), IssuedReason = table.Column(type: "int", nullable: false), PurchasePrice = table.Column(type: "decimal(18,2)", nullable: true), PurchasingCustomerId = table.Column(type: "int", nullable: true), Status = table.Column(type: "int", nullable: false), IssueDate = table.Column(type: "datetime2", nullable: false), ExpiryDate = table.Column(type: "datetime2", nullable: true), Notes = table.Column(type: "nvarchar(max)", nullable: true), IssuedById = table.Column(type: "nvarchar(450)", nullable: true), CompanyId = table.Column(type: "int", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false), UpdatedAt = table.Column(type: "datetime2", nullable: true), CreatedBy = table.Column(type: "nvarchar(max)", nullable: true), UpdatedBy = table.Column(type: "nvarchar(max)", nullable: true), IsDeleted = table.Column(type: "bit", nullable: false), DeletedAt = table.Column(type: "datetime2", nullable: true), DeletedBy = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_GiftCertificates", x => x.Id); table.ForeignKey( name: "FK_GiftCertificates_AspNetUsers_IssuedById", column: x => x.IssuedById, principalTable: "AspNetUsers", principalColumn: "Id"); table.ForeignKey( name: "FK_GiftCertificates_Customers_PurchasingCustomerId", column: x => x.PurchasingCustomerId, principalTable: "Customers", principalColumn: "Id"); table.ForeignKey( name: "FK_GiftCertificates_Customers_RecipientCustomerId", column: x => x.RecipientCustomerId, principalTable: "Customers", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "GiftCertificateRedemptions", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), GiftCertificateId = table.Column(type: "int", nullable: false), InvoiceId = table.Column(type: "int", nullable: false), AmountRedeemed = table.Column(type: "decimal(18,2)", nullable: false), RedeemedDate = table.Column(type: "datetime2", nullable: false), RedeemedById = table.Column(type: "nvarchar(450)", nullable: true), CompanyId = table.Column(type: "int", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false), UpdatedAt = table.Column(type: "datetime2", nullable: true), CreatedBy = table.Column(type: "nvarchar(max)", nullable: true), UpdatedBy = table.Column(type: "nvarchar(max)", nullable: true), IsDeleted = table.Column(type: "bit", nullable: false), DeletedAt = table.Column(type: "datetime2", nullable: true), DeletedBy = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_GiftCertificateRedemptions", x => x.Id); table.ForeignKey( name: "FK_GiftCertificateRedemptions_AspNetUsers_RedeemedById", column: x => x.RedeemedById, principalTable: "AspNetUsers", principalColumn: "Id"); table.ForeignKey( name: "FK_GiftCertificateRedemptions_GiftCertificates_GiftCertificateId", column: x => x.GiftCertificateId, principalTable: "GiftCertificates", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_GiftCertificateRedemptions_Invoices_InvoiceId", column: x => x.InvoiceId, principalTable: "Invoices", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 1, column: "CreatedAt", value: new DateTime(2026, 3, 19, 15, 45, 3, 145, DateTimeKind.Utc).AddTicks(4465)); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 2, column: "CreatedAt", value: new DateTime(2026, 3, 19, 15, 45, 3, 145, DateTimeKind.Utc).AddTicks(4472)); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 3, column: "CreatedAt", value: new DateTime(2026, 3, 19, 15, 45, 3, 145, DateTimeKind.Utc).AddTicks(4474)); migrationBuilder.CreateIndex( name: "IX_GiftCertificateRedemptions_GiftCertificateId", table: "GiftCertificateRedemptions", column: "GiftCertificateId"); migrationBuilder.CreateIndex( name: "IX_GiftCertificateRedemptions_InvoiceId", table: "GiftCertificateRedemptions", column: "InvoiceId"); migrationBuilder.CreateIndex( name: "IX_GiftCertificateRedemptions_RedeemedById", table: "GiftCertificateRedemptions", column: "RedeemedById"); migrationBuilder.CreateIndex( name: "IX_GiftCertificates_IssuedById", table: "GiftCertificates", column: "IssuedById"); migrationBuilder.CreateIndex( name: "IX_GiftCertificates_PurchasingCustomerId", table: "GiftCertificates", column: "PurchasingCustomerId"); migrationBuilder.CreateIndex( name: "IX_GiftCertificates_RecipientCustomerId", table: "GiftCertificates", column: "RecipientCustomerId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "GiftCertificateRedemptions"); migrationBuilder.DropTable( name: "GiftCertificates"); migrationBuilder.DropColumn( name: "GiftCertificateRedeemed", table: "Invoices"); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 1, column: "CreatedAt", value: new DateTime(2026, 3, 19, 2, 38, 23, 419, DateTimeKind.Utc).AddTicks(5291)); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 2, column: "CreatedAt", value: new DateTime(2026, 3, 19, 2, 38, 23, 419, DateTimeKind.Utc).AddTicks(5296)); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 3, column: "CreatedAt", value: new DateTime(2026, 3, 19, 2, 38, 23, 419, DateTimeKind.Utc).AddTicks(5298)); } } }