20241010095341_UpdateUsersAndLoginedTables.cs 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using Microsoft.EntityFrameworkCore.Migrations;
  3. using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
  4. #nullable disable
  5. namespace AvaloniaPractic.Migrations
  6. {
  7. /// <inheritdoc />
  8. public partial class UpdateUsersAndLoginedTables : Migration
  9. {
  10. /// <inheritdoc />
  11. protected override void Up(MigrationBuilder migrationBuilder)
  12. {
  13. migrationBuilder.CreateTable(
  14. name: "Roles",
  15. columns: table => new
  16. {
  17. Id = table.Column<int>(type: "integer", nullable: false)
  18. .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
  19. Name = table.Column<string>(type: "text", nullable: false)
  20. },
  21. constraints: table =>
  22. {
  23. table.PrimaryKey("PK_Roles", x => x.Id);
  24. });
  25. migrationBuilder.CreateTable(
  26. name: "users",
  27. columns: table => new
  28. {
  29. id = table.Column<int>(type: "integer", nullable: false)
  30. .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
  31. username = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
  32. email = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
  33. createdat = table.Column<DateTime>(type: "timestamp without time zone", nullable: true, defaultValueSql: "CURRENT_TIMESTAMP")
  34. },
  35. constraints: table =>
  36. {
  37. table.PrimaryKey("users_pkey", x => x.id);
  38. });
  39. migrationBuilder.CreateTable(
  40. name: "Logins",
  41. columns: table => new
  42. {
  43. Id = table.Column<int>(type: "integer", nullable: false)
  44. .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
  45. Login = table.Column<string>(type: "text", nullable: false),
  46. Password = table.Column<string>(type: "text", nullable: false),
  47. RoleId = table.Column<int>(type: "integer", nullable: false),
  48. UserId = table.Column<int>(type: "integer", nullable: false)
  49. },
  50. constraints: table =>
  51. {
  52. table.PrimaryKey("PK_Logins", x => x.Id);
  53. table.ForeignKey(
  54. name: "FK_Logins_Roles_RoleId",
  55. column: x => x.RoleId,
  56. principalTable: "Roles",
  57. principalColumn: "Id",
  58. onDelete: ReferentialAction.Cascade);
  59. table.ForeignKey(
  60. name: "FK_Logins_users_UserId",
  61. column: x => x.UserId,
  62. principalTable: "users",
  63. principalColumn: "id",
  64. onDelete: ReferentialAction.Cascade);
  65. });
  66. migrationBuilder.CreateIndex(
  67. name: "IX_Logins_RoleId",
  68. table: "Logins",
  69. column: "RoleId");
  70. migrationBuilder.CreateIndex(
  71. name: "IX_Logins_UserId",
  72. table: "Logins",
  73. column: "UserId");
  74. }
  75. /// <inheritdoc />
  76. protected override void Down(MigrationBuilder migrationBuilder)
  77. {
  78. migrationBuilder.DropTable(
  79. name: "Logins");
  80. migrationBuilder.DropTable(
  81. name: "Roles");
  82. migrationBuilder.DropTable(
  83. name: "users");
  84. }
  85. }
  86. }