Skip to content

Commit f0e934d

Browse files
committed
feat: add 15 substitute players to database seed data
Added GetSubstitutes() and GetSubstitutesWithId() methods to PlayerData utility, following the same pattern as Starting 11. Created SeedSubstitutes migration to seed 15 substitute players with squad numbers 1, 2, 4, 5, 6, 8, 12, 14, 15, 16, 17, 18, 21, 22, 25. Database now contains 26 total players: 11 starting (Starting11=true) and 15 substitutes (Starting11=false). All squad numbers verified conflict-free. Additional improvements: - Fixed run-migrations-and-copy-database.sh to use storage/ path - Updated copilot-instructions.md with correct database paths - Removed obsolete Data/players-sqlite3.db file Closes #332
1 parent cff7431 commit f0e934d

7 files changed

Lines changed: 551 additions & 7 deletions

File tree

.github/copilot-instructions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ dotnet ef database update --project src/Dotnet.Samples.AspNetCore.WebApi
297297
**Important**: The `run-migrations-and-copy-database.sh` script:
298298
- Resets the placeholder database file
299299
- Runs all migrations
300-
- Copies the generated database from `bin/Debug/net8.0/Data/` to `Data/`
300+
- Copies the generated database from `bin/Debug/net8.0/storage/` to `storage/`
301301
- Requires `dotnet ef` CLI tool installed globally
302302

303303
### Docker Operations
@@ -325,9 +325,9 @@ docker compose down -v
325325
## 🚨 Common Issues & Workarounds
326326

327327
### Database Path Issues
328-
- **SQLite database location**: `storage/players-sqlite3.db` relative to binary output
329-
- **Container storage**: `/storage/players-sqlite3.db` (mounted volume)
330-
- **Environment variable**: `STORAGE_PATH` can override the default path in containers
328+
- **Development**: `storage/players-sqlite3.db` (source, copied to `bin/Debug/net8.0/storage/` during build)
329+
- **Container**: Pre-seeded database copied from image `/app/hold/` to volume `/storage/` on first run
330+
- **Runtime**: Application uses `AppContext.BaseDirectory/storage/players-sqlite3.db`
331331

332332
### Validation Patterns
333333
- **FluentValidation** runs in the validator class for input format/structure

scripts/run-migrations-and-copy-database.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ DATA_FILE="players-sqlite3.db"
55
PROJECT_ROOT_PATH="src/Dotnet.Samples.AspNetCore.WebApi"
66
PROJECT_BASE_PATH="$PROJECT_ROOT_PATH/bin/Debug/net8.0"
77

8-
SOURCE_FILE_PATH="$PROJECT_BASE_PATH/Data/$DATA_FILE"
9-
TARGET_FILE_PATH="$PROJECT_ROOT_PATH/Data/$DATA_FILE"
8+
SOURCE_FILE_PATH="$PROJECT_BASE_PATH/storage/$DATA_FILE"
9+
TARGET_FILE_PATH="$PROJECT_ROOT_PATH/storage/$DATA_FILE"
1010

1111
log() {
1212
local emoji=$1

src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20251221220614_SeedSubstitutes.Designer.cs

Lines changed: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Dotnet.Samples.AspNetCore.WebApi.Utilities;
2+
using Microsoft.EntityFrameworkCore.Migrations;
3+
4+
#nullable disable
5+
6+
namespace Dotnet.Samples.AspNetCore.WebApi.Migrations
7+
{
8+
/// <inheritdoc />
9+
public partial class SeedSubstitutes : Migration
10+
{
11+
/// <inheritdoc />
12+
protected override void Up(MigrationBuilder migrationBuilder)
13+
{
14+
var substitutes = PlayerData.GetSubstitutesWithId();
15+
16+
foreach (var player in substitutes)
17+
{
18+
migrationBuilder.InsertData(
19+
table: "Players",
20+
columns:
21+
[
22+
"Id",
23+
"FirstName",
24+
"MiddleName",
25+
"LastName",
26+
"DateOfBirth",
27+
"SquadNumber",
28+
"Position",
29+
"AbbrPosition",
30+
"Team",
31+
"League",
32+
"Starting11"
33+
],
34+
values: new object[]
35+
{
36+
player.Id,
37+
player.FirstName,
38+
player.MiddleName,
39+
player.LastName,
40+
player.DateOfBirth,
41+
player.SquadNumber,
42+
player.Position,
43+
player.AbbrPosition,
44+
player.Team,
45+
player.League,
46+
player.Starting11
47+
}
48+
);
49+
}
50+
}
51+
52+
/// <inheritdoc />
53+
protected override void Down(MigrationBuilder migrationBuilder)
54+
{
55+
var substitutes = PlayerData.GetSubstitutesWithId();
56+
foreach (var player in substitutes)
57+
{
58+
migrationBuilder.DeleteData(table: "Players", keyColumn: "Id", keyValue: player.Id);
59+
}
60+
}
61+
}
62+
}

src/Dotnet.Samples.AspNetCore.WebApi/Migrations/PlayerDbContextModelSnapshot.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ partial class PlayerDbContextModelSnapshot : ModelSnapshot
1515
protected override void BuildModel(ModelBuilder modelBuilder)
1616
{
1717
#pragma warning disable 612, 618
18-
modelBuilder.HasAnnotation("ProductVersion", "9.0.4");
18+
modelBuilder.HasAnnotation("ProductVersion", "9.0.11");
1919

2020
modelBuilder.Entity("Dotnet.Samples.AspNetCore.WebApi.Models.Player", b =>
2121
{

0 commit comments

Comments
 (0)