using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Infrastructure.Migrations.AppDb
{
///
public partial class AddCrypto : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn(
name: "CoinID",
table: "Board",
type: "int",
nullable: true);
migrationBuilder.CreateTable(
name: "Coin",
columns: table => new
{
ID = table.Column(type: "int", nullable: false, comment: "PK")
.Annotation("SqlServer:Identity", "1, 1"),
Symbol = table.Column(type: "nvarchar(30)", maxLength: 30, nullable: false, comment: "심볼 (BTC, ETH 등)"),
Name = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false, comment: "코인 이름"),
LogoImage = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: true, comment: "로고 이미지"),
Description = table.Column(type: "nvarchar(max)", nullable: true, comment: "설명"),
ContractAddress = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: true, comment: "컨트랙트 주소"),
WebsiteUrl = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: true, comment: "홈페이지 URL"),
WhitepaperUrl = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: true, comment: "백서 URL"),
TwitterUrl = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: true, comment: "트위터 URL"),
TelegramUrl = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: true, comment: "텔레그램 URL"),
IsActive = table.Column(type: "bit", nullable: false, comment: "사용 여부"),
IsWarning = table.Column(type: "bit", nullable: false, comment: "위험 경고"),
IsNew = table.Column(type: "bit", nullable: false, comment: "신규 상장"),
IsDelisted = table.Column(type: "bit", nullable: false, comment: "상장 폐지"),
UpdatedAt = table.Column(type: "datetime2", nullable: true, comment: "수정 일시"),
CreatedAt = table.Column(type: "datetime2", nullable: false, comment: "등록 일시")
},
constraints: table =>
{
table.PrimaryKey("PK_Coin", x => x.ID);
},
comment: "코인/토큰");
migrationBuilder.CreateTable(
name: "CoinCategory",
columns: table => new
{
ID = table.Column(type: "int", nullable: false, comment: "PK")
.Annotation("SqlServer:Identity", "1, 1"),
Code = table.Column(type: "nvarchar(30)", maxLength: 30, nullable: false, comment: "카테고리 코드"),
Name = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false, comment: "카테고리 이름"),
Order = table.Column(type: "smallint", nullable: false, comment: "순서"),
IsActive = table.Column(type: "bit", nullable: false, comment: "사용 여부"),
UpdatedAt = table.Column(type: "datetime2", nullable: true, comment: "수정 일시"),
CreatedAt = table.Column(type: "datetime2", nullable: false, comment: "등록 일시")
},
constraints: table =>
{
table.PrimaryKey("PK_CoinCategory", x => x.ID);
},
comment: "코인 카테고리");
migrationBuilder.CreateTable(
name: "CoinCategoryMap",
columns: table => new
{
ID = table.Column(type: "int", nullable: false, comment: "PK")
.Annotation("SqlServer:Identity", "1, 1"),
CoinID = table.Column(type: "int", nullable: false, comment: "코인 ID"),
CategoryID = table.Column(type: "int", nullable: false, comment: "카테고리 ID")
},
constraints: table =>
{
table.PrimaryKey("PK_CoinCategoryMap", x => x.ID);
table.ForeignKey(
name: "FK_CoinCategoryMap_CoinCategory_CategoryID",
column: x => x.CategoryID,
principalTable: "CoinCategory",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_CoinCategoryMap_Coin_CoinID",
column: x => x.CoinID,
principalTable: "Coin",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
},
comment: "코인-카테고리 연결");
migrationBuilder.CreateIndex(
name: "IX_Board_CoinID",
table: "Board",
column: "CoinID");
migrationBuilder.CreateIndex(
name: "IX_Coin_IsActive",
table: "Coin",
column: "IsActive");
migrationBuilder.CreateIndex(
name: "IX_Coin_IsDelisted",
table: "Coin",
column: "IsDelisted");
migrationBuilder.CreateIndex(
name: "IX_Coin_IsNew",
table: "Coin",
column: "IsNew");
migrationBuilder.CreateIndex(
name: "IX_Coin_IsWarning",
table: "Coin",
column: "IsWarning");
migrationBuilder.CreateIndex(
name: "IX_Coin_Symbol",
table: "Coin",
column: "Symbol",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Coin_Symbol_IsActive",
table: "Coin",
columns: new[] { "Symbol", "IsActive" });
migrationBuilder.CreateIndex(
name: "IX_CoinCategory_Code",
table: "CoinCategory",
column: "Code",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_CoinCategory_IsActive",
table: "CoinCategory",
column: "IsActive");
migrationBuilder.CreateIndex(
name: "IX_CoinCategory_Order",
table: "CoinCategory",
column: "Order");
migrationBuilder.CreateIndex(
name: "IX_CoinCategoryMap_CategoryID",
table: "CoinCategoryMap",
column: "CategoryID");
migrationBuilder.CreateIndex(
name: "IX_CoinCategoryMap_CoinID_CategoryID",
table: "CoinCategoryMap",
columns: new[] { "CoinID", "CategoryID" },
unique: true);
migrationBuilder.AddForeignKey(
name: "FK_Board_Coin_CoinID",
table: "Board",
column: "CoinID",
principalTable: "Coin",
principalColumn: "ID",
onDelete: ReferentialAction.SetNull);
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Board_Coin_CoinID",
table: "Board");
migrationBuilder.DropTable(
name: "CoinCategoryMap");
migrationBuilder.DropTable(
name: "CoinCategory");
migrationBuilder.DropTable(
name: "Coin");
migrationBuilder.DropIndex(
name: "IX_Board_CoinID",
table: "Board");
migrationBuilder.DropColumn(
name: "CoinID",
table: "Board");
}
}
}