using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace PowderCoating.Infrastructure.Migrations { /// public partial class AddLegalCompliance : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "MarketingEmailOptOut", table: "Companies", type: "bit", nullable: false, defaultValue: false); // Add as nullable first so we can backfill unique GUIDs per row migrationBuilder.AddColumn( name: "MarketingUnsubscribeToken", table: "Companies", type: "nvarchar(max)", nullable: true); // Backfill: assign a unique token to every existing company row migrationBuilder.Sql(@" UPDATE Companies SET MarketingUnsubscribeToken = LOWER(REPLACE(NEWID(), '-', '')) WHERE MarketingUnsubscribeToken IS NULL "); // Now enforce non-nullable migrationBuilder.AlterColumn( name: "MarketingUnsubscribeToken", table: "Companies", type: "nvarchar(max)", nullable: false, defaultValue: ""); migrationBuilder.CreateTable( name: "TermsAcceptances", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), UserId = table.Column(type: "nvarchar(max)", nullable: false), CompanyId = table.Column(type: "int", nullable: false), TosVersion = table.Column(type: "nvarchar(max)", nullable: false), AcceptedAt = table.Column(type: "datetime2", nullable: false), IpAddress = table.Column(type: "nvarchar(max)", nullable: true), UserAgent = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_TermsAcceptances", x => x.Id); }); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 1, column: "CreatedAt", value: new DateTime(2026, 4, 10, 2, 19, 30, 410, DateTimeKind.Utc).AddTicks(5127)); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 2, column: "CreatedAt", value: new DateTime(2026, 4, 10, 2, 19, 30, 410, DateTimeKind.Utc).AddTicks(5133)); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 3, column: "CreatedAt", value: new DateTime(2026, 4, 10, 2, 19, 30, 410, DateTimeKind.Utc).AddTicks(5135)); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "TermsAcceptances"); migrationBuilder.DropColumn( name: "MarketingEmailOptOut", table: "Companies"); migrationBuilder.DropColumn( name: "MarketingUnsubscribeToken", table: "Companies"); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 1, column: "CreatedAt", value: new DateTime(2026, 4, 9, 1, 38, 18, 363, DateTimeKind.Utc).AddTicks(787)); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 2, column: "CreatedAt", value: new DateTime(2026, 4, 9, 1, 38, 18, 363, DateTimeKind.Utc).AddTicks(794)); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 3, column: "CreatedAt", value: new DateTime(2026, 4, 9, 1, 38, 18, 363, DateTimeKind.Utc).AddTicks(795)); } } }