-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* DB leaderboards initial commit * Clarify message * uuuhhh AMONG US
- Loading branch information
Showing
9 changed files
with
1,177 additions
and
84 deletions.
There are no files selected for viewing
718 changes: 718 additions & 0 deletions
718
ReplayBrowser/Data/Migrations/20241111013501_DbLeaderboards.Designer.cs
Large diffs are not rendered by default.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
ReplayBrowser/Data/Migrations/20241111013501_DbLeaderboards.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; | ||
|
||
#nullable disable | ||
|
||
namespace Server.Migrations | ||
{ | ||
/// <inheritdoc /> | ||
public partial class DbLeaderboards : Migration | ||
{ | ||
/// <inheritdoc /> | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.CreateTable( | ||
name: "LeaderboardDefinitions", | ||
columns: table => new | ||
{ | ||
Name = table.Column<string>(type: "text", nullable: false), | ||
TrackedData = table.Column<string>(type: "text", nullable: false), | ||
ExtraInfo = table.Column<string>(type: "text", nullable: true), | ||
NameColumn = table.Column<string>(type: "text", nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_LeaderboardDefinitions", x => x.Name); | ||
}); | ||
|
||
migrationBuilder.CreateTable( | ||
name: "Leaderboards", | ||
columns: table => new | ||
{ | ||
Id = table.Column<int>(type: "integer", nullable: false) | ||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), | ||
Servers = table.Column<List<string>>(type: "text[]", nullable: false), | ||
Count = table.Column<int>(type: "integer", nullable: false), | ||
Position = table.Column<int>(type: "integer", nullable: false), | ||
PlayerGuid = table.Column<Guid>(type: "uuid", nullable: true), | ||
Username = table.Column<string>(type: "text", nullable: false), | ||
LeaderboardDefinitionName = table.Column<string>(type: "text", nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_Leaderboards", x => x.Id); | ||
table.ForeignKey( | ||
name: "FK_Leaderboards_LeaderboardDefinitions_LeaderboardDefinitionNa~", | ||
column: x => x.LeaderboardDefinitionName, | ||
principalTable: "LeaderboardDefinitions", | ||
principalColumn: "Name", | ||
onDelete: ReferentialAction.Cascade); | ||
}); | ||
|
||
migrationBuilder.CreateIndex( | ||
name: "IX_Leaderboards_LeaderboardDefinitionName", | ||
table: "Leaderboards", | ||
column: "LeaderboardDefinitionName"); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropTable( | ||
name: "Leaderboards"); | ||
|
||
migrationBuilder.DropTable( | ||
name: "LeaderboardDefinitions"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace ReplayBrowser.Data.Models; | ||
|
||
public class LeaderboardDefinition : IEntityTypeConfiguration<LeaderboardDefinition> | ||
{ | ||
public required string Name { get; set; } | ||
|
||
/// <summary> | ||
/// The text that will appear for the "Count" column. | ||
/// </summary> | ||
public required string TrackedData { get; set; } | ||
|
||
/// <summary> | ||
/// Will be displayed in a small font below the name. | ||
/// </summary> | ||
public string? ExtraInfo { get; set; } | ||
public string NameColumn { get; set; } = "Player Name"; | ||
|
||
public void Configure(EntityTypeBuilder<LeaderboardDefinition> builder) | ||
{ | ||
builder.HasKey(x => x.Name); | ||
builder.Property(x => x.TrackedData).IsRequired(); | ||
builder.Property(x => x.NameColumn).IsRequired(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace ReplayBrowser.Data.Models; | ||
|
||
public class LeaderboardPosition : IEntityTypeConfiguration<LeaderboardPosition> | ||
{ | ||
public int Id { get; set; } | ||
|
||
/// <summary> | ||
/// The servers that this position is for. | ||
/// </summary> | ||
public required List<string> Servers { get; set; } = null!; | ||
|
||
/// <summary> | ||
/// The number next to the position. For example "most times played" would be a count of how many times the player has played. | ||
/// </summary> | ||
public required int Count { get; set; } | ||
|
||
/// <summary> | ||
/// The position of the player in the leaderboard. | ||
/// </summary> | ||
public int Position { get; set; } | ||
|
||
/// <summary> | ||
/// The GUID of the player. If null, position is not for a player, but rather a general statistic. | ||
/// </summary> | ||
public Guid? PlayerGuid { get; set; } | ||
|
||
/// <summary> | ||
/// The display value of the player or statistic. | ||
/// </summary> | ||
public string Username { get; set; } = null!; | ||
|
||
|
||
public string LeaderboardDefinitionName { get; set; } = null!; | ||
public LeaderboardDefinition LeaderboardDefinition { get; set; } = null!; | ||
|
||
|
||
|
||
public void Configure(EntityTypeBuilder<LeaderboardPosition> builder) | ||
{ | ||
builder.HasOne(lp => lp.LeaderboardDefinition) | ||
.WithMany() | ||
.HasForeignKey(lp => lp.LeaderboardDefinitionName); | ||
|
||
builder.HasKey(x => x.Id); | ||
builder.Property(x => x.Servers).IsRequired(); | ||
builder.Property(x => x.Count).IsRequired(); | ||
builder.Property(x => x.Position).IsRequired(); | ||
builder.Property(x => x.PlayerGuid).IsRequired(false); | ||
builder.Property(x => x.Username).IsRequired(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.