Store round start date in the database (#21153)

This commit is contained in:
DrSmugleaf
2023-10-22 21:01:48 -07:00
committed by GitHub
parent 190b1f61f2
commit 43d5c00648
8 changed files with 3584 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,39 @@
#nullable disable
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Content.Server.Database.Migrations.Postgres
{
/// <inheritdoc />
public partial class RoundStartDate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "start_date",
table: "round",
type: "timestamp with time zone",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
migrationBuilder.CreateIndex(
name: "IX_round_start_date",
table: "round",
column: "start_date");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_round_start_date",
table: "round");
migrationBuilder.DropColumn(
name: "start_date",
table: "round");
}
}
}

View File

@@ -856,12 +856,20 @@ namespace Content.Server.Database.Migrations.Postgres
.HasColumnType("integer")
.HasColumnName("server_id");
b.Property<DateTime>("StartDate")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValue(new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified))
.HasColumnName("start_date");
b.HasKey("Id")
.HasName("PK_round");
b.HasIndex("ServerId")
.HasDatabaseName("IX_round_server_id");
b.HasIndex("StartDate");
b.ToTable("round", (string)null);
});

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,39 @@
#nullable disable
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Content.Server.Database.Migrations.Sqlite
{
/// <inheritdoc />
public partial class RoundStartDate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "start_date",
table: "round",
type: "TEXT",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
migrationBuilder.CreateIndex(
name: "IX_round_start_date",
table: "round",
column: "start_date");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_round_start_date",
table: "round");
migrationBuilder.DropColumn(
name: "start_date",
table: "round");
}
}
}

View File

@@ -806,12 +806,20 @@ namespace Content.Server.Database.Migrations.Sqlite
.HasColumnType("INTEGER")
.HasColumnName("server_id");
b.Property<DateTime>("StartDate")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT")
.HasDefaultValue(new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified))
.HasColumnName("start_date");
b.HasKey("Id")
.HasName("PK_round");
b.HasIndex("ServerId")
.HasDatabaseName("IX_round_server_id");
b.HasIndex("StartDate");
b.ToTable("round", (string)null);
});

View File

@@ -111,6 +111,13 @@ namespace Content.Server.Database
.HasForeignKey(player => player.PlayerUserId)
.HasPrincipalKey(player => player.UserId);
modelBuilder.Entity<Round>()
.HasIndex(round => round.StartDate);
modelBuilder.Entity<Round>()
.Property(round => round.StartDate)
.HasDefaultValue(default(DateTime));
modelBuilder.Entity<AdminLogPlayer>()
.HasKey(logPlayer => new {logPlayer.PlayerUserId, logPlayer.LogId, logPlayer.RoundId});
@@ -468,6 +475,8 @@ namespace Content.Server.Database
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public DateTime StartDate { get; set; }
public List<Player> Players { get; set; } = default!;
public List<AdminLog> AdminLogs { get; set; } = default!;

View File

@@ -677,6 +677,7 @@ namespace Content.Server.Database
var round = new Round
{
StartDate = DateTime.UtcNow,
Players = players,
ServerId = server.Id
};