1
0

20211120202701_AdminLogs.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using System;
  2. using System.Text.Json;
  3. using Microsoft.EntityFrameworkCore.Migrations;
  4. using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
  5. #nullable disable
  6. namespace Content.Server.Database.Migrations.Postgres
  7. {
  8. public partial class AdminLogs : Migration
  9. {
  10. protected override void Up(MigrationBuilder migrationBuilder)
  11. {
  12. migrationBuilder.AddUniqueConstraint(
  13. name: "ak_player_user_id",
  14. table: "player",
  15. column: "user_id");
  16. migrationBuilder.CreateTable(
  17. name: "round",
  18. columns: table => new
  19. {
  20. round_id = table.Column<int>(type: "integer", nullable: false)
  21. .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
  22. },
  23. constraints: table =>
  24. {
  25. table.PrimaryKey("PK_round", x => x.round_id);
  26. });
  27. migrationBuilder.CreateTable(
  28. name: "admin_log",
  29. columns: table => new
  30. {
  31. admin_log_id = table.Column<int>(type: "integer", nullable: false)
  32. .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
  33. round_id = table.Column<int>(type: "integer", nullable: false),
  34. type = table.Column<int>(type: "integer", nullable: false),
  35. date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
  36. message = table.Column<string>(type: "text", nullable: false),
  37. json = table.Column<JsonDocument>(type: "jsonb", nullable: false)
  38. },
  39. constraints: table =>
  40. {
  41. table.PrimaryKey("PK_admin_log", x => new { x.admin_log_id, x.round_id });
  42. table.ForeignKey(
  43. name: "FK_admin_log_round_round_id",
  44. column: x => x.round_id,
  45. principalTable: "round",
  46. principalColumn: "round_id",
  47. onDelete: ReferentialAction.Cascade);
  48. });
  49. migrationBuilder.CreateTable(
  50. name: "player_round",
  51. columns: table => new
  52. {
  53. players_id = table.Column<int>(type: "integer", nullable: false),
  54. rounds_id = table.Column<int>(type: "integer", nullable: false)
  55. },
  56. constraints: table =>
  57. {
  58. table.PrimaryKey("PK_player_round", x => new { x.players_id, x.rounds_id });
  59. table.ForeignKey(
  60. name: "FK_player_round_player_players_id",
  61. column: x => x.players_id,
  62. principalTable: "player",
  63. principalColumn: "player_id",
  64. onDelete: ReferentialAction.Cascade);
  65. table.ForeignKey(
  66. name: "FK_player_round_round_rounds_id",
  67. column: x => x.rounds_id,
  68. principalTable: "round",
  69. principalColumn: "round_id",
  70. onDelete: ReferentialAction.Cascade);
  71. });
  72. migrationBuilder.CreateTable(
  73. name: "admin_log_entity",
  74. columns: table => new
  75. {
  76. uid = table.Column<int>(type: "integer", nullable: false)
  77. .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
  78. name = table.Column<string>(type: "text", nullable: true),
  79. admin_log_id = table.Column<int>(type: "integer", nullable: true),
  80. admin_log_round_id = table.Column<int>(type: "integer", nullable: true)
  81. },
  82. constraints: table =>
  83. {
  84. table.PrimaryKey("PK_admin_log_entity", x => x.uid);
  85. table.ForeignKey(
  86. name: "FK_admin_log_entity_admin_log_admin_log_id_admin_log_round_id",
  87. columns: x => new { x.admin_log_id, x.admin_log_round_id },
  88. principalTable: "admin_log",
  89. principalColumns: new[] { "admin_log_id", "round_id" });
  90. });
  91. migrationBuilder.CreateTable(
  92. name: "admin_log_player",
  93. columns: table => new
  94. {
  95. player_user_id = table.Column<Guid>(type: "uuid", nullable: false),
  96. log_id = table.Column<int>(type: "integer", nullable: false),
  97. round_id = table.Column<int>(type: "integer", nullable: false)
  98. },
  99. constraints: table =>
  100. {
  101. table.PrimaryKey("PK_admin_log_player", x => new { x.player_user_id, x.log_id, x.round_id });
  102. table.ForeignKey(
  103. name: "FK_admin_log_player_admin_log_log_id_round_id",
  104. columns: x => new { x.log_id, x.round_id },
  105. principalTable: "admin_log",
  106. principalColumns: new[] { "admin_log_id", "round_id" },
  107. onDelete: ReferentialAction.Cascade);
  108. table.ForeignKey(
  109. name: "FK_admin_log_player_player_player_user_id",
  110. column: x => x.player_user_id,
  111. principalTable: "player",
  112. principalColumn: "user_id",
  113. onDelete: ReferentialAction.Cascade);
  114. });
  115. migrationBuilder.CreateIndex(
  116. name: "IX_admin_log_round_id",
  117. table: "admin_log",
  118. column: "round_id");
  119. migrationBuilder.CreateIndex(
  120. name: "IX_admin_log_type",
  121. table: "admin_log",
  122. column: "type");
  123. migrationBuilder.CreateIndex(
  124. name: "IX_admin_log_entity_admin_log_id_admin_log_round_id",
  125. table: "admin_log_entity",
  126. columns: new[] { "admin_log_id", "admin_log_round_id" });
  127. migrationBuilder.CreateIndex(
  128. name: "IX_admin_log_player_log_id_round_id",
  129. table: "admin_log_player",
  130. columns: new[] { "log_id", "round_id" });
  131. migrationBuilder.CreateIndex(
  132. name: "IX_player_round_rounds_id",
  133. table: "player_round",
  134. column: "rounds_id");
  135. }
  136. protected override void Down(MigrationBuilder migrationBuilder)
  137. {
  138. migrationBuilder.DropTable(
  139. name: "admin_log_entity");
  140. migrationBuilder.DropTable(
  141. name: "admin_log_player");
  142. migrationBuilder.DropTable(
  143. name: "player_round");
  144. migrationBuilder.DropTable(
  145. name: "admin_log");
  146. migrationBuilder.DropTable(
  147. name: "round");
  148. migrationBuilder.DropUniqueConstraint(
  149. name: "ak_player_user_id",
  150. table: "player");
  151. }
  152. }
  153. }