120 lines
4.5 KiB
C#
120 lines
4.5 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace PowderCoating.Infrastructure.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class AddLegalCompliance : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.AddColumn<bool>(
|
|
name: "MarketingEmailOptOut",
|
|
table: "Companies",
|
|
type: "bit",
|
|
nullable: false,
|
|
defaultValue: false);
|
|
|
|
// Add as nullable first so we can backfill unique GUIDs per row
|
|
migrationBuilder.AddColumn<string>(
|
|
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<string>(
|
|
name: "MarketingUnsubscribeToken",
|
|
table: "Companies",
|
|
type: "nvarchar(max)",
|
|
nullable: false,
|
|
defaultValue: "");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "TermsAcceptances",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
UserId = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
CompanyId = table.Column<int>(type: "int", nullable: false),
|
|
TosVersion = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
AcceptedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
|
|
IpAddress = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
|
UserAgent = table.Column<string>(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));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
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));
|
|
}
|
|
}
|
|
}
|