using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Infrastructure.Migrations.AppDb
{
    /// <inheritdoc />
    public partial class AddCoinMarketTable : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "Market",
                table: "Coin");

            migrationBuilder.CreateTable(
                name: "CoinMarket",
                columns: table => new
                {
                    ID = table.Column<int>(type: "int", nullable: false, comment: "PK")
                        .Annotation("SqlServer:Identity", "1, 1"),
                    CoinID = table.Column<int>(type: "int", nullable: false, comment: "코인 ID"),
                    Market = table.Column<string>(type: "nvarchar(30)", maxLength: 30, nullable: false, comment: "거래쌍 (KRW-BTC 등)")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CoinMarket", x => x.ID);
                    table.ForeignKey(
                        name: "FK_CoinMarket_Coin_CoinID",
                        column: x => x.CoinID,
                        principalTable: "Coin",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "코인-거래쌍 연결");

            migrationBuilder.CreateIndex(
                name: "IX_CoinMarket_CoinID_Market",
                table: "CoinMarket",
                columns: new[] { "CoinID", "Market" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_CoinMarket_Market",
                table: "CoinMarket",
                column: "Market");
        }

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

            migrationBuilder.AddColumn<string>(
                name: "Market",
                table: "Coin",
                type: "nvarchar(30)",
                maxLength: 30,
                nullable: false,
                defaultValue: "",
                comment: "거래쌍 (KRW-BTC 등)");
        }
    }
}
