using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql
{
    /// <inheritdoc />
    public partial class BackgroundJobOutbox : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "BackgroundJobOutboxMessages",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    JobKind = table.Column<int>(type: "int", nullable: false),
                    JobId = table.Column<Guid>(type: "char(36)", nullable: false),
                    State = table.Column<int>(type: "int", nullable: false),
                    PublishAttempts = table.Column<int>(type: "int", nullable: false),
                    ProcessingAttempts = table.Column<int>(type: "int", nullable: false),
                    PublishedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    ProcessingToken = table.Column<Guid>(type: "char(36)", nullable: true),
                    LeaseExpiresAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    CompletedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    LastError = table.Column<string>(type: "varchar(2000)", maxLength: 2000, nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BackgroundJobOutboxMessages", x => x.Id);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_BackgroundJobOutboxMessages_JobKind_JobId",
                table: "BackgroundJobOutboxMessages",
                columns: new[] { "JobKind", "JobId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_BackgroundJobOutboxMessages_LeaseExpiresAt",
                table: "BackgroundJobOutboxMessages",
                column: "LeaseExpiresAt");

            migrationBuilder.CreateIndex(
                name: "IX_BackgroundJobOutboxMessages_State_CreatedAt",
                table: "BackgroundJobOutboxMessages",
                columns: new[] { "State", "CreatedAt" });

            migrationBuilder.CreateIndex(
                name: "IX_BackgroundJobOutboxMessages_State_CompletedAt",
                table: "BackgroundJobOutboxMessages",
                columns: new[] { "State", "CompletedAt" });
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "BackgroundJobOutboxMessages");
        }
    }
}
