20260611112621_AddApiPurchase.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using System;
  2. using Microsoft.EntityFrameworkCore.Migrations;
  3. #nullable disable
  4. namespace Infrastructure.Migrations.AppDb
  5. {
  6. /// <inheritdoc />
  7. public partial class AddApiPurchase : Migration
  8. {
  9. /// <inheritdoc />
  10. protected override void Up(MigrationBuilder migrationBuilder)
  11. {
  12. migrationBuilder.AddColumn<decimal>(
  13. name: "ApiCommissionRate",
  14. table: "Game",
  15. type: "decimal(18,2)",
  16. nullable: false,
  17. defaultValue: 0m);
  18. migrationBuilder.CreateTable(
  19. name: "ApiPurchase",
  20. columns: table => new
  21. {
  22. ID = table.Column<int>(type: "int", nullable: false)
  23. .Annotation("SqlServer:Identity", "1, 1"),
  24. ApplicationID = table.Column<int>(type: "int", nullable: false),
  25. ChannelID = table.Column<int>(type: "int", nullable: false),
  26. CreditedMemberID = table.Column<int>(type: "int", nullable: false),
  27. GameID = table.Column<int>(type: "int", nullable: false),
  28. OrderID = table.Column<string>(type: "nvarchar(255)", maxLength: 255, nullable: false),
  29. Marketplace = table.Column<int>(type: "int", nullable: false),
  30. ProductID = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
  31. SubID = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
  32. OrderPrice = table.Column<int>(type: "int", nullable: false),
  33. CommissionRate = table.Column<decimal>(type: "decimal(5,2)", precision: 5, scale: 2, nullable: false),
  34. CommissionAmount = table.Column<int>(type: "int", nullable: false),
  35. CatalogPrice = table.Column<int>(type: "int", nullable: true),
  36. PriceMismatched = table.Column<bool>(type: "bit", nullable: false),
  37. Status = table.Column<int>(type: "int", nullable: false),
  38. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
  39. ConfirmDueAt = table.Column<DateTime>(type: "datetime2", nullable: false),
  40. ConfirmedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
  41. CanceledAt = table.Column<DateTime>(type: "datetime2", nullable: true)
  42. },
  43. constraints: table =>
  44. {
  45. table.PrimaryKey("PK_ApiPurchase", x => x.ID);
  46. table.ForeignKey(
  47. name: "FK_ApiPurchase_ApiApplication_ApplicationID",
  48. column: x => x.ApplicationID,
  49. principalTable: "ApiApplication",
  50. principalColumn: "ID",
  51. onDelete: ReferentialAction.Restrict);
  52. table.ForeignKey(
  53. name: "FK_ApiPurchase_Channel_ChannelID",
  54. column: x => x.ChannelID,
  55. principalTable: "Channel",
  56. principalColumn: "ID",
  57. onDelete: ReferentialAction.Restrict);
  58. table.ForeignKey(
  59. name: "FK_ApiPurchase_Game_GameID",
  60. column: x => x.GameID,
  61. principalTable: "Game",
  62. principalColumn: "ID",
  63. onDelete: ReferentialAction.Restrict);
  64. },
  65. comment: "게임사 API 결제 보고 원장 (채널 판매 수수료, 14일 보류 후 확정)");
  66. migrationBuilder.CreateTable(
  67. name: "GameProductCatalog",
  68. columns: table => new
  69. {
  70. ID = table.Column<int>(type: "int", nullable: false)
  71. .Annotation("SqlServer:Identity", "1, 1"),
  72. GameID = table.Column<int>(type: "int", nullable: false),
  73. ProductID = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
  74. Price = table.Column<int>(type: "int", nullable: false),
  75. IsActive = table.Column<bool>(type: "bit", nullable: false),
  76. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
  77. UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true)
  78. },
  79. constraints: table =>
  80. {
  81. table.PrimaryKey("PK_GameProductCatalog", x => x.ID);
  82. table.ForeignKey(
  83. name: "FK_GameProductCatalog_Game_GameID",
  84. column: x => x.GameID,
  85. principalTable: "Game",
  86. principalColumn: "ID",
  87. onDelete: ReferentialAction.Cascade);
  88. },
  89. comment: "게임별 인앱 상품 SKU 정가 카탈로그 (API 결제 보고가 검증용)");
  90. migrationBuilder.CreateTable(
  91. name: "ApiPurchaseCancel",
  92. columns: table => new
  93. {
  94. ID = table.Column<int>(type: "int", nullable: false)
  95. .Annotation("SqlServer:Identity", "1, 1"),
  96. PurchaseID = table.Column<int>(type: "int", nullable: false),
  97. ApplicationID = table.Column<int>(type: "int", nullable: false),
  98. ChannelID = table.Column<int>(type: "int", nullable: false),
  99. CreditedMemberID = table.Column<int>(type: "int", nullable: false),
  100. WasConfirmed = table.Column<bool>(type: "bit", nullable: false),
  101. RecoveredAmount = table.Column<int>(type: "int", nullable: false),
  102. ShortfallAmount = table.Column<int>(type: "int", nullable: false),
  103. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
  104. },
  105. constraints: table =>
  106. {
  107. table.PrimaryKey("PK_ApiPurchaseCancel", x => x.ID);
  108. table.ForeignKey(
  109. name: "FK_ApiPurchaseCancel_ApiPurchase_PurchaseID",
  110. column: x => x.PurchaseID,
  111. principalTable: "ApiPurchase",
  112. principalColumn: "ID",
  113. onDelete: ReferentialAction.Restrict);
  114. },
  115. comment: "API 결제 취소 감사 기록 (1 결제 1 취소)");
  116. migrationBuilder.CreateIndex(
  117. name: "IX_ApiPurchase_ApplicationID_Marketplace_OrderID",
  118. table: "ApiPurchase",
  119. columns: new[] { "ApplicationID", "Marketplace", "OrderID" },
  120. unique: true);
  121. migrationBuilder.CreateIndex(
  122. name: "IX_ApiPurchase_ChannelID",
  123. table: "ApiPurchase",
  124. column: "ChannelID");
  125. migrationBuilder.CreateIndex(
  126. name: "IX_ApiPurchase_CreatedAt",
  127. table: "ApiPurchase",
  128. column: "CreatedAt");
  129. migrationBuilder.CreateIndex(
  130. name: "IX_ApiPurchase_GameID",
  131. table: "ApiPurchase",
  132. column: "GameID");
  133. migrationBuilder.CreateIndex(
  134. name: "IX_ApiPurchase_Status_ConfirmDueAt",
  135. table: "ApiPurchase",
  136. columns: new[] { "Status", "ConfirmDueAt" });
  137. migrationBuilder.CreateIndex(
  138. name: "IX_ApiPurchaseCancel_ApplicationID",
  139. table: "ApiPurchaseCancel",
  140. column: "ApplicationID");
  141. migrationBuilder.CreateIndex(
  142. name: "IX_ApiPurchaseCancel_ChannelID",
  143. table: "ApiPurchaseCancel",
  144. column: "ChannelID");
  145. migrationBuilder.CreateIndex(
  146. name: "IX_ApiPurchaseCancel_CreatedAt",
  147. table: "ApiPurchaseCancel",
  148. column: "CreatedAt");
  149. migrationBuilder.CreateIndex(
  150. name: "IX_ApiPurchaseCancel_PurchaseID",
  151. table: "ApiPurchaseCancel",
  152. column: "PurchaseID",
  153. unique: true);
  154. migrationBuilder.CreateIndex(
  155. name: "IX_GameProductCatalog_GameID_ProductID",
  156. table: "GameProductCatalog",
  157. columns: new[] { "GameID", "ProductID" },
  158. unique: true);
  159. }
  160. /// <inheritdoc />
  161. protected override void Down(MigrationBuilder migrationBuilder)
  162. {
  163. migrationBuilder.DropTable(
  164. name: "ApiPurchaseCancel");
  165. migrationBuilder.DropTable(
  166. name: "GameProductCatalog");
  167. migrationBuilder.DropTable(
  168. name: "ApiPurchase");
  169. migrationBuilder.DropColumn(
  170. name: "ApiCommissionRate",
  171. table: "Game");
  172. }
  173. }
  174. }