using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ClassNotify.Server.Data.Migrations
{
///
public partial class AddNotificationExpiresAtAndPendingIndex : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn(
name: "ExpiresAt",
table: "Notifications",
type: "timestamp with time zone",
nullable: true);
migrationBuilder.AddColumn(
name: "Voice",
table: "Notifications",
type: "boolean",
nullable: false,
defaultValue: true);
migrationBuilder.AddColumn(
name: "Shake",
table: "Notifications",
type: "boolean",
nullable: false,
defaultValue: true);
migrationBuilder.AddColumn(
name: "DurationSeconds",
table: "Notifications",
type: "integer",
nullable: false,
defaultValue: 15);
migrationBuilder.CreateIndex(
name: "IX_Notifications_TenantId_ClassroomId_ExpiresAt",
table: "Notifications",
columns: new[] { "TenantId", "ClassroomId", "ExpiresAt" });
migrationBuilder.CreateIndex(
name: "IX_NotificationReceipts_DeviceId_Status",
table: "NotificationReceipts",
columns: new[] { "DeviceId", "Status" });
// P1 Batch 9: Backfill legacy notifications where ExpiresAt IS NULL to CreatedAt (marking them expired)
migrationBuilder.Sql("UPDATE \"Notifications\" SET \"ExpiresAt\" = \"CreatedAt\" WHERE \"ExpiresAt\" IS NULL;");
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_NotificationReceipts_DeviceId_Status",
table: "NotificationReceipts");
migrationBuilder.DropIndex(
name: "IX_Notifications_TenantId_ClassroomId_ExpiresAt",
table: "Notifications");
migrationBuilder.DropColumn(
name: "DurationSeconds",
table: "Notifications");
migrationBuilder.DropColumn(
name: "Shake",
table: "Notifications");
migrationBuilder.DropColumn(
name: "Voice",
table: "Notifications");
migrationBuilder.DropColumn(
name: "ExpiresAt",
table: "Notifications");
}
}
}