You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20230303145041_Initial.cs 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. using System;
  2. using Microsoft.EntityFrameworkCore.Migrations;
  3. #nullable disable
  4. namespace Diligent.WebAPI.Data.Migrations
  5. {
  6. public partial class Initial : Migration
  7. {
  8. protected override void Up(MigrationBuilder migrationBuilder)
  9. {
  10. migrationBuilder.CreateTable(
  11. name: "AspNetRoles",
  12. columns: table => new
  13. {
  14. Id = table.Column<int>(type: "int", nullable: false)
  15. .Annotation("SqlServer:Identity", "1, 1"),
  16. Name = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
  17. NormalizedName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
  18. ConcurrencyStamp = table.Column<string>(type: "nvarchar(max)", nullable: true)
  19. },
  20. constraints: table =>
  21. {
  22. table.PrimaryKey("PK_AspNetRoles", x => x.Id);
  23. });
  24. migrationBuilder.CreateTable(
  25. name: "AspNetUsers",
  26. columns: table => new
  27. {
  28. Id = table.Column<int>(type: "int", nullable: false)
  29. .Annotation("SqlServer:Identity", "1, 1"),
  30. FirstName = table.Column<string>(type: "nvarchar(max)", nullable: false),
  31. LastName = table.Column<string>(type: "nvarchar(max)", nullable: false),
  32. IsEnabled = table.Column<bool>(type: "bit", nullable: true, defaultValue: true),
  33. Position = table.Column<string>(type: "nvarchar(max)", nullable: true),
  34. LinkedIn = table.Column<string>(type: "nvarchar(max)", nullable: true),
  35. UserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
  36. NormalizedUserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
  37. Email = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
  38. NormalizedEmail = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
  39. EmailConfirmed = table.Column<bool>(type: "bit", nullable: false),
  40. PasswordHash = table.Column<string>(type: "nvarchar(max)", nullable: true),
  41. SecurityStamp = table.Column<string>(type: "nvarchar(max)", nullable: true),
  42. ConcurrencyStamp = table.Column<string>(type: "nvarchar(max)", nullable: true),
  43. PhoneNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
  44. PhoneNumberConfirmed = table.Column<bool>(type: "bit", nullable: false),
  45. TwoFactorEnabled = table.Column<bool>(type: "bit", nullable: false),
  46. LockoutEnd = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
  47. LockoutEnabled = table.Column<bool>(type: "bit", nullable: false),
  48. AccessFailedCount = table.Column<int>(type: "int", nullable: false)
  49. },
  50. constraints: table =>
  51. {
  52. table.PrimaryKey("PK_AspNetUsers", x => x.Id);
  53. });
  54. migrationBuilder.CreateTable(
  55. name: "Categories",
  56. columns: table => new
  57. {
  58. Id = table.Column<int>(type: "int", nullable: false)
  59. .Annotation("SqlServer:Identity", "1, 1"),
  60. Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
  61. ParentCategoryId = table.Column<int>(type: "int", nullable: true)
  62. },
  63. constraints: table =>
  64. {
  65. table.PrimaryKey("PK_Categories", x => x.Id);
  66. table.ForeignKey(
  67. name: "FK_Categories_Categories_ParentCategoryId",
  68. column: x => x.ParentCategoryId,
  69. principalTable: "Categories",
  70. principalColumn: "Id");
  71. });
  72. migrationBuilder.CreateTable(
  73. name: "Tags",
  74. columns: table => new
  75. {
  76. Id = table.Column<int>(type: "int", nullable: false)
  77. .Annotation("SqlServer:Identity", "1, 1"),
  78. Name = table.Column<string>(type: "nvarchar(max)", nullable: false)
  79. },
  80. constraints: table =>
  81. {
  82. table.PrimaryKey("PK_Tags", x => x.Id);
  83. });
  84. migrationBuilder.CreateTable(
  85. name: "WebhookDefinitions",
  86. columns: table => new
  87. {
  88. Id = table.Column<long>(type: "bigint", nullable: false)
  89. .Annotation("SqlServer:Identity", "1, 1"),
  90. Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
  91. DisplayName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
  92. Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
  93. CreatedAtUtc = table.Column<DateTime>(type: "datetime2", nullable: false),
  94. UpdatedAtUtc = table.Column<DateTime>(type: "datetime2", nullable: true),
  95. DeletedAtUtc = table.Column<DateTime>(type: "datetime2", nullable: true)
  96. },
  97. constraints: table =>
  98. {
  99. table.PrimaryKey("PK_WebhookDefinitions", x => x.Id);
  100. });
  101. migrationBuilder.CreateTable(
  102. name: "AspNetRoleClaims",
  103. columns: table => new
  104. {
  105. Id = table.Column<int>(type: "int", nullable: false)
  106. .Annotation("SqlServer:Identity", "1, 1"),
  107. RoleId = table.Column<int>(type: "int", nullable: false),
  108. ClaimType = table.Column<string>(type: "nvarchar(max)", nullable: true),
  109. ClaimValue = table.Column<string>(type: "nvarchar(max)", nullable: true)
  110. },
  111. constraints: table =>
  112. {
  113. table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
  114. table.ForeignKey(
  115. name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
  116. column: x => x.RoleId,
  117. principalTable: "AspNetRoles",
  118. principalColumn: "Id",
  119. onDelete: ReferentialAction.Cascade);
  120. });
  121. migrationBuilder.CreateTable(
  122. name: "AspNetUserClaims",
  123. columns: table => new
  124. {
  125. Id = table.Column<int>(type: "int", nullable: false)
  126. .Annotation("SqlServer:Identity", "1, 1"),
  127. UserId = table.Column<int>(type: "int", nullable: false),
  128. ClaimType = table.Column<string>(type: "nvarchar(max)", nullable: true),
  129. ClaimValue = table.Column<string>(type: "nvarchar(max)", nullable: true)
  130. },
  131. constraints: table =>
  132. {
  133. table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
  134. table.ForeignKey(
  135. name: "FK_AspNetUserClaims_AspNetUsers_UserId",
  136. column: x => x.UserId,
  137. principalTable: "AspNetUsers",
  138. principalColumn: "Id",
  139. onDelete: ReferentialAction.Cascade);
  140. });
  141. migrationBuilder.CreateTable(
  142. name: "AspNetUserLogins",
  143. columns: table => new
  144. {
  145. LoginProvider = table.Column<string>(type: "nvarchar(450)", nullable: false),
  146. ProviderKey = table.Column<string>(type: "nvarchar(450)", nullable: false),
  147. ProviderDisplayName = table.Column<string>(type: "nvarchar(max)", nullable: true),
  148. UserId = table.Column<int>(type: "int", nullable: false)
  149. },
  150. constraints: table =>
  151. {
  152. table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
  153. table.ForeignKey(
  154. name: "FK_AspNetUserLogins_AspNetUsers_UserId",
  155. column: x => x.UserId,
  156. principalTable: "AspNetUsers",
  157. principalColumn: "Id",
  158. onDelete: ReferentialAction.Cascade);
  159. });
  160. migrationBuilder.CreateTable(
  161. name: "AspNetUserRoles",
  162. columns: table => new
  163. {
  164. UserId = table.Column<int>(type: "int", nullable: false),
  165. RoleId = table.Column<int>(type: "int", nullable: false)
  166. },
  167. constraints: table =>
  168. {
  169. table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
  170. table.ForeignKey(
  171. name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
  172. column: x => x.RoleId,
  173. principalTable: "AspNetRoles",
  174. principalColumn: "Id",
  175. onDelete: ReferentialAction.Cascade);
  176. table.ForeignKey(
  177. name: "FK_AspNetUserRoles_AspNetUsers_UserId",
  178. column: x => x.UserId,
  179. principalTable: "AspNetUsers",
  180. principalColumn: "Id",
  181. onDelete: ReferentialAction.Cascade);
  182. });
  183. migrationBuilder.CreateTable(
  184. name: "AspNetUserTokens",
  185. columns: table => new
  186. {
  187. UserId = table.Column<int>(type: "int", nullable: false),
  188. LoginProvider = table.Column<string>(type: "nvarchar(450)", nullable: false),
  189. Name = table.Column<string>(type: "nvarchar(450)", nullable: false),
  190. Value = table.Column<string>(type: "nvarchar(max)", nullable: true)
  191. },
  192. constraints: table =>
  193. {
  194. table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
  195. table.ForeignKey(
  196. name: "FK_AspNetUserTokens_AspNetUsers_UserId",
  197. column: x => x.UserId,
  198. principalTable: "AspNetUsers",
  199. principalColumn: "Id",
  200. onDelete: ReferentialAction.Cascade);
  201. });
  202. migrationBuilder.CreateTable(
  203. name: "RefreshTokens",
  204. columns: table => new
  205. {
  206. Id = table.Column<int>(type: "int", nullable: false)
  207. .Annotation("SqlServer:Identity", "1, 1"),
  208. Token = table.Column<string>(type: "nvarchar(max)", nullable: false),
  209. JwtId = table.Column<string>(type: "nvarchar(max)", nullable: false),
  210. CreationDate = table.Column<DateTime>(type: "datetime2", nullable: false),
  211. ExpiryDate = table.Column<DateTime>(type: "datetime2", nullable: false),
  212. Used = table.Column<bool>(type: "bit", nullable: false),
  213. Invalidated = table.Column<bool>(type: "bit", nullable: false),
  214. UserId = table.Column<int>(type: "int", nullable: false)
  215. },
  216. constraints: table =>
  217. {
  218. table.PrimaryKey("PK_RefreshTokens", x => x.Id);
  219. table.ForeignKey(
  220. name: "FK_RefreshTokens_AspNetUsers_UserId",
  221. column: x => x.UserId,
  222. principalTable: "AspNetUsers",
  223. principalColumn: "Id",
  224. onDelete: ReferentialAction.Cascade);
  225. });
  226. migrationBuilder.CreateTable(
  227. name: "Files",
  228. columns: table => new
  229. {
  230. Id = table.Column<int>(type: "int", nullable: false)
  231. .Annotation("SqlServer:Identity", "1, 1"),
  232. Title = table.Column<string>(type: "nvarchar(max)", nullable: false),
  233. DocumentId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
  234. CategoryId = table.Column<int>(type: "int", nullable: true),
  235. Deleted = table.Column<bool>(type: "bit", nullable: false),
  236. Note = table.Column<string>(type: "nvarchar(max)", nullable: false)
  237. },
  238. constraints: table =>
  239. {
  240. table.PrimaryKey("PK_Files", x => x.Id);
  241. table.ForeignKey(
  242. name: "FK_Files_Categories_CategoryId",
  243. column: x => x.CategoryId,
  244. principalTable: "Categories",
  245. principalColumn: "Id");
  246. });
  247. migrationBuilder.CreateTable(
  248. name: "UserCategories",
  249. columns: table => new
  250. {
  251. Id = table.Column<int>(type: "int", nullable: false)
  252. .Annotation("SqlServer:Identity", "1, 1"),
  253. UserId = table.Column<int>(type: "int", nullable: false),
  254. CategoryId = table.Column<int>(type: "int", nullable: false)
  255. },
  256. constraints: table =>
  257. {
  258. table.PrimaryKey("PK_UserCategories", x => x.Id);
  259. table.ForeignKey(
  260. name: "FK_UserCategories_AspNetUsers_UserId",
  261. column: x => x.UserId,
  262. principalTable: "AspNetUsers",
  263. principalColumn: "Id",
  264. onDelete: ReferentialAction.Cascade);
  265. table.ForeignKey(
  266. name: "FK_UserCategories_Categories_CategoryId",
  267. column: x => x.CategoryId,
  268. principalTable: "Categories",
  269. principalColumn: "Id",
  270. onDelete: ReferentialAction.Cascade);
  271. });
  272. migrationBuilder.CreateTable(
  273. name: "WebhookSubscriptions",
  274. columns: table => new
  275. {
  276. Id = table.Column<long>(type: "bigint", nullable: false)
  277. .Annotation("SqlServer:Identity", "1, 1"),
  278. WebhookURL = table.Column<string>(type: "nvarchar(max)", nullable: false),
  279. IsActive = table.Column<bool>(type: "bit", nullable: false),
  280. WebhookDefinitionId = table.Column<long>(type: "bigint", nullable: false),
  281. CreatedAtUtc = table.Column<DateTime>(type: "datetime2", nullable: false),
  282. UpdatedAtUtc = table.Column<DateTime>(type: "datetime2", nullable: true),
  283. DeletedAtUtc = table.Column<DateTime>(type: "datetime2", nullable: true)
  284. },
  285. constraints: table =>
  286. {
  287. table.PrimaryKey("PK_WebhookSubscriptions", x => x.Id);
  288. table.ForeignKey(
  289. name: "FK_WebhookSubscriptions_WebhookDefinitions_WebhookDefinitionId",
  290. column: x => x.WebhookDefinitionId,
  291. principalTable: "WebhookDefinitions",
  292. principalColumn: "Id",
  293. onDelete: ReferentialAction.Cascade);
  294. });
  295. migrationBuilder.CreateTable(
  296. name: "FileEntityTag",
  297. columns: table => new
  298. {
  299. FilesId = table.Column<int>(type: "int", nullable: false),
  300. TagsId = table.Column<int>(type: "int", nullable: false)
  301. },
  302. constraints: table =>
  303. {
  304. table.PrimaryKey("PK_FileEntityTag", x => new { x.FilesId, x.TagsId });
  305. table.ForeignKey(
  306. name: "FK_FileEntityTag_Files_FilesId",
  307. column: x => x.FilesId,
  308. principalTable: "Files",
  309. principalColumn: "Id",
  310. onDelete: ReferentialAction.Cascade);
  311. table.ForeignKey(
  312. name: "FK_FileEntityTag_Tags_TagsId",
  313. column: x => x.TagsId,
  314. principalTable: "Tags",
  315. principalColumn: "Id",
  316. onDelete: ReferentialAction.Cascade);
  317. });
  318. migrationBuilder.CreateIndex(
  319. name: "IX_AspNetRoleClaims_RoleId",
  320. table: "AspNetRoleClaims",
  321. column: "RoleId");
  322. migrationBuilder.CreateIndex(
  323. name: "RoleNameIndex",
  324. table: "AspNetRoles",
  325. column: "NormalizedName",
  326. unique: true,
  327. filter: "[NormalizedName] IS NOT NULL");
  328. migrationBuilder.CreateIndex(
  329. name: "IX_AspNetUserClaims_UserId",
  330. table: "AspNetUserClaims",
  331. column: "UserId");
  332. migrationBuilder.CreateIndex(
  333. name: "IX_AspNetUserLogins_UserId",
  334. table: "AspNetUserLogins",
  335. column: "UserId");
  336. migrationBuilder.CreateIndex(
  337. name: "IX_AspNetUserRoles_RoleId",
  338. table: "AspNetUserRoles",
  339. column: "RoleId");
  340. migrationBuilder.CreateIndex(
  341. name: "EmailIndex",
  342. table: "AspNetUsers",
  343. column: "NormalizedEmail");
  344. migrationBuilder.CreateIndex(
  345. name: "UserNameIndex",
  346. table: "AspNetUsers",
  347. column: "NormalizedUserName",
  348. unique: true,
  349. filter: "[NormalizedUserName] IS NOT NULL");
  350. migrationBuilder.CreateIndex(
  351. name: "IX_Categories_ParentCategoryId",
  352. table: "Categories",
  353. column: "ParentCategoryId");
  354. migrationBuilder.CreateIndex(
  355. name: "IX_FileEntityTag_TagsId",
  356. table: "FileEntityTag",
  357. column: "TagsId");
  358. migrationBuilder.CreateIndex(
  359. name: "IX_Files_CategoryId",
  360. table: "Files",
  361. column: "CategoryId");
  362. migrationBuilder.CreateIndex(
  363. name: "IX_RefreshTokens_UserId",
  364. table: "RefreshTokens",
  365. column: "UserId");
  366. migrationBuilder.CreateIndex(
  367. name: "IX_UserCategories_CategoryId",
  368. table: "UserCategories",
  369. column: "CategoryId");
  370. migrationBuilder.CreateIndex(
  371. name: "IX_UserCategories_UserId",
  372. table: "UserCategories",
  373. column: "UserId");
  374. migrationBuilder.CreateIndex(
  375. name: "IX_WebhookSubscriptions_WebhookDefinitionId",
  376. table: "WebhookSubscriptions",
  377. column: "WebhookDefinitionId");
  378. }
  379. protected override void Down(MigrationBuilder migrationBuilder)
  380. {
  381. migrationBuilder.DropTable(
  382. name: "AspNetRoleClaims");
  383. migrationBuilder.DropTable(
  384. name: "AspNetUserClaims");
  385. migrationBuilder.DropTable(
  386. name: "AspNetUserLogins");
  387. migrationBuilder.DropTable(
  388. name: "AspNetUserRoles");
  389. migrationBuilder.DropTable(
  390. name: "AspNetUserTokens");
  391. migrationBuilder.DropTable(
  392. name: "FileEntityTag");
  393. migrationBuilder.DropTable(
  394. name: "RefreshTokens");
  395. migrationBuilder.DropTable(
  396. name: "UserCategories");
  397. migrationBuilder.DropTable(
  398. name: "WebhookSubscriptions");
  399. migrationBuilder.DropTable(
  400. name: "AspNetRoles");
  401. migrationBuilder.DropTable(
  402. name: "Files");
  403. migrationBuilder.DropTable(
  404. name: "Tags");
  405. migrationBuilder.DropTable(
  406. name: "AspNetUsers");
  407. migrationBuilder.DropTable(
  408. name: "WebhookDefinitions");
  409. migrationBuilder.DropTable(
  410. name: "Categories");
  411. }
  412. }
  413. }