using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; namespace MessageService.Infrastructure.Migrations { [DbContext(typeof(MessageDbContext))] [Migration("20260913000100_ConversationActivityAndMessageSearch")] public partial class ConversationActivityAndMessageSearch : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "LastMessageTime", table: "conversations", type: "datetime(6)", nullable: true); migrationBuilder.Sql(""" UPDATE `conversations` AS `conversation` SET `conversation`.`LastMessageTime` = COALESCE( ( SELECT MAX(`message`.`CreationTime`) FROM `messages` AS `message` WHERE `message`.`StreamKey` = `conversation`.`StreamKey` AND `message`.`IsDeleted` = 0 ), `conversation`.`CreationTime` ); """); migrationBuilder.CreateIndex( name: "IX_messages_StreamKey_MsgType_State_SequenceId", table: "messages", columns: new[] { "StreamKey", "MsgType", "State", "SequenceId" }); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropIndex( name: "IX_messages_StreamKey_MsgType_State_SequenceId", table: "messages"); migrationBuilder.DropColumn( name: "LastMessageTime", table: "conversations"); } } }