-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
700 additions
and
27 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -405,4 +405,7 @@ Plugins/ | |
Canvas/ | ||
Zones/ | ||
|
||
!WFDS.Server/Pages/Canvas/ | ||
!WFDS.Server/Pages/Canvas/ | ||
|
||
data.db | ||
data.db-* |
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,18 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using WFDS.Database.DbSet; | ||
|
||
namespace WFDS.Database; | ||
|
||
public class DataDbContext(DbContextOptions<DataDbContext> options) : DbContext(options) | ||
{ | ||
public DbSet<Player> Players { get; set; } | ||
public DbSet<BannedPlayer> BannedPlayers { get; set; } | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.Entity<Player>().ToTable("players"); | ||
modelBuilder.Entity<BannedPlayer>().ToTable("banned_players"); | ||
|
||
base.OnModelCreating(modelBuilder); | ||
} | ||
} |
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,15 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Design; | ||
|
||
namespace WFDS.Database; | ||
|
||
public class DataDbContextFactory : IDesignTimeDbContextFactory<DataDbContext> | ||
{ | ||
public DataDbContext CreateDbContext(string[] args) | ||
{ | ||
var optionsBuilder = new DbContextOptionsBuilder<DataDbContext>(); | ||
optionsBuilder.UseSqlite("Data Source=./data.db;Cache=Shared"); | ||
|
||
return new DataDbContext(optionsBuilder.Options); | ||
} | ||
} |
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,23 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace WFDS.Database.DbSet; | ||
|
||
[Index(nameof(SteamId), IsUnique = true)] | ||
public class BannedPlayer | ||
{ | ||
[Key] | ||
[Column("id")] | ||
public long Id { get; init; } | ||
|
||
[Column("steam_id")] | ||
public ulong SteamId { get; init; } | ||
|
||
[MaxLength(32)] | ||
[Column("display_name")] | ||
public string DisplayName { get; set; } = string.Empty; | ||
|
||
[Column("banned_at")] | ||
public DateTime BannedAt { get; set; } = DateTime.UtcNow; | ||
} |
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,25 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace WFDS.Database.DbSet; | ||
|
||
[Index(nameof(SteamId), IsUnique = true)] | ||
public class Player | ||
{ | ||
[Key] | ||
[Column("id")] | ||
public long Id { get; init; } | ||
[Column("steam_id")] | ||
public ulong SteamId { get; init; } | ||
|
||
[MaxLength(32)] | ||
[Column("display_name")] | ||
public string DisplayName { get; set; } = string.Empty; | ||
[Column("last_joined_at")] | ||
public DateTime LastJoinedAt { get; set; } = DateTime.UtcNow; | ||
[Column("created_at")] | ||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow; | ||
[Column("updated_at")] | ||
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow; | ||
} |
81 changes: 81 additions & 0 deletions
81
WFDS.Database/Migrations/20241210075353_Initial.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,69 @@ | ||
using System; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
#nullable disable | ||
|
||
namespace WFDS.Database.Migrations | ||
{ | ||
/// <inheritdoc /> | ||
public partial class Initial : Migration | ||
{ | ||
/// <inheritdoc /> | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.CreateTable( | ||
name: "banned_players", | ||
columns: table => new | ||
{ | ||
Id = table.Column<long>(type: "INTEGER", nullable: false) | ||
.Annotation("Sqlite:Autoincrement", true), | ||
SteamId = table.Column<ulong>(type: "INTEGER", nullable: false), | ||
DisplayName = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false), | ||
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_banned_players", x => x.Id); | ||
}); | ||
|
||
migrationBuilder.CreateTable( | ||
name: "players", | ||
columns: table => new | ||
{ | ||
Id = table.Column<long>(type: "INTEGER", nullable: false) | ||
.Annotation("Sqlite:Autoincrement", true), | ||
SteamId = table.Column<ulong>(type: "INTEGER", nullable: false), | ||
DisplayName = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false), | ||
LastJoinedAt = table.Column<DateTime>(type: "TEXT", nullable: false), | ||
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false), | ||
UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_players", x => x.Id); | ||
}); | ||
|
||
migrationBuilder.CreateIndex( | ||
name: "IX_banned_players_SteamId", | ||
table: "banned_players", | ||
column: "SteamId", | ||
unique: true); | ||
|
||
migrationBuilder.CreateIndex( | ||
name: "IX_players_SteamId", | ||
table: "players", | ||
column: "SteamId", | ||
unique: true); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropTable( | ||
name: "banned_players"); | ||
|
||
migrationBuilder.DropTable( | ||
name: "players"); | ||
} | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
WFDS.Database/Migrations/20241210075705_ChangeColumnNameAndUpdateBannedPlayers.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.