20260602050554_AddDeveloperPortalSchema.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. using System;
  2. using Microsoft.EntityFrameworkCore.Migrations;
  3. #nullable disable
  4. namespace Infrastructure.Migrations.AppDb
  5. {
  6. /// <inheritdoc />
  7. public partial class AddDeveloperPortalSchema : Migration
  8. {
  9. /// <inheritdoc />
  10. protected override void Up(MigrationBuilder migrationBuilder)
  11. {
  12. migrationBuilder.AlterColumn<int>(
  13. name: "Price",
  14. table: "Product",
  15. type: "int",
  16. nullable: false,
  17. comment: "판매가 (KRW)",
  18. oldClrType: typeof(int),
  19. oldType: "int",
  20. oldComment: "정가 (P)");
  21. migrationBuilder.AlterColumn<int>(
  22. name: "DiscountValue",
  23. table: "Product",
  24. type: "int",
  25. nullable: false,
  26. oldClrType: typeof(int),
  27. oldType: "int",
  28. oldComment: "할인 값 (Percent: 0..99, Amount: 0..Price)");
  29. migrationBuilder.AlterColumn<byte>(
  30. name: "DiscountType",
  31. table: "Product",
  32. type: "tinyint",
  33. nullable: false,
  34. oldClrType: typeof(byte),
  35. oldType: "tinyint",
  36. oldComment: "할인 모드 (0=None, 1=Percent, 2=Amount)");
  37. migrationBuilder.CreateTable(
  38. name: "ApiApplication",
  39. columns: table => new
  40. {
  41. ID = table.Column<int>(type: "int", nullable: false)
  42. .Annotation("SqlServer:Identity", "1, 1"),
  43. OwnerMemberID = table.Column<int>(type: "int", nullable: false),
  44. Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
  45. Description = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
  46. HomepageUrl = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
  47. LogoPath = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
  48. Status = table.Column<int>(type: "int", nullable: false),
  49. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
  50. UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
  51. ApprovedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
  52. SuspendedAt = table.Column<DateTime>(type: "datetime2", nullable: true)
  53. },
  54. constraints: table =>
  55. {
  56. table.PrimaryKey("PK_ApiApplication", x => x.ID);
  57. table.ForeignKey(
  58. name: "FK_ApiApplication_Member_OwnerMemberID",
  59. column: x => x.OwnerMemberID,
  60. principalTable: "Member",
  61. principalColumn: "ID",
  62. onDelete: ReferentialAction.Cascade);
  63. },
  64. comment: "개발자 API 앱");
  65. migrationBuilder.CreateTable(
  66. name: "ApiPersonalAccessToken",
  67. columns: table => new
  68. {
  69. ID = table.Column<long>(type: "bigint", nullable: false)
  70. .Annotation("SqlServer:Identity", "1, 1"),
  71. OwnerMemberID = table.Column<int>(type: "int", nullable: false),
  72. Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
  73. TokenHash = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
  74. TokenHint = table.Column<string>(type: "nvarchar(4)", maxLength: 4, nullable: false),
  75. ScopesCsv = table.Column<string>(type: "nvarchar(1024)", maxLength: 1024, nullable: false),
  76. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
  77. ExpiresAt = table.Column<DateTime>(type: "datetime2", nullable: true),
  78. LastUsedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
  79. RevokedAt = table.Column<DateTime>(type: "datetime2", nullable: true)
  80. },
  81. constraints: table =>
  82. {
  83. table.PrimaryKey("PK_ApiPersonalAccessToken", x => x.ID);
  84. table.ForeignKey(
  85. name: "FK_ApiPersonalAccessToken_Member_OwnerMemberID",
  86. column: x => x.OwnerMemberID,
  87. principalTable: "Member",
  88. principalColumn: "ID",
  89. onDelete: ReferentialAction.Cascade);
  90. },
  91. comment: "Personal Access Token (PAT)");
  92. migrationBuilder.CreateTable(
  93. name: "ApiRequestLog",
  94. columns: table => new
  95. {
  96. ID = table.Column<long>(type: "bigint", nullable: false)
  97. .Annotation("SqlServer:Identity", "1, 1"),
  98. ApplicationID = table.Column<int>(type: "int", nullable: true),
  99. PatID = table.Column<long>(type: "bigint", nullable: true),
  100. Endpoint = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
  101. Method = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: false),
  102. StatusCode = table.Column<int>(type: "int", nullable: false),
  103. ResponseMs = table.Column<int>(type: "int", nullable: false),
  104. IpAddress = table.Column<string>(type: "nvarchar(45)", maxLength: 45, nullable: true),
  105. RequestedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
  106. },
  107. constraints: table =>
  108. {
  109. table.PrimaryKey("PK_ApiRequestLog", x => x.ID);
  110. },
  111. comment: "공개 API 호출 로그");
  112. migrationBuilder.CreateTable(
  113. name: "ApiApplicationScope",
  114. columns: table => new
  115. {
  116. ID = table.Column<int>(type: "int", nullable: false)
  117. .Annotation("SqlServer:Identity", "1, 1"),
  118. ApplicationID = table.Column<int>(type: "int", nullable: false),
  119. Scope = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
  120. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
  121. },
  122. constraints: table =>
  123. {
  124. table.PrimaryKey("PK_ApiApplicationScope", x => x.ID);
  125. table.ForeignKey(
  126. name: "FK_ApiApplicationScope_ApiApplication_ApplicationID",
  127. column: x => x.ApplicationID,
  128. principalTable: "ApiApplication",
  129. principalColumn: "ID",
  130. onDelete: ReferentialAction.Cascade);
  131. },
  132. comment: "앱이 요청한 scope 목록");
  133. migrationBuilder.CreateTable(
  134. name: "ApiCredential",
  135. columns: table => new
  136. {
  137. ID = table.Column<int>(type: "int", nullable: false)
  138. .Annotation("SqlServer:Identity", "1, 1"),
  139. ApplicationID = table.Column<int>(type: "int", nullable: false),
  140. ClientID = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
  141. SecretHash = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
  142. SecretHint = table.Column<string>(type: "nvarchar(4)", maxLength: 4, nullable: false),
  143. Status = table.Column<int>(type: "int", nullable: false),
  144. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
  145. LastUsedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
  146. RevokedAt = table.Column<DateTime>(type: "datetime2", nullable: true)
  147. },
  148. constraints: table =>
  149. {
  150. table.PrimaryKey("PK_ApiCredential", x => x.ID);
  151. table.ForeignKey(
  152. name: "FK_ApiCredential_ApiApplication_ApplicationID",
  153. column: x => x.ApplicationID,
  154. principalTable: "ApiApplication",
  155. principalColumn: "ID",
  156. onDelete: ReferentialAction.Cascade);
  157. },
  158. comment: "OAuth2 Client Credentials");
  159. migrationBuilder.CreateTable(
  160. name: "ApiRateLimit",
  161. columns: table => new
  162. {
  163. ID = table.Column<int>(type: "int", nullable: false)
  164. .Annotation("SqlServer:Identity", "1, 1"),
  165. ApplicationID = table.Column<int>(type: "int", nullable: false),
  166. LimitPerMinute = table.Column<int>(type: "int", nullable: false),
  167. CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
  168. UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
  169. },
  170. constraints: table =>
  171. {
  172. table.PrimaryKey("PK_ApiRateLimit", x => x.ID);
  173. table.ForeignKey(
  174. name: "FK_ApiRateLimit_ApiApplication_ApplicationID",
  175. column: x => x.ApplicationID,
  176. principalTable: "ApiApplication",
  177. principalColumn: "ID",
  178. onDelete: ReferentialAction.Cascade);
  179. },
  180. comment: "앱별 Rate Limit override");
  181. migrationBuilder.CreateIndex(
  182. name: "IX_ApiApplication_OwnerMemberID",
  183. table: "ApiApplication",
  184. column: "OwnerMemberID");
  185. migrationBuilder.CreateIndex(
  186. name: "IX_ApiApplication_Status",
  187. table: "ApiApplication",
  188. column: "Status");
  189. migrationBuilder.CreateIndex(
  190. name: "IX_ApiApplicationScope_ApplicationID_Scope",
  191. table: "ApiApplicationScope",
  192. columns: new[] { "ApplicationID", "Scope" },
  193. unique: true);
  194. migrationBuilder.CreateIndex(
  195. name: "IX_ApiCredential_ApplicationID",
  196. table: "ApiCredential",
  197. column: "ApplicationID");
  198. migrationBuilder.CreateIndex(
  199. name: "IX_ApiCredential_ClientID",
  200. table: "ApiCredential",
  201. column: "ClientID",
  202. unique: true);
  203. migrationBuilder.CreateIndex(
  204. name: "IX_ApiPersonalAccessToken_OwnerMemberID",
  205. table: "ApiPersonalAccessToken",
  206. column: "OwnerMemberID");
  207. migrationBuilder.CreateIndex(
  208. name: "IX_ApiPersonalAccessToken_TokenHash",
  209. table: "ApiPersonalAccessToken",
  210. column: "TokenHash",
  211. unique: true);
  212. migrationBuilder.CreateIndex(
  213. name: "IX_ApiRateLimit_ApplicationID",
  214. table: "ApiRateLimit",
  215. column: "ApplicationID",
  216. unique: true);
  217. migrationBuilder.CreateIndex(
  218. name: "IX_ApiRequestLog_ApplicationID",
  219. table: "ApiRequestLog",
  220. column: "ApplicationID");
  221. migrationBuilder.CreateIndex(
  222. name: "IX_ApiRequestLog_PatID",
  223. table: "ApiRequestLog",
  224. column: "PatID");
  225. migrationBuilder.CreateIndex(
  226. name: "IX_ApiRequestLog_RequestedAt",
  227. table: "ApiRequestLog",
  228. column: "RequestedAt");
  229. }
  230. /// <inheritdoc />
  231. protected override void Down(MigrationBuilder migrationBuilder)
  232. {
  233. migrationBuilder.DropTable(
  234. name: "ApiApplicationScope");
  235. migrationBuilder.DropTable(
  236. name: "ApiCredential");
  237. migrationBuilder.DropTable(
  238. name: "ApiPersonalAccessToken");
  239. migrationBuilder.DropTable(
  240. name: "ApiRateLimit");
  241. migrationBuilder.DropTable(
  242. name: "ApiRequestLog");
  243. migrationBuilder.DropTable(
  244. name: "ApiApplication");
  245. migrationBuilder.AlterColumn<int>(
  246. name: "Price",
  247. table: "Product",
  248. type: "int",
  249. nullable: false,
  250. comment: "정가 (P)",
  251. oldClrType: typeof(int),
  252. oldType: "int",
  253. oldComment: "판매가 (KRW)");
  254. migrationBuilder.AlterColumn<int>(
  255. name: "DiscountValue",
  256. table: "Product",
  257. type: "int",
  258. nullable: false,
  259. comment: "할인 값 (Percent: 0..99, Amount: 0..Price)",
  260. oldClrType: typeof(int),
  261. oldType: "int");
  262. migrationBuilder.AlterColumn<byte>(
  263. name: "DiscountType",
  264. table: "Product",
  265. type: "tinyint",
  266. nullable: false,
  267. comment: "할인 모드 (0=None, 1=Percent, 2=Amount)",
  268. oldClrType: typeof(byte),
  269. oldType: "tinyint");
  270. }
  271. }
  272. }