20220127165122_UnifyMore.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using System;
  2. using Microsoft.EntityFrameworkCore.Migrations;
  3. #nullable disable
  4. namespace Content.Server.Database.Migrations.Sqlite
  5. {
  6. public partial class UnifyMore : Migration
  7. {
  8. protected override void Up(MigrationBuilder migrationBuilder)
  9. {
  10. migrationBuilder.CreateTable(
  11. name: "server_ban",
  12. columns: table => new
  13. {
  14. server_ban_id = table.Column<int>(type: "INTEGER", nullable: false)
  15. .Annotation("Sqlite:Autoincrement", true),
  16. user_id = table.Column<Guid>(type: "TEXT", nullable: true),
  17. address = table.Column<string>(type: "TEXT", nullable: true),
  18. hwid = table.Column<byte[]>(type: "BLOB", nullable: true),
  19. ban_time = table.Column<DateTime>(type: "TEXT", nullable: false),
  20. expiration_time = table.Column<DateTime>(type: "TEXT", nullable: true),
  21. reason = table.Column<string>(type: "TEXT", nullable: false),
  22. banning_admin = table.Column<Guid>(type: "TEXT", nullable: true)
  23. },
  24. constraints: table =>
  25. {
  26. table.PrimaryKey("PK_server_ban", x => x.server_ban_id);
  27. table.CheckConstraint("CK_server_ban_HaveEitherAddressOrUserIdOrHWId", "address IS NOT NULL OR user_id IS NOT NULL OR hwid IS NOT NULL");
  28. });
  29. migrationBuilder.CreateTable(
  30. name: "server_unban",
  31. columns: table => new
  32. {
  33. unban_id = table.Column<int>(type: "INTEGER", nullable: false)
  34. .Annotation("Sqlite:Autoincrement", true),
  35. ban_id = table.Column<int>(type: "INTEGER", nullable: false),
  36. unbanning_admin = table.Column<Guid>(type: "TEXT", nullable: true),
  37. unban_time = table.Column<DateTime>(type: "TEXT", nullable: false)
  38. },
  39. constraints: table =>
  40. {
  41. table.PrimaryKey("PK_server_unban", x => x.unban_id);
  42. table.ForeignKey(
  43. name: "FK_server_unban_server_ban_ban_id",
  44. column: x => x.ban_id,
  45. principalTable: "server_ban",
  46. principalColumn: "server_ban_id",
  47. onDelete: ReferentialAction.Cascade);
  48. });
  49. migrationBuilder.Sql(@"
  50. INSERT INTO server_ban (server_ban_id, user_id, address, hwid, ban_time, expiration_time, reason, banning_admin)
  51. SELECT ban_id, user_id, address, hwid, ban_time, expiration_time, reason, banning_admin
  52. FROM ban;");
  53. migrationBuilder.Sql("INSERT INTO server_unban SELECT * FROM unban;");
  54. migrationBuilder.CreateIndex(
  55. name: "IX_player_user_id",
  56. table: "player",
  57. column: "user_id",
  58. unique: true);
  59. migrationBuilder.CreateIndex(
  60. name: "IX_connection_log_user_id",
  61. table: "connection_log",
  62. column: "user_id");
  63. migrationBuilder.CreateIndex(
  64. name: "IX_server_ban_address",
  65. table: "server_ban",
  66. column: "address");
  67. migrationBuilder.CreateIndex(
  68. name: "IX_server_ban_user_id",
  69. table: "server_ban",
  70. column: "user_id");
  71. migrationBuilder.CreateIndex(
  72. name: "IX_server_unban_ban_id",
  73. table: "server_unban",
  74. column: "ban_id",
  75. unique: true);
  76. migrationBuilder.DropTable(
  77. name: "unban");
  78. migrationBuilder.DropTable(
  79. name: "ban");
  80. }
  81. protected override void Down(MigrationBuilder migrationBuilder)
  82. {
  83. migrationBuilder.DropIndex(
  84. name: "IX_player_user_id",
  85. table: "player");
  86. migrationBuilder.DropIndex(
  87. name: "IX_connection_log_user_id",
  88. table: "connection_log");
  89. migrationBuilder.CreateTable(
  90. name: "ban",
  91. columns: table => new
  92. {
  93. ban_id = table.Column<int>(type: "INTEGER", nullable: false)
  94. .Annotation("Sqlite:Autoincrement", true),
  95. address = table.Column<string>(type: "TEXT", nullable: true),
  96. ban_time = table.Column<DateTime>(type: "TEXT", nullable: false),
  97. banning_admin = table.Column<Guid>(type: "TEXT", nullable: true),
  98. expiration_time = table.Column<DateTime>(type: "TEXT", nullable: true),
  99. hwid = table.Column<byte[]>(type: "BLOB", nullable: true),
  100. reason = table.Column<string>(type: "TEXT", nullable: false),
  101. user_id = table.Column<Guid>(type: "TEXT", nullable: true)
  102. },
  103. constraints: table =>
  104. {
  105. table.PrimaryKey("PK_ban", x => x.ban_id);
  106. });
  107. migrationBuilder.CreateTable(
  108. name: "unban",
  109. columns: table => new
  110. {
  111. unban_id = table.Column<int>(type: "INTEGER", nullable: false)
  112. .Annotation("Sqlite:Autoincrement", true),
  113. ban_id = table.Column<int>(type: "INTEGER", nullable: false),
  114. unban_time = table.Column<DateTime>(type: "TEXT", nullable: false),
  115. unbanning_admin = table.Column<Guid>(type: "TEXT", nullable: true)
  116. },
  117. constraints: table =>
  118. {
  119. table.PrimaryKey("PK_unban", x => x.unban_id);
  120. table.ForeignKey(
  121. name: "FK_unban_ban_ban_id",
  122. column: x => x.ban_id,
  123. principalTable: "ban",
  124. principalColumn: "ban_id",
  125. onDelete: ReferentialAction.Cascade);
  126. });
  127. migrationBuilder.Sql(@"
  128. INSERT INTO ban (ban_id, user_id, address, hwid, ban_time, expiration_time, reason, banning_admin)
  129. SELECT server_ban_id, user_id, address, hwid, ban_time, expiration_time, reason, banning_admin
  130. FROM server_ban;");
  131. migrationBuilder.Sql(@"INSERT INTO unban SELECT * FROM server_unban;");
  132. migrationBuilder.DropTable(
  133. name: "server_unban");
  134. migrationBuilder.DropTable(
  135. name: "server_ban");
  136. migrationBuilder.CreateIndex(
  137. name: "IX_unban_ban_id",
  138. table: "unban",
  139. column: "ban_id",
  140. unique: true);
  141. }
  142. }
  143. }