using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Infrastructure.Migrations.AppDb
{
///
public partial class AddApiPurchase : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn(
name: "ApiCommissionRate",
table: "Game",
type: "decimal(18,2)",
nullable: false,
defaultValue: 0m);
migrationBuilder.CreateTable(
name: "ApiPurchase",
columns: table => new
{
ID = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ApplicationID = table.Column(type: "int", nullable: false),
ChannelID = table.Column(type: "int", nullable: false),
CreditedMemberID = table.Column(type: "int", nullable: false),
GameID = table.Column(type: "int", nullable: false),
OrderID = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false),
Marketplace = table.Column(type: "int", nullable: false),
ProductID = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: true),
SubID = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: true),
OrderPrice = table.Column(type: "int", nullable: false),
CommissionRate = table.Column(type: "decimal(5,2)", precision: 5, scale: 2, nullable: false),
CommissionAmount = table.Column(type: "int", nullable: false),
CatalogPrice = table.Column(type: "int", nullable: true),
PriceMismatched = table.Column(type: "bit", nullable: false),
Status = table.Column(type: "int", nullable: false),
CreatedAt = table.Column(type: "datetime2", nullable: false),
ConfirmDueAt = table.Column(type: "datetime2", nullable: false),
ConfirmedAt = table.Column(type: "datetime2", nullable: true),
CanceledAt = table.Column(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ApiPurchase", x => x.ID);
table.ForeignKey(
name: "FK_ApiPurchase_ApiApplication_ApplicationID",
column: x => x.ApplicationID,
principalTable: "ApiApplication",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_ApiPurchase_Channel_ChannelID",
column: x => x.ChannelID,
principalTable: "Channel",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_ApiPurchase_Game_GameID",
column: x => x.GameID,
principalTable: "Game",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
},
comment: "게임사 API 결제 보고 원장 (채널 판매 수수료, 14일 보류 후 확정)");
migrationBuilder.CreateTable(
name: "GameProductCatalog",
columns: table => new
{
ID = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
GameID = table.Column(type: "int", nullable: false),
ProductID = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false),
Price = table.Column(type: "int", nullable: false),
IsActive = table.Column(type: "bit", nullable: false),
CreatedAt = table.Column(type: "datetime2", nullable: false),
UpdatedAt = table.Column(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_GameProductCatalog", x => x.ID);
table.ForeignKey(
name: "FK_GameProductCatalog_Game_GameID",
column: x => x.GameID,
principalTable: "Game",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
},
comment: "게임별 인앱 상품 SKU 정가 카탈로그 (API 결제 보고가 검증용)");
migrationBuilder.CreateTable(
name: "ApiPurchaseCancel",
columns: table => new
{
ID = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PurchaseID = table.Column(type: "int", nullable: false),
ApplicationID = table.Column(type: "int", nullable: false),
ChannelID = table.Column(type: "int", nullable: false),
CreditedMemberID = table.Column(type: "int", nullable: false),
WasConfirmed = table.Column(type: "bit", nullable: false),
RecoveredAmount = table.Column(type: "int", nullable: false),
ShortfallAmount = table.Column(type: "int", nullable: false),
CreatedAt = table.Column(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ApiPurchaseCancel", x => x.ID);
table.ForeignKey(
name: "FK_ApiPurchaseCancel_ApiPurchase_PurchaseID",
column: x => x.PurchaseID,
principalTable: "ApiPurchase",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
},
comment: "API 결제 취소 감사 기록 (1 결제 1 취소)");
migrationBuilder.CreateIndex(
name: "IX_ApiPurchase_ApplicationID_Marketplace_OrderID",
table: "ApiPurchase",
columns: new[] { "ApplicationID", "Marketplace", "OrderID" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_ApiPurchase_ChannelID",
table: "ApiPurchase",
column: "ChannelID");
migrationBuilder.CreateIndex(
name: "IX_ApiPurchase_CreatedAt",
table: "ApiPurchase",
column: "CreatedAt");
migrationBuilder.CreateIndex(
name: "IX_ApiPurchase_GameID",
table: "ApiPurchase",
column: "GameID");
migrationBuilder.CreateIndex(
name: "IX_ApiPurchase_Status_ConfirmDueAt",
table: "ApiPurchase",
columns: new[] { "Status", "ConfirmDueAt" });
migrationBuilder.CreateIndex(
name: "IX_ApiPurchaseCancel_ApplicationID",
table: "ApiPurchaseCancel",
column: "ApplicationID");
migrationBuilder.CreateIndex(
name: "IX_ApiPurchaseCancel_ChannelID",
table: "ApiPurchaseCancel",
column: "ChannelID");
migrationBuilder.CreateIndex(
name: "IX_ApiPurchaseCancel_CreatedAt",
table: "ApiPurchaseCancel",
column: "CreatedAt");
migrationBuilder.CreateIndex(
name: "IX_ApiPurchaseCancel_PurchaseID",
table: "ApiPurchaseCancel",
column: "PurchaseID",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_GameProductCatalog_GameID_ProductID",
table: "GameProductCatalog",
columns: new[] { "GameID", "ProductID" },
unique: true);
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ApiPurchaseCancel");
migrationBuilder.DropTable(
name: "GameProductCatalog");
migrationBuilder.DropTable(
name: "ApiPurchase");
migrationBuilder.DropColumn(
name: "ApiCommissionRate",
table: "Game");
}
}
}