Files
tbd-station-14/Content.Server.Database/Migrations/Postgres/20211120202701_AdminLogs.cs
Javier Guardia Fernández 319aec109d Admin logs (#5419)
* Add admin logging, models, migrations

* Add logging damage changes

* Add Log admin flag, LogFilter, Logs admin menu tab, message
Refactor admin logging API

* Change admin log get method names

* Fix the name again

* Minute amount of reorganization

* Reset Postgres db snapshot

* Reset Sqlite db snapshot

* Make AdminLog have a composite primary key of round, id

* Minute cleanup

* Change admin system to do a type check instead of index check

* Make admin logs use C# 10 interpolated string handlers

* Implement UI on its own window
Custom controls
Searching
Add admin log converters

* Implement limits into the query

* Change logs to be put into an OutputPanel instead for text wrapping

* Add log <-> player m2m relationship back

* UI improvements, make text wrap, add separators

* Remove entity prefix from damaged log

* Add explicit m2m model, fix any players filter

* Add debug command to test bulk adding logs

* Admin logs now just kinda go

* Add histogram for database update time

* Make admin log system update run every 5 seconds

* Add a cap to the log queue and a metric for how many times it has been reached

* Add metric for logs sent in a round

* Make cvars out of admin logs queue send delay and cap

* Merge fixes

* Reset some changes

* Add test for adding and getting a single log

* Add tests for bulk adding logs

* Add test for querying logs

* Add CallerArgumentExpression to LogStringHandler methods and test

* Improve UI, fix SQLite, add searching by round

* Add entities to admin logs

* Move distinct after orderby

* Add migrations

* ef core eat my ass

* Add cvar for client logs batch size

* Sort logs from newest to oldest by default

* Merge fixes

* Reorganize tests and add one for date ordering

* Add note to log types to not change their numeric values

* Add impacts to logs, better UI filtering

* Make log add callable from shared for convenience

* Get current round id directly from game ticker

* Revert namespace change for DamageableSystem
2021-11-22 18:49:26 +01:00

172 lines
7.3 KiB
C#

using System;
using System.Text.Json;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Content.Server.Database.Migrations.Postgres
{
public partial class AdminLogs : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddUniqueConstraint(
name: "ak_player_user_id",
table: "player",
column: "user_id");
migrationBuilder.CreateTable(
name: "round",
columns: table => new
{
round_id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
},
constraints: table =>
{
table.PrimaryKey("PK_round", x => x.round_id);
});
migrationBuilder.CreateTable(
name: "admin_log",
columns: table => new
{
admin_log_id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
round_id = table.Column<int>(type: "integer", nullable: false),
type = table.Column<int>(type: "integer", nullable: false),
date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
message = table.Column<string>(type: "text", nullable: false),
json = table.Column<JsonDocument>(type: "jsonb", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_admin_log", x => new { x.admin_log_id, x.round_id });
table.ForeignKey(
name: "FK_admin_log_round_round_id",
column: x => x.round_id,
principalTable: "round",
principalColumn: "round_id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "player_round",
columns: table => new
{
players_id = table.Column<int>(type: "integer", nullable: false),
rounds_id = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_player_round", x => new { x.players_id, x.rounds_id });
table.ForeignKey(
name: "FK_player_round_player_players_id",
column: x => x.players_id,
principalTable: "player",
principalColumn: "player_id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_player_round_round_rounds_id",
column: x => x.rounds_id,
principalTable: "round",
principalColumn: "round_id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "admin_log_entity",
columns: table => new
{
uid = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
name = table.Column<string>(type: "text", nullable: true),
admin_log_id = table.Column<int>(type: "integer", nullable: true),
admin_log_round_id = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_admin_log_entity", x => x.uid);
table.ForeignKey(
name: "FK_admin_log_entity_admin_log_admin_log_id_admin_log_round_id",
columns: x => new { x.admin_log_id, x.admin_log_round_id },
principalTable: "admin_log",
principalColumns: new[] { "admin_log_id", "round_id" });
});
migrationBuilder.CreateTable(
name: "admin_log_player",
columns: table => new
{
player_user_id = table.Column<Guid>(type: "uuid", nullable: false),
log_id = table.Column<int>(type: "integer", nullable: false),
round_id = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_admin_log_player", x => new { x.player_user_id, x.log_id, x.round_id });
table.ForeignKey(
name: "FK_admin_log_player_admin_log_log_id_round_id",
columns: x => new { x.log_id, x.round_id },
principalTable: "admin_log",
principalColumns: new[] { "admin_log_id", "round_id" },
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_admin_log_player_player_player_user_id",
column: x => x.player_user_id,
principalTable: "player",
principalColumn: "user_id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_admin_log_round_id",
table: "admin_log",
column: "round_id");
migrationBuilder.CreateIndex(
name: "IX_admin_log_type",
table: "admin_log",
column: "type");
migrationBuilder.CreateIndex(
name: "IX_admin_log_entity_admin_log_id_admin_log_round_id",
table: "admin_log_entity",
columns: new[] { "admin_log_id", "admin_log_round_id" });
migrationBuilder.CreateIndex(
name: "IX_admin_log_player_log_id_round_id",
table: "admin_log_player",
columns: new[] { "log_id", "round_id" });
migrationBuilder.CreateIndex(
name: "IX_player_round_rounds_id",
table: "player_round",
column: "rounds_id");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "admin_log_entity");
migrationBuilder.DropTable(
name: "admin_log_player");
migrationBuilder.DropTable(
name: "player_round");
migrationBuilder.DropTable(
name: "admin_log");
migrationBuilder.DropTable(
name: "round");
migrationBuilder.DropUniqueConstraint(
name: "ak_player_user_id",
table: "player");
}
}
}