20240128145047_InitialCreate.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. using System;
  2. using Microsoft.EntityFrameworkCore.Migrations;
  3. #nullable disable
  4. #pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
  5. namespace MTWorkHR.Identity.Migrations
  6. {
  7. /// <inheritdoc />
  8. public partial class InitialCreate : Migration
  9. {
  10. /// <inheritdoc />
  11. protected override void Up(MigrationBuilder migrationBuilder)
  12. {
  13. migrationBuilder.CreateTable(
  14. name: "AspNetRoles",
  15. columns: table => new
  16. {
  17. Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
  18. CreateUser = table.Column<string>(type: "nvarchar(max)", nullable: true),
  19. UpdateUser = table.Column<string>(type: "nvarchar(max)", nullable: true),
  20. CreateDate = table.Column<DateTime>(type: "datetime2", nullable: false),
  21. UpdateDate = table.Column<DateTime>(type: "datetime2", nullable: true),
  22. IsDeleted = table.Column<bool>(type: "bit", nullable: false),
  23. DeleteUserId = table.Column<string>(type: "nvarchar(max)", nullable: true),
  24. IsAdmin = table.Column<bool>(type: "bit", nullable: true),
  25. Name = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
  26. NormalizedName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
  27. ConcurrencyStamp = table.Column<string>(type: "nvarchar(max)", nullable: true)
  28. },
  29. constraints: table =>
  30. {
  31. table.PrimaryKey("PK_AspNetRoles", x => x.Id);
  32. });
  33. migrationBuilder.CreateTable(
  34. name: "AspNetUsers",
  35. columns: table => new
  36. {
  37. Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
  38. FirstName = table.Column<string>(type: "nvarchar(max)", nullable: false),
  39. LastName = table.Column<string>(type: "nvarchar(max)", nullable: false),
  40. UserType = table.Column<int>(type: "int", nullable: false),
  41. ManagerId = table.Column<string>(type: "nvarchar(450)", nullable: true),
  42. CreateUser = table.Column<string>(type: "nvarchar(max)", nullable: true),
  43. UpdateUser = table.Column<string>(type: "nvarchar(max)", nullable: true),
  44. IsStopped = table.Column<bool>(type: "bit", nullable: false),
  45. IsDeleted = table.Column<bool>(type: "bit", nullable: false),
  46. DeleteUserId = table.Column<string>(type: "nvarchar(max)", nullable: true),
  47. UserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
  48. NormalizedUserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
  49. Email = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
  50. NormalizedEmail = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
  51. EmailConfirmed = table.Column<bool>(type: "bit", nullable: false),
  52. PasswordHash = table.Column<string>(type: "nvarchar(max)", nullable: true),
  53. SecurityStamp = table.Column<string>(type: "nvarchar(max)", nullable: true),
  54. ConcurrencyStamp = table.Column<string>(type: "nvarchar(max)", nullable: true),
  55. PhoneNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
  56. PhoneNumberConfirmed = table.Column<bool>(type: "bit", nullable: false),
  57. TwoFactorEnabled = table.Column<bool>(type: "bit", nullable: false),
  58. LockoutEnd = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
  59. LockoutEnabled = table.Column<bool>(type: "bit", nullable: false),
  60. AccessFailedCount = table.Column<int>(type: "int", nullable: false)
  61. },
  62. constraints: table =>
  63. {
  64. table.PrimaryKey("PK_AspNetUsers", x => x.Id);
  65. table.ForeignKey(
  66. name: "FK_AspNetUsers_AspNetUsers_ManagerId",
  67. column: x => x.ManagerId,
  68. principalTable: "AspNetUsers",
  69. principalColumn: "Id");
  70. });
  71. migrationBuilder.CreateTable(
  72. name: "Permissions",
  73. columns: table => new
  74. {
  75. Id = table.Column<long>(type: "bigint", nullable: false)
  76. .Annotation("SqlServer:Identity", "1, 1"),
  77. Name = table.Column<string>(type: "nvarchar(250)", maxLength: 250, nullable: false),
  78. CategoryName = table.Column<string>(type: "nvarchar(150)", maxLength: 150, nullable: false),
  79. Desc = table.Column<string>(type: "nvarchar(250)", maxLength: 250, nullable: false),
  80. Show = table.Column<bool>(type: "bit", nullable: false)
  81. },
  82. constraints: table =>
  83. {
  84. table.PrimaryKey("PK_Permissions", x => x.Id);
  85. });
  86. migrationBuilder.CreateTable(
  87. name: "AspNetRoleClaims",
  88. columns: table => new
  89. {
  90. Id = table.Column<int>(type: "int", nullable: false)
  91. .Annotation("SqlServer:Identity", "1, 1"),
  92. RoleId = table.Column<string>(type: "nvarchar(450)", nullable: false),
  93. ClaimType = table.Column<string>(type: "nvarchar(max)", nullable: true),
  94. ClaimValue = table.Column<string>(type: "nvarchar(max)", nullable: true)
  95. },
  96. constraints: table =>
  97. {
  98. table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
  99. table.ForeignKey(
  100. name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
  101. column: x => x.RoleId,
  102. principalTable: "AspNetRoles",
  103. principalColumn: "Id",
  104. onDelete: ReferentialAction.Cascade);
  105. });
  106. migrationBuilder.CreateTable(
  107. name: "ApplicationRoleApplicationUser",
  108. columns: table => new
  109. {
  110. UserRolesId = table.Column<string>(type: "nvarchar(450)", nullable: false),
  111. UsersId = table.Column<string>(type: "nvarchar(450)", nullable: false)
  112. },
  113. constraints: table =>
  114. {
  115. table.PrimaryKey("PK_ApplicationRoleApplicationUser", x => new { x.UserRolesId, x.UsersId });
  116. table.ForeignKey(
  117. name: "FK_ApplicationRoleApplicationUser_AspNetRoles_UserRolesId",
  118. column: x => x.UserRolesId,
  119. principalTable: "AspNetRoles",
  120. principalColumn: "Id",
  121. onDelete: ReferentialAction.Cascade);
  122. table.ForeignKey(
  123. name: "FK_ApplicationRoleApplicationUser_AspNetUsers_UsersId",
  124. column: x => x.UsersId,
  125. principalTable: "AspNetUsers",
  126. principalColumn: "Id",
  127. onDelete: ReferentialAction.Cascade);
  128. });
  129. migrationBuilder.CreateTable(
  130. name: "AspNetUserClaims",
  131. columns: table => new
  132. {
  133. Id = table.Column<int>(type: "int", nullable: false)
  134. .Annotation("SqlServer:Identity", "1, 1"),
  135. UserId = table.Column<string>(type: "nvarchar(450)", nullable: false),
  136. ClaimType = table.Column<string>(type: "nvarchar(max)", nullable: true),
  137. ClaimValue = table.Column<string>(type: "nvarchar(max)", nullable: true)
  138. },
  139. constraints: table =>
  140. {
  141. table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
  142. table.ForeignKey(
  143. name: "FK_AspNetUserClaims_AspNetUsers_UserId",
  144. column: x => x.UserId,
  145. principalTable: "AspNetUsers",
  146. principalColumn: "Id",
  147. onDelete: ReferentialAction.Cascade);
  148. });
  149. migrationBuilder.CreateTable(
  150. name: "AspNetUserLogins",
  151. columns: table => new
  152. {
  153. LoginProvider = table.Column<string>(type: "nvarchar(450)", nullable: false),
  154. ProviderKey = table.Column<string>(type: "nvarchar(450)", nullable: false),
  155. ProviderDisplayName = table.Column<string>(type: "nvarchar(max)", nullable: true),
  156. UserId = table.Column<string>(type: "nvarchar(450)", nullable: false)
  157. },
  158. constraints: table =>
  159. {
  160. table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
  161. table.ForeignKey(
  162. name: "FK_AspNetUserLogins_AspNetUsers_UserId",
  163. column: x => x.UserId,
  164. principalTable: "AspNetUsers",
  165. principalColumn: "Id",
  166. onDelete: ReferentialAction.Cascade);
  167. });
  168. migrationBuilder.CreateTable(
  169. name: "AspNetUserRoles",
  170. columns: table => new
  171. {
  172. UserId = table.Column<string>(type: "nvarchar(450)", nullable: false),
  173. RoleId = table.Column<string>(type: "nvarchar(450)", nullable: false)
  174. },
  175. constraints: table =>
  176. {
  177. table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
  178. table.ForeignKey(
  179. name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
  180. column: x => x.RoleId,
  181. principalTable: "AspNetRoles",
  182. principalColumn: "Id",
  183. onDelete: ReferentialAction.Cascade);
  184. table.ForeignKey(
  185. name: "FK_AspNetUserRoles_AspNetUsers_UserId",
  186. column: x => x.UserId,
  187. principalTable: "AspNetUsers",
  188. principalColumn: "Id",
  189. onDelete: ReferentialAction.Cascade);
  190. });
  191. migrationBuilder.CreateTable(
  192. name: "AspNetUserTokens",
  193. columns: table => new
  194. {
  195. UserId = table.Column<string>(type: "nvarchar(450)", nullable: false),
  196. LoginProvider = table.Column<string>(type: "nvarchar(450)", nullable: false),
  197. Name = table.Column<string>(type: "nvarchar(450)", nullable: false),
  198. Value = table.Column<string>(type: "nvarchar(max)", nullable: true)
  199. },
  200. constraints: table =>
  201. {
  202. table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
  203. table.ForeignKey(
  204. name: "FK_AspNetUserTokens_AspNetUsers_UserId",
  205. column: x => x.UserId,
  206. principalTable: "AspNetUsers",
  207. principalColumn: "Id",
  208. onDelete: ReferentialAction.Cascade);
  209. });
  210. migrationBuilder.CreateTable(
  211. name: "RolePermissions",
  212. columns: table => new
  213. {
  214. Id = table.Column<long>(type: "bigint", nullable: false)
  215. .Annotation("SqlServer:Identity", "1, 1"),
  216. RoleId = table.Column<string>(type: "nvarchar(450)", nullable: false),
  217. PermissionId = table.Column<long>(type: "bigint", nullable: false),
  218. PermissionName = table.Column<string>(type: "nvarchar(max)", nullable: false)
  219. },
  220. constraints: table =>
  221. {
  222. table.PrimaryKey("PK_RolePermissions", x => x.Id);
  223. table.ForeignKey(
  224. name: "FK_RolePermissions_AspNetRoles_RoleId",
  225. column: x => x.RoleId,
  226. principalTable: "AspNetRoles",
  227. principalColumn: "Id",
  228. onDelete: ReferentialAction.Cascade);
  229. table.ForeignKey(
  230. name: "FK_RolePermissions_Permissions_PermissionId",
  231. column: x => x.PermissionId,
  232. principalTable: "Permissions",
  233. principalColumn: "Id",
  234. onDelete: ReferentialAction.Cascade);
  235. });
  236. migrationBuilder.InsertData(
  237. table: "AspNetRoles",
  238. columns: new[] { "Id", "ConcurrencyStamp", "CreateDate", "CreateUser", "DeleteUserId", "IsAdmin", "IsDeleted", "Name", "NormalizedName", "UpdateDate", "UpdateUser" },
  239. values: new object[,]
  240. {
  241. { "AD5B3B92-2311-48F8-9DEC-F9FAEF1F211A", null, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), null, null, true, false, "Admin", "ADMIN", null, null },
  242. { "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", null, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), null, null, false, false, "Employee", "EMPLOYEE", null, null }
  243. });
  244. migrationBuilder.InsertData(
  245. table: "AspNetUsers",
  246. columns: new[] { "Id", "AccessFailedCount", "ConcurrencyStamp", "CreateUser", "DeleteUserId", "Email", "EmailConfirmed", "FirstName", "IsDeleted", "IsStopped", "LastName", "LockoutEnabled", "LockoutEnd", "ManagerId", "NormalizedEmail", "NormalizedUserName", "PasswordHash", "PhoneNumber", "PhoneNumberConfirmed", "SecurityStamp", "TwoFactorEnabled", "UpdateUser", "UserName", "UserType" },
  247. values: new object[,]
  248. {
  249. { "ADMB3B92-2311-48F8-9DEC-F9FAEF1F21UA", 0, "7cc87689-9eab-4280-b8e3-1834080783a5", null, null, "a@b.com", true, "Zinab", false, false, "Elgendy", false, null, null, "A@B.COM", "ADMIN", "AQAAAAIAAYagAAAAEPg+ASbciPFxtyxQq8Wx5ilBUQ0RbAoITXXkOQm1PzC5BzySX0sn/wUmOjBKPDGV9w==", "1234567890", true, "49bb16c3-4704-4c60-908d-dc8506950acc", false, null, "Admin", 1 },
  250. { "AL5B3B92-2311-48F8-9DEC-F9FAEF1F21UB", 0, "4af7b4cf-802a-455b-b598-997e167745b3", null, null, "ali@b.com", true, "Ali", false, false, "Farok", false, null, null, "ALI@B.COM", "ALI", "AQAAAAIAAYagAAAAEI3QJkcZjCH4Y8Db4rEgL8Mmll5oCvYcWiXZjQSN9bGW4SMcjHe3ZPMnkN/l9DmJeQ==", "1234567890", true, "62549056-1b9d-46d4-84f8-adea3e4d8b68", false, null, "ali", 1 }
  251. });
  252. migrationBuilder.InsertData(
  253. table: "AspNetUserRoles",
  254. columns: new[] { "RoleId", "UserId" },
  255. values: new object[,]
  256. {
  257. { "AD5B3B92-2311-48F8-9DEC-F9FAEF1F211A", "ADMB3B92-2311-48F8-9DEC-F9FAEF1F21UA" },
  258. { "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", "AL5B3B92-2311-48F8-9DEC-F9FAEF1F21UB" }
  259. });
  260. migrationBuilder.CreateIndex(
  261. name: "IX_ApplicationRoleApplicationUser_UsersId",
  262. table: "ApplicationRoleApplicationUser",
  263. column: "UsersId");
  264. migrationBuilder.CreateIndex(
  265. name: "IX_AspNetRoleClaims_RoleId",
  266. table: "AspNetRoleClaims",
  267. column: "RoleId");
  268. migrationBuilder.CreateIndex(
  269. name: "RoleNameIndex",
  270. table: "AspNetRoles",
  271. column: "NormalizedName",
  272. unique: true,
  273. filter: "[NormalizedName] IS NOT NULL");
  274. migrationBuilder.CreateIndex(
  275. name: "IX_AspNetUserClaims_UserId",
  276. table: "AspNetUserClaims",
  277. column: "UserId");
  278. migrationBuilder.CreateIndex(
  279. name: "IX_AspNetUserLogins_UserId",
  280. table: "AspNetUserLogins",
  281. column: "UserId");
  282. migrationBuilder.CreateIndex(
  283. name: "IX_AspNetUserRoles_RoleId",
  284. table: "AspNetUserRoles",
  285. column: "RoleId");
  286. migrationBuilder.CreateIndex(
  287. name: "EmailIndex",
  288. table: "AspNetUsers",
  289. column: "NormalizedEmail");
  290. migrationBuilder.CreateIndex(
  291. name: "IX_AspNetUsers_ManagerId",
  292. table: "AspNetUsers",
  293. column: "ManagerId");
  294. migrationBuilder.CreateIndex(
  295. name: "UserNameIndex",
  296. table: "AspNetUsers",
  297. column: "NormalizedUserName",
  298. unique: true,
  299. filter: "[NormalizedUserName] IS NOT NULL");
  300. migrationBuilder.CreateIndex(
  301. name: "IX_RolePermissions_PermissionId",
  302. table: "RolePermissions",
  303. column: "PermissionId");
  304. migrationBuilder.CreateIndex(
  305. name: "IX_RolePermissions_RoleId",
  306. table: "RolePermissions",
  307. column: "RoleId");
  308. }
  309. /// <inheritdoc />
  310. protected override void Down(MigrationBuilder migrationBuilder)
  311. {
  312. migrationBuilder.DropTable(
  313. name: "ApplicationRoleApplicationUser");
  314. migrationBuilder.DropTable(
  315. name: "AspNetRoleClaims");
  316. migrationBuilder.DropTable(
  317. name: "AspNetUserClaims");
  318. migrationBuilder.DropTable(
  319. name: "AspNetUserLogins");
  320. migrationBuilder.DropTable(
  321. name: "AspNetUserRoles");
  322. migrationBuilder.DropTable(
  323. name: "AspNetUserTokens");
  324. migrationBuilder.DropTable(
  325. name: "RolePermissions");
  326. migrationBuilder.DropTable(
  327. name: "AspNetUsers");
  328. migrationBuilder.DropTable(
  329. name: "AspNetRoles");
  330. migrationBuilder.DropTable(
  331. name: "Permissions");
  332. }
  333. }
  334. }