diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 678aa72..6cd2cf1 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -34,8 +34,8 @@ src/Dotnet.Samples.AspNetCore.WebApi/ ├── Extensions/ — IServiceCollection extension methods (service registration) ├── Configurations/ — Options classes bound from appsettings.json ├── Middlewares/ — Custom ASP.NET Core middleware -├── Data/ — DbContext + DbInitializer (seed data) -└── Storage/ — SQLite database file (players.db) +├── Data/ — DbContext; seed data via HasData() in OnModelCreating +└── Storage/ — SQLite database file (created at runtime by MigrateAsync) test/Dotnet.Samples.AspNetCore.WebApi.Tests/ ├── Unit/ — Unit tests (controllers, services, validators) @@ -206,7 +206,7 @@ This project uses Spec-Driven Development (SDD): discuss in Plan mode first, cre **Add an endpoint**: Add DTO in `Models/` → update `PlayerMappingProfile` in `Mappings/` → add repository method(s) in `Repositories/` → add service method in `Services/` → add controller action in `Controllers/` → add/update validator rule set in `Validators/` → add tests in `test/.../Unit/` → run pre-commit checks. -**Modify schema**: Update `Player` entity → update DTOs → update AutoMapper profile → reset `Storage/players.db` → update tests → run `dotnet test`. +**Modify schema**: Update `Player` entity → update DTOs → update AutoMapper profile → update `HasData()` seed data in `OnModelCreating` if needed → run `dotnet ef migrations add ` → update tests → run `dotnet test`. ## Architecture Decision Records (ADRs) diff --git a/.gitignore b/.gitignore index 3dc861b..771f3ed 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ logs/ bin/ obj/ TestResults/ +storage/*.db .claude/settings.local.json diff --git a/.sonarcloud.properties b/.sonarcloud.properties index 3010202..334004f 100644 --- a/.sonarcloud.properties +++ b/.sonarcloud.properties @@ -7,8 +7,9 @@ # listed explicitly. # ============================================================================= -sonar.sources=src/ -sonar.tests=test/ +# NOTE: sonar.sources and sonar.tests are NOT supported by the Scanner for .NET +# and are silently ignored. The scanner auto-discovers sources and test projects +# from .csproj files. Do not add them back. sonar.sourceEncoding=UTF-8 # ============================================================================= @@ -16,14 +17,12 @@ sonar.sourceEncoding=UTF-8 # ============================================================================= sonar.exclusions=\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414191223_InitialCreate.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414191223_InitialCreate.Designer.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414195445_SeedStarting11.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414195445_SeedStarting11.Designer.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20251221220614_SeedSubstitutes.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20251221220614_SeedSubstitutes.Designer.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260329000000_NormalizePlayerDataset.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260329000000_NormalizePlayerDataset.Designer.cs,\ + src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141647_InitialCreate.cs,\ + src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141647_InitialCreate.Designer.cs,\ + src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141707_SeedStarting11.cs,\ + src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141707_SeedStarting11.Designer.cs,\ + src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141721_SeedSubstitutes.cs,\ + src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141721_SeedSubstitutes.Designer.cs,\ src/Dotnet.Samples.AspNetCore.WebApi/Migrations/PlayerDbContextModelSnapshot.cs # ============================================================================= @@ -41,14 +40,12 @@ sonar.coverage.exclusions=\ test/Dotnet.Samples.AspNetCore.WebApi.Tests/Utilities/PlayerMocks.cs,\ test/Dotnet.Samples.AspNetCore.WebApi.Tests/Utilities/PlayerStubs.cs,\ test/Dotnet.Samples.AspNetCore.WebApi.Tests/Usings.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414191223_InitialCreate.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414191223_InitialCreate.Designer.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414195445_SeedStarting11.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414195445_SeedStarting11.Designer.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20251221220614_SeedSubstitutes.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20251221220614_SeedSubstitutes.Designer.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260329000000_NormalizePlayerDataset.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260329000000_NormalizePlayerDataset.Designer.cs,\ + src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141647_InitialCreate.cs,\ + src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141647_InitialCreate.Designer.cs,\ + src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141707_SeedStarting11.cs,\ + src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141707_SeedStarting11.Designer.cs,\ + src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141721_SeedSubstitutes.cs,\ + src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141721_SeedSubstitutes.Designer.cs,\ src/Dotnet.Samples.AspNetCore.WebApi/Migrations/PlayerDbContextModelSnapshot.cs,\ src/Dotnet.Samples.AspNetCore.WebApi/Data/PlayerDbContext.cs,\ src/Dotnet.Samples.AspNetCore.WebApi/Program.cs @@ -59,7 +56,7 @@ sonar.coverage.exclusions=\ # listed explicitly. # # Migrations — EF Core migration files are intentionally repetitive -# (sequential InsertData/UpdateData/Sql calls). +# (sequential InsertData calls generated by EF Core tooling). # # PlayerDbContext.cs — scaffolded EF Core infrastructure. # @@ -73,14 +70,12 @@ sonar.coverage.exclusions=\ # ============================================================================= sonar.cpd.exclusions=\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414191223_InitialCreate.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414191223_InitialCreate.Designer.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414195445_SeedStarting11.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414195445_SeedStarting11.Designer.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20251221220614_SeedSubstitutes.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20251221220614_SeedSubstitutes.Designer.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260329000000_NormalizePlayerDataset.cs,\ - src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260329000000_NormalizePlayerDataset.Designer.cs,\ + src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141647_InitialCreate.cs,\ + src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141647_InitialCreate.Designer.cs,\ + src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141707_SeedStarting11.cs,\ + src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141707_SeedStarting11.Designer.cs,\ + src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141721_SeedSubstitutes.cs,\ + src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141721_SeedSubstitutes.Designer.cs,\ src/Dotnet.Samples.AspNetCore.WebApi/Migrations/PlayerDbContextModelSnapshot.cs,\ src/Dotnet.Samples.AspNetCore.WebApi/Data/PlayerDbContext.cs,\ src/Dotnet.Samples.AspNetCore.WebApi/Utilities/PlayerData.cs,\ diff --git a/CHANGELOG.md b/CHANGELOG.md index 1478f7d..777620c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,9 @@ This project uses famous football stadiums (A-Z) that hosted FIFA World Cup matc ### Changed +- Replace pre-seeded `storage/players-sqlite3.db` binary blob with EF Core `MigrateAsync()` at startup: schema and seed data are now applied automatically before the first request is served; `STORAGE_PATH` env var controls the database file path (Docker volume path in production, `AppContext.BaseDirectory/storage/` locally); the committed database file, `Dockerfile` db copy step, and `scripts/run-migrations-and-copy-database.sh` have been removed (#459) +- Recreate EF Core migrations using `HasData()` in `OnModelCreating`: three self-contained migrations (`InitialCreate` DDL, `SeedStarting11` DML, `SeedSubstitutes` DML) generated by EF Core with literal `InsertData` values — no migration calls application methods; `NormalizePlayerDataset` patch migration eliminated by folding corrections into seed data from the start (#459) +- Replace `DatabaseFakes.CreateTable()` (placeholder schema) and `DatabaseFakes.Seed()` (manual insert bypassing migrations) with `DatabaseFakes.MigrateAsync()`, which applies the full EF Core migration chain on in-memory SQLite (#459) - Switch runtime base image from `mcr.microsoft.com/dotnet/aspnet:10.0` (Debian) to `mcr.microsoft.com/dotnet/aspnet:10.0-alpine` (before: 113.4 MB → after: 73.9 MB compressed; measured via `docker manifest inspect` and diff --git a/Dockerfile b/Dockerfile index 2560490..4eeeb5b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,6 @@ WORKDIR /src COPY src/Dotnet.Samples.AspNetCore.WebApi/*.csproj ./Dotnet.Samples.AspNetCore.WebApi/ RUN dotnet restore ./Dotnet.Samples.AspNetCore.WebApi -# Copy source code and pre-seeded SQLite database COPY src/Dotnet.Samples.AspNetCore.WebApi/ ./Dotnet.Samples.AspNetCore.WebApi/ WORKDIR /src/Dotnet.Samples.AspNetCore.WebApi @@ -53,10 +52,6 @@ COPY --chmod=444 README.md ./ # Copy entrypoint and healthcheck scripts COPY --chmod=555 scripts/entrypoint.sh ./entrypoint.sh COPY --chmod=555 scripts/healthcheck.sh ./healthcheck.sh -# The 'hold' is our storage compartment within the image. Here, we copy a -# pre-seeded SQLite database file, which Compose will mount as a persistent -# 'storage' volume when the container starts up. -COPY --from=builder /src/Dotnet.Samples.AspNetCore.WebApi/storage/players-sqlite3.db ./hold/players-sqlite3.db # Add non-root user and make volume mount point writable RUN addgroup -S aspnetcore && \ diff --git a/README.md b/README.md index 5c22b1a..de7f0a4 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,7 @@ Before you begin, ensure you have the following installed: - .NET 10 SDK (LTS) or higher - Docker Desktop (optional, for containerized deployment) -- dotnet-ef CLI tool (for database migrations) +- dotnet-ef CLI tool (optional, for creating new migrations) ```bash dotnet tool install --global dotnet-ef @@ -206,7 +206,7 @@ docker compose build docker compose up ``` -> 💡 On first run, the container copies a pre-seeded SQLite database into a persistent volume. On subsequent runs, that volume is reused and the data is preserved. +> 💡 On first run, the app applies EF Core migrations and seeds the database automatically into a persistent volume. On subsequent runs, that volume is reused and the data is preserved. ### Stop the application @@ -216,7 +216,7 @@ docker compose down ### Reset the database -To remove the volume and reinitialize the database from the built-in seed file: +To remove the volume and let the app re-create and re-seed the database on next startup: ```bash docker compose down -v @@ -306,8 +306,7 @@ dotnet test --results-directory "coverage" --collect:"XPlat Code Coverage" --set | `dotnet test --collect:"XPlat Code Coverage"` | Run tests with coverage report | | `dotnet csharpier .` | Format source code | | `dotnet ef migrations add ` | Create a new migration | -| `dotnet ef database update` | Apply migrations | -| `./scripts/run-migrations-and-copy-database.sh` | Regenerate database with seed data | +| `dotnet ef database update` | Apply migrations manually | | `docker compose build` | Build Docker image | | `docker compose up` | Start Docker container | | `docker compose down` | Stop Docker container | diff --git a/adr/0003-use-sqlite-for-data-storage.md b/adr/0003-use-sqlite-for-data-storage.md index efcede7..8409b47 100644 --- a/adr/0003-use-sqlite-for-data-storage.md +++ b/adr/0003-use-sqlite-for-data-storage.md @@ -14,14 +14,15 @@ The cross-language comparison set (Go/Gin, Java/Spring Boot, Python/FastAPI, Rus ## Decision -We will use SQLite as the database engine, accessed through Entity Framework Core. The database file is stored at `storage/players-sqlite3.db` and is pre-seeded with sample data. Docker deployments mount the file into a named volume so data survives container restarts. +We will use SQLite as the database engine, accessed through Entity Framework Core. The database file is created at `storage/players-sqlite3.db` at runtime: EF Core applies pending migrations (schema + seed data via `HasData()`) automatically at startup via `MigrateAsync()` before the first request is served. Docker deployments mount the file into a named volume so data survives container restarts. ## Consequences ### Positive + - Zero-config: no server process, no connection string credentials, no Docker service dependency for local development. -- The database file can be committed to the repository as seed data, making onboarding instant. - EF Core abstracts the SQL dialect, so migrating to another database requires changing only the provider registration. +- `MigrateAsync()` at startup ensures the schema is always up to date, making onboarding instant without committing binary database files. ### Negative - SQLite does not support concurrent writes, making it unsuitable for multi-instance deployments or high-throughput scenarios. diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index a1158cf..edcd60c 100644 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -8,23 +8,15 @@ log() { return 0 } -IMAGE_STORAGE_PATH="/app/hold/players-sqlite3.db" -VOLUME_STORAGE_PATH="/storage/players-sqlite3.db" - log "✔ Starting container..." +VOLUME_STORAGE_PATH="${STORAGE_PATH:-/storage/players-sqlite3.db}" + if [ ! -f "$VOLUME_STORAGE_PATH" ]; then log "⚠️ No existing database file found in volume." - if [ -f "$IMAGE_STORAGE_PATH" ]; then - log "🔄 Copying database file to writable volume..." - cp "$IMAGE_STORAGE_PATH" "$VOLUME_STORAGE_PATH" - log "✔ Database initialized at $VOLUME_STORAGE_PATH" - else - log "⚠️ Database file missing at $IMAGE_STORAGE_PATH" - exit 1 - fi + log "🗄️ EF Core migrations will initialize the database on first start." else - log "✔ Existing database file found. Skipping seed copy." + log "✔ Existing database file found at $VOLUME_STORAGE_PATH." fi log "✔ Ready!" diff --git a/scripts/run-migrations-and-copy-database.sh b/scripts/run-migrations-and-copy-database.sh deleted file mode 100644 index b9da3a9..0000000 --- a/scripts/run-migrations-and-copy-database.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash - -DATA_FILE="players-sqlite3.db" - -PROJECT_ROOT_PATH="src/Dotnet.Samples.AspNetCore.WebApi" -PROJECT_BASE_PATH="$PROJECT_ROOT_PATH/bin/Debug/net8.0" - -SOURCE_FILE_PATH="$PROJECT_BASE_PATH/storage/$DATA_FILE" -TARGET_FILE_PATH="$PROJECT_ROOT_PATH/storage/$DATA_FILE" - -# log prints a formatted log message prefixed by an emoji and timestamp, followed by the log level and message. -# Parameters: emoji — emoji or symbol to prefix the entry; level — severity or level label; message — the log text. -log() { - local emoji=$1 - local level=$2 - local message=$3 - local timestamp - timestamp=$(date +"%Y-%m-%d %H:%M:%S") - echo "$emoji [$timestamp] [$level] $message" - return 0 -} - -# Check if the EF Core CLI tool is installed -if ! command -v dotnet ef &> /dev/null; then - log "❌" "ERROR" "'dotnet ef' not found. Install it with 'dotnet tool install --global dotnet-ef'" - exit 1 -fi - -# Ensure clean placeholder database file exists -log "✅" "INFO" "Resetting placeholder database at '$TARGET_FILE_PATH'" -rm -f "$TARGET_FILE_PATH" -touch "$TARGET_FILE_PATH" - -# Run the database migration -log "✅" "INFO" "Running EF Core database migration for project at '$PROJECT_ROOT_PATH'..." -dotnet ef database update --project "$PROJECT_ROOT_PATH" -if [[ $? -ne 0 ]]; then - log "❌" "ERROR" "Migration failed. See error above." - exit 1 -fi - -# Check and copy database -if [[ -f "$SOURCE_FILE_PATH" ]]; then - log "✅" "INFO" "Found database at '$SOURCE_FILE_PATH'" - log "✅" "INFO" "Copying to '$TARGET_FILE_PATH'..." - cp -f "$SOURCE_FILE_PATH" "$TARGET_FILE_PATH" - - if [[ $? -eq 0 ]]; then - log "✅" "INFO" "Database successfully copied to '$TARGET_FILE_PATH'" - else - log "❌" "ERROR" "Failed to copy the database file." - exit 1 - fi -else - log "⚠️" "WARNING" "Database file not found at '$SOURCE_FILE_PATH'." - log "⚠️" "WARNING" "Make sure the migration actually generated the file." - exit 1 -fi - -# Confirm destination file exists -if [[ -f "$TARGET_FILE_PATH" ]]; then - log "✅" "INFO" "Done. The database is now available at '$TARGET_FILE_PATH'" -else - log "⚠️" "WARNING" "Something went wrong. The destination file was not found." - exit 1 -fi diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Data/PlayerDbContext.cs b/src/Dotnet.Samples.AspNetCore.WebApi/Data/PlayerDbContext.cs index 8752ba1..8c8ce15 100644 --- a/src/Dotnet.Samples.AspNetCore.WebApi/Data/PlayerDbContext.cs +++ b/src/Dotnet.Samples.AspNetCore.WebApi/Data/PlayerDbContext.cs @@ -1,4 +1,5 @@ using Dotnet.Samples.AspNetCore.WebApi.Models; +using Dotnet.Samples.AspNetCore.WebApi.Utilities; using Microsoft.EntityFrameworkCore; namespace Dotnet.Samples.AspNetCore.WebApi.Data; @@ -33,6 +34,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.HasKey(player => player.Id); entity.Property(player => player.Id).ValueGeneratedOnAdd(); entity.HasIndex(player => player.SquadNumber).IsUnique(); + entity.HasData(PlayerData.MakeStarting11WithId()); + entity.HasData(PlayerData.GetSubstitutesWithId()); }); } } diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Dotnet.Samples.AspNetCore.WebApi.csproj b/src/Dotnet.Samples.AspNetCore.WebApi/Dotnet.Samples.AspNetCore.WebApi.csproj index 741c36a..8310cf2 100644 --- a/src/Dotnet.Samples.AspNetCore.WebApi/Dotnet.Samples.AspNetCore.WebApi.csproj +++ b/src/Dotnet.Samples.AspNetCore.WebApi/Dotnet.Samples.AspNetCore.WebApi.csproj @@ -25,13 +25,6 @@ - - - PreserveNewest - true - - - true $(NoWarn);1591 diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Extensions/ServiceCollectionExtensions.cs b/src/Dotnet.Samples.AspNetCore.WebApi/Extensions/ServiceCollectionExtensions.cs index d082377..800c81b 100644 --- a/src/Dotnet.Samples.AspNetCore.WebApi/Extensions/ServiceCollectionExtensions.cs +++ b/src/Dotnet.Samples.AspNetCore.WebApi/Extensions/ServiceCollectionExtensions.cs @@ -31,11 +31,16 @@ IWebHostEnvironment environment { services.AddDbContextPool(options => { - var dataSource = Path.Combine( - AppContext.BaseDirectory, - "storage", - "players-sqlite3.db" - ); + var storagePath = Environment.GetEnvironmentVariable("STORAGE_PATH"); + var dataSource = !string.IsNullOrWhiteSpace(storagePath) + ? storagePath + : Path.Combine(AppContext.BaseDirectory, "storage", "players-sqlite3.db"); + + var storageDir = Path.GetDirectoryName(dataSource); + if (!string.IsNullOrWhiteSpace(storageDir)) + { + Directory.CreateDirectory(storageDir); + } options.UseSqlite($"Data Source={dataSource}"); if (environment.IsDevelopment()) diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414195445_SeedStarting11.Designer.cs b/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414195445_SeedStarting11.Designer.cs deleted file mode 100644 index 4afc29e..0000000 --- a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414195445_SeedStarting11.Designer.cs +++ /dev/null @@ -1,69 +0,0 @@ -// -using System; -using Dotnet.Samples.AspNetCore.WebApi.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Dotnet.Samples.AspNetCore.WebApi.Migrations -{ - [DbContext(typeof(PlayerDbContext))] - [Migration("20250414195445_SeedStarting11")] - partial class SeedStarting11 - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "9.0.4"); - - modelBuilder.Entity("Dotnet.Samples.AspNetCore.WebApi.Models.Player", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("AbbrPosition") - .HasColumnType("TEXT"); - - b.Property("DateOfBirth") - .HasColumnType("TEXT"); - - b.Property("FirstName") - .HasColumnType("TEXT"); - - b.Property("LastName") - .HasColumnType("TEXT"); - - b.Property("League") - .HasColumnType("TEXT"); - - b.Property("MiddleName") - .HasColumnType("TEXT"); - - b.Property("Position") - .HasColumnType("TEXT"); - - b.Property("SquadNumber") - .HasColumnType("INTEGER"); - - b.Property("Starting11") - .HasColumnType("INTEGER"); - - b.Property("Team") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("SquadNumber") - .IsUnique(); - - b.ToTable("Players"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414195445_SeedStarting11.cs b/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414195445_SeedStarting11.cs deleted file mode 100644 index 198c334..0000000 --- a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414195445_SeedStarting11.cs +++ /dev/null @@ -1,62 +0,0 @@ -using Dotnet.Samples.AspNetCore.WebApi.Utilities; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Dotnet.Samples.AspNetCore.WebApi.Migrations -{ - /// - public partial class SeedStarting11 : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - var starting11 = PlayerData.MakeStarting11WithId(); - - foreach (var player in starting11) - { - migrationBuilder.InsertData( - table: "Players", - columns: - [ - "Id", - "FirstName", - "MiddleName", - "LastName", - "DateOfBirth", - "SquadNumber", - "Position", - "AbbrPosition", - "Team", - "League", - "Starting11" - ], - values: new object[] - { - player.Id, - player.FirstName, - player.MiddleName, - player.LastName, - player.DateOfBirth, - player.SquadNumber, - player.Position, - player.AbbrPosition, - player.Team, - player.League, - player.Starting11 - } - ); - } - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - var starting11 = PlayerData.MakeStarting11WithId(); - foreach (var player in starting11) - { - migrationBuilder.DeleteData(table: "Players", keyColumn: "Id", keyValue: player.Id); - } - } - } -} diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20251221220614_SeedSubstitutes.Designer.cs b/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20251221220614_SeedSubstitutes.Designer.cs deleted file mode 100644 index f7f7b89..0000000 --- a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20251221220614_SeedSubstitutes.Designer.cs +++ /dev/null @@ -1,69 +0,0 @@ -// -using System; -using Dotnet.Samples.AspNetCore.WebApi.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Dotnet.Samples.AspNetCore.WebApi.Migrations -{ - [DbContext(typeof(PlayerDbContext))] - [Migration("20251221220614_SeedSubstitutes")] - partial class SeedSubstitutes - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "9.0.11"); - - modelBuilder.Entity("Dotnet.Samples.AspNetCore.WebApi.Models.Player", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("AbbrPosition") - .HasColumnType("TEXT"); - - b.Property("DateOfBirth") - .HasColumnType("TEXT"); - - b.Property("FirstName") - .HasColumnType("TEXT"); - - b.Property("LastName") - .HasColumnType("TEXT"); - - b.Property("League") - .HasColumnType("TEXT"); - - b.Property("MiddleName") - .HasColumnType("TEXT"); - - b.Property("Position") - .HasColumnType("TEXT"); - - b.Property("SquadNumber") - .HasColumnType("INTEGER"); - - b.Property("Starting11") - .HasColumnType("INTEGER"); - - b.Property("Team") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("SquadNumber") - .IsUnique(); - - b.ToTable("Players"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20251221220614_SeedSubstitutes.cs b/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20251221220614_SeedSubstitutes.cs deleted file mode 100644 index b4e4ffc..0000000 --- a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20251221220614_SeedSubstitutes.cs +++ /dev/null @@ -1,62 +0,0 @@ -using Dotnet.Samples.AspNetCore.WebApi.Utilities; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Dotnet.Samples.AspNetCore.WebApi.Migrations -{ - /// - public partial class SeedSubstitutes : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - var substitutes = PlayerData.GetSubstitutesWithId(); - - foreach (var player in substitutes) - { - migrationBuilder.InsertData( - table: "Players", - columns: - [ - "Id", - "FirstName", - "MiddleName", - "LastName", - "DateOfBirth", - "SquadNumber", - "Position", - "AbbrPosition", - "Team", - "League", - "Starting11" - ], - values: new object[] - { - player.Id, - player.FirstName, - player.MiddleName, - player.LastName, - player.DateOfBirth, - player.SquadNumber, - player.Position, - player.AbbrPosition, - player.Team, - player.League, - player.Starting11 - } - ); - } - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - var substitutes = PlayerData.GetSubstitutesWithId(); - foreach (var player in substitutes) - { - migrationBuilder.DeleteData(table: "Players", keyColumn: "Id", keyValue: player.Id); - } - } - } -} diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260329000000_NormalizePlayerDataset.Designer.cs b/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260329000000_NormalizePlayerDataset.Designer.cs deleted file mode 100644 index 33c29f9..0000000 --- a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260329000000_NormalizePlayerDataset.Designer.cs +++ /dev/null @@ -1,69 +0,0 @@ -// -using System; -using Dotnet.Samples.AspNetCore.WebApi.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Dotnet.Samples.AspNetCore.WebApi.Migrations -{ - [DbContext(typeof(PlayerDbContext))] - [Migration("20260329000000_NormalizePlayerDataset")] - partial class NormalizePlayerDataset - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "9.0.11"); - - modelBuilder.Entity("Dotnet.Samples.AspNetCore.WebApi.Models.Player", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("AbbrPosition") - .HasColumnType("TEXT"); - - b.Property("DateOfBirth") - .HasColumnType("TEXT"); - - b.Property("FirstName") - .HasColumnType("TEXT"); - - b.Property("LastName") - .HasColumnType("TEXT"); - - b.Property("League") - .HasColumnType("TEXT"); - - b.Property("MiddleName") - .HasColumnType("TEXT"); - - b.Property("Position") - .HasColumnType("TEXT"); - - b.Property("SquadNumber") - .HasColumnType("INTEGER"); - - b.Property("Starting11") - .HasColumnType("INTEGER"); - - b.Property("Team") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("SquadNumber") - .IsUnique(); - - b.ToTable("Players"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260329000000_NormalizePlayerDataset.cs b/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260329000000_NormalizePlayerDataset.cs deleted file mode 100644 index f3502a5..0000000 --- a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260329000000_NormalizePlayerDataset.cs +++ /dev/null @@ -1,192 +0,0 @@ -using Dotnet.Samples.AspNetCore.WebApi.Utilities; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Dotnet.Samples.AspNetCore.WebApi.Migrations -{ - /// - public partial class NormalizePlayerDataset : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - // Update UUIDs to canonical UUID v5 values for starting 11 - migrationBuilder.Sql( - "UPDATE Players SET Id = '01772c59-43f0-5d85-b913-c78e4e281452' WHERE SquadNumber = 23" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'da31293b-4c7e-5e0f-a168-469ee29ecbc4' WHERE SquadNumber = 26" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'c096c69e-762b-5281-9290-bb9c167a24a0' WHERE SquadNumber = 13" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'd5f7dd7a-1dcb-5960-ba27-e34865b63358' WHERE SquadNumber = 19" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = '2f6f90a0-9b9d-5023-96d2-a2aaf03143a6' WHERE SquadNumber = 3" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'b5b46e79-929e-5ed2-949d-0d167109c022' WHERE SquadNumber = 11" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = '0293b282-1da8-562e-998e-83849b417a42' WHERE SquadNumber = 7" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'd3ba552a-dac3-588a-b961-1ea7224017fd', Team = 'SL Benfica', League = 'Liga Portugal' WHERE SquadNumber = 24" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = '9613cae9-16ab-5b54-937e-3135123b9e0d', Team = 'Brighton & Hove Albion' WHERE SquadNumber = 20" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'acc433bf-d505-51fe-831e-45eb44c4d43c', Team = 'Paris Saint-Germain', League = 'Ligue 1' WHERE SquadNumber = 10" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = '38bae91d-8519-55a2-b30a-b9fe38849bfb' WHERE SquadNumber = 9" - ); - - // Update UUIDs to canonical UUID v5 values for substitutes - migrationBuilder.Sql( - "UPDATE Players SET Id = '5a9cd988-95e6-54c1-bc34-9aa08acca8d0' WHERE SquadNumber = 1" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'c62f2ac1-41e8-5d34-b073-2ba0913d0e31' WHERE SquadNumber = 12" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = '5fdb10e8-38c0-5084-9a3f-b369a960b9c2' WHERE SquadNumber = 2" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'bbd441f7-fcfb-5834-8468-2a9004b64c8c' WHERE SquadNumber = 4" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'd8bfea25-f189-5d5e-b3a5-ed89329b9f7c' WHERE SquadNumber = 6" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'dca343a8-12e5-53d6-89a8-916b120a5ee4' WHERE SquadNumber = 8" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = '98306555-a466-5d18-804e-dc82175e697b' WHERE SquadNumber = 25" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = '9d140400-196f-55d8-86e1-e0b96a375c83' WHERE SquadNumber = 5" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'd3b0e8e8-2c34-531a-b608-b24fed0ef986' WHERE SquadNumber = 14" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = '7cc8d527-56a2-58bd-9528-2618fc139d30' WHERE SquadNumber = 17" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = '191c82af-0c51-526a-b903-c3600b61b506' WHERE SquadNumber = 18" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'b1306b7b-a3a4-5f7c-90fd-dd5bdbed57ba' WHERE SquadNumber = 15" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'ecec27e8-487b-5622-b116-0855020477ed' WHERE SquadNumber = 16" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = '7941cd7c-4df1-5952-97e8-1e7f5d08e8aa' WHERE SquadNumber = 21" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = '79c96f29-c59f-5f98-96b8-3a5946246624' WHERE SquadNumber = 22" - ); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - // Revert team/league corrections - migrationBuilder.Sql( - "UPDATE Players SET Team = 'Chelsea FC', League = 'Premier League' WHERE SquadNumber = 24" - ); - migrationBuilder.Sql("UPDATE Players SET Team = 'Liverpool FC' WHERE SquadNumber = 20"); - migrationBuilder.Sql( - "UPDATE Players SET Team = 'Inter Miami CF', League = 'Major League Soccer' WHERE SquadNumber = 10" - ); - - // Revert UUIDs for starting 11 - migrationBuilder.Sql( - "UPDATE Players SET Id = 'f91b9671-cfd1-48d7-afb9-34e93568c9ee' WHERE SquadNumber = 23" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = '51ec988a-0d8b-42d9-84e4-5e17c93d8d50' WHERE SquadNumber = 26" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = '0969be24-086c-4c51-9c29-0280683b8133' WHERE SquadNumber = 13" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'ac532709-4682-49db-acc2-395f61f405ab' WHERE SquadNumber = 19" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'dc052ee4-c69d-49da-a256-b8ec727f4d59' WHERE SquadNumber = 3" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = '6def9bb7-23c2-42b5-b37b-2e9b6fec31cd' WHERE SquadNumber = 11" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = '8ca911d9-ab32-4366-b2b1-cad5eb6f4bcc' WHERE SquadNumber = 7" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = '198c4774-9607-4e76-8475-ec2528af69d2' WHERE SquadNumber = 24" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = '06971ada-1b3d-4d4a-88f5-e2f35311b5aa' WHERE SquadNumber = 20" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'df6f6bab-5efd-4518-80bb-09ef54435636' WHERE SquadNumber = 10" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = '27cf4e29-67d5-4c3b-9cf8-7d3fa3942fcb' WHERE SquadNumber = 9" - ); - - // Revert UUIDs for substitutes - migrationBuilder.Sql( - "UPDATE Players SET Id = 'b1f8a5d3-2c4e-4a6b-8d9f-1e3c5a7b9d2f' WHERE SquadNumber = 1" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'c2e9b6f4-3d5f-4b7c-9e0a-2f4d6b8c0e3a' WHERE SquadNumber = 12" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'd3f0c7e5-4e6a-5c8d-0f1b-3a5e7c9d1f4b' WHERE SquadNumber = 2" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'e4a1d8f6-5f7b-6d9e-1a2c-4b6d8e0a2c5d' WHERE SquadNumber = 4" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'f5b2e9a7-6a8c-7e0f-2b3d-5c7e9a1b3d6e' WHERE SquadNumber = 6" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'a6c3f0b8-7b9d-8f1a-3c4e-6d8f0b2c4e7f' WHERE SquadNumber = 8" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'b7d4a1c9-8c0e-9a2b-4d5f-7e9a1c3d5f8a' WHERE SquadNumber = 25" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'c8e5b2d0-9d1f-0b3c-5e6a-8f0b2d4e6a9b' WHERE SquadNumber = 5" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'd9f6c3e1-0e2a-1c4d-6f7b-9a1c3e5f7b0c' WHERE SquadNumber = 14" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'e0a7d4f2-1f3b-2d5e-7a8c-0b2d4f6a8c1d' WHERE SquadNumber = 17" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'f1b8e5a3-2a4c-3e6f-8b9d-1c3e5a7b9d2e' WHERE SquadNumber = 18" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'a2c9f6b4-3b5d-4f7a-9c0e-2d4f6b8c0e3f' WHERE SquadNumber = 15" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'b3d0a7c5-4c6e-5a8b-0d1f-3e5a7c9d1f4a' WHERE SquadNumber = 16" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'c4e1b8d6-5d7f-6b9c-1e2a-4f6d8e0a2c5b' WHERE SquadNumber = 21" - ); - migrationBuilder.Sql( - "UPDATE Players SET Id = 'd5f2c9e7-6e8a-7c0d-2f3b-5a7e9a1b3d6c' WHERE SquadNumber = 22" - ); - } - } -} diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414191223_InitialCreate.Designer.cs b/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141647_InitialCreate.Designer.cs similarity index 94% rename from src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414191223_InitialCreate.Designer.cs rename to src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141647_InitialCreate.Designer.cs index 6567cb1..e237b15 100644 --- a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414191223_InitialCreate.Designer.cs +++ b/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141647_InitialCreate.Designer.cs @@ -11,14 +11,14 @@ namespace Dotnet.Samples.AspNetCore.WebApi.Migrations { [DbContext(typeof(PlayerDbContext))] - [Migration("20250414191223_InitialCreate")] + [Migration("20260409141647_InitialCreate")] partial class InitialCreate { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "9.0.4"); + modelBuilder.HasAnnotation("ProductVersion", "10.0.5"); modelBuilder.Entity("Dotnet.Samples.AspNetCore.WebApi.Models.Player", b => { diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414191223_InitialCreate.cs b/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141647_InitialCreate.cs similarity index 100% rename from src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414191223_InitialCreate.cs rename to src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141647_InitialCreate.cs diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141707_SeedStarting11.Designer.cs b/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141707_SeedStarting11.Designer.cs new file mode 100644 index 0000000..96b96d7 --- /dev/null +++ b/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141707_SeedStarting11.Designer.cs @@ -0,0 +1,222 @@ +// +using System; +using Dotnet.Samples.AspNetCore.WebApi.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Dotnet.Samples.AspNetCore.WebApi.Migrations +{ + [DbContext(typeof(PlayerDbContext))] + [Migration("20260409141707_SeedStarting11")] + partial class SeedStarting11 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "10.0.5"); + + modelBuilder.Entity("Dotnet.Samples.AspNetCore.WebApi.Models.Player", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("AbbrPosition") + .HasColumnType("TEXT"); + + b.Property("DateOfBirth") + .HasColumnType("TEXT"); + + b.Property("FirstName") + .HasColumnType("TEXT"); + + b.Property("LastName") + .HasColumnType("TEXT"); + + b.Property("League") + .HasColumnType("TEXT"); + + b.Property("MiddleName") + .HasColumnType("TEXT"); + + b.Property("Position") + .HasColumnType("TEXT"); + + b.Property("SquadNumber") + .HasColumnType("INTEGER"); + + b.Property("Starting11") + .HasColumnType("INTEGER"); + + b.Property("Team") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("SquadNumber") + .IsUnique(); + + b.ToTable("Players"); + + b.HasData( + new + { + Id = new Guid("01772c59-43f0-5d85-b913-c78e4e281452"), + AbbrPosition = "GK", + DateOfBirth = new DateTime(1992, 9, 1, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Damián", + LastName = "Martínez", + League = "Premier League", + MiddleName = "Emiliano", + Position = "Goalkeeper", + SquadNumber = 23, + Starting11 = true, + Team = "Aston Villa FC" + }, + new + { + Id = new Guid("da31293b-4c7e-5e0f-a168-469ee29ecbc4"), + AbbrPosition = "RB", + DateOfBirth = new DateTime(1998, 4, 5, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Nahuel", + LastName = "Molina", + League = "La Liga", + Position = "Right-Back", + SquadNumber = 26, + Starting11 = true, + Team = "Altético Madrid" + }, + new + { + Id = new Guid("c096c69e-762b-5281-9290-bb9c167a24a0"), + AbbrPosition = "CB", + DateOfBirth = new DateTime(1998, 4, 26, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Cristian", + LastName = "Romero", + League = "Premier League", + MiddleName = "Gabriel", + Position = "Centre-Back", + SquadNumber = 13, + Starting11 = true, + Team = "Tottenham Hotspur" + }, + new + { + Id = new Guid("d5f7dd7a-1dcb-5960-ba27-e34865b63358"), + AbbrPosition = "CB", + DateOfBirth = new DateTime(1988, 2, 11, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Nicolás", + LastName = "Otamendi", + League = "Liga Portugal", + MiddleName = "Hernán Gonzalo", + Position = "Centre-Back", + SquadNumber = 19, + Starting11 = true, + Team = "SL Benfica" + }, + new + { + Id = new Guid("2f6f90a0-9b9d-5023-96d2-a2aaf03143a6"), + AbbrPosition = "LB", + DateOfBirth = new DateTime(1992, 8, 30, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Nicolás", + LastName = "Tagliafico", + League = "Ligue 1", + MiddleName = "Alejandro", + Position = "Left-Back", + SquadNumber = 3, + Starting11 = true, + Team = "Olympique Lyon" + }, + new + { + Id = new Guid("b5b46e79-929e-5ed2-949d-0d167109c022"), + AbbrPosition = "RW", + DateOfBirth = new DateTime(1988, 2, 13, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Ángel", + LastName = "Di María", + League = "Liga Portugal", + MiddleName = "Fabián", + Position = "Right Winger", + SquadNumber = 11, + Starting11 = true, + Team = "SL Benfica" + }, + new + { + Id = new Guid("0293b282-1da8-562e-998e-83849b417a42"), + AbbrPosition = "CM", + DateOfBirth = new DateTime(1994, 5, 23, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Rodrigo", + LastName = "de Paul", + League = "La Liga", + MiddleName = "Javier", + Position = "Central Midfield", + SquadNumber = 7, + Starting11 = true, + Team = "Altético Madrid" + }, + new + { + Id = new Guid("d3ba552a-dac3-588a-b961-1ea7224017fd"), + AbbrPosition = "CM", + DateOfBirth = new DateTime(2001, 1, 16, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Enzo", + LastName = "Fernández", + League = "Liga Portugal", + MiddleName = "Jeremías", + Position = "Central Midfield", + SquadNumber = 24, + Starting11 = true, + Team = "SL Benfica" + }, + new + { + Id = new Guid("9613cae9-16ab-5b54-937e-3135123b9e0d"), + AbbrPosition = "CM", + DateOfBirth = new DateTime(1998, 12, 23, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Alexis", + LastName = "Mac Allister", + League = "Premier League", + Position = "Central Midfield", + SquadNumber = 20, + Starting11 = true, + Team = "Brighton & Hove Albion" + }, + new + { + Id = new Guid("acc433bf-d505-51fe-831e-45eb44c4d43c"), + AbbrPosition = "RW", + DateOfBirth = new DateTime(1987, 6, 23, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Lionel", + LastName = "Messi", + League = "Ligue 1", + MiddleName = "Andrés", + Position = "Right Winger", + SquadNumber = 10, + Starting11 = true, + Team = "Paris Saint-Germain" + }, + new + { + Id = new Guid("38bae91d-8519-55a2-b30a-b9fe38849bfb"), + AbbrPosition = "CF", + DateOfBirth = new DateTime(2000, 1, 30, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Julián", + LastName = "Álvarez", + League = "Premier League", + Position = "Centre-Forward", + SquadNumber = 9, + Starting11 = true, + Team = "Manchester City" + }); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141707_SeedStarting11.cs b/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141707_SeedStarting11.cs new file mode 100644 index 0000000..d466914 --- /dev/null +++ b/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141707_SeedStarting11.cs @@ -0,0 +1,251 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace Dotnet.Samples.AspNetCore.WebApi.Migrations +{ + /// + public partial class SeedStarting11 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.InsertData( + table: "Players", + columns: new[] + { + "Id", + "AbbrPosition", + "DateOfBirth", + "FirstName", + "LastName", + "League", + "MiddleName", + "Position", + "SquadNumber", + "Starting11", + "Team" + }, + values: new object[,] + { + { + new Guid("01772c59-43f0-5d85-b913-c78e4e281452"), + "GK", + new DateTime(1992, 9, 1, 0, 0, 0, 0, DateTimeKind.Utc), + "Damián", + "Martínez", + "Premier League", + "Emiliano", + "Goalkeeper", + 23, + true, + "Aston Villa FC" + }, + { + new Guid("0293b282-1da8-562e-998e-83849b417a42"), + "CM", + new DateTime(1994, 5, 23, 0, 0, 0, 0, DateTimeKind.Utc), + "Rodrigo", + "de Paul", + "La Liga", + "Javier", + "Central Midfield", + 7, + true, + "Altético Madrid" + }, + { + new Guid("2f6f90a0-9b9d-5023-96d2-a2aaf03143a6"), + "LB", + new DateTime(1992, 8, 30, 0, 0, 0, 0, DateTimeKind.Utc), + "Nicolás", + "Tagliafico", + "Ligue 1", + "Alejandro", + "Left-Back", + 3, + true, + "Olympique Lyon" + }, + { + new Guid("38bae91d-8519-55a2-b30a-b9fe38849bfb"), + "CF", + new DateTime(2000, 1, 30, 0, 0, 0, 0, DateTimeKind.Utc), + "Julián", + "Álvarez", + "Premier League", + null, + "Centre-Forward", + 9, + true, + "Manchester City" + }, + { + new Guid("9613cae9-16ab-5b54-937e-3135123b9e0d"), + "CM", + new DateTime(1998, 12, 23, 0, 0, 0, 0, DateTimeKind.Utc), + "Alexis", + "Mac Allister", + "Premier League", + null, + "Central Midfield", + 20, + true, + "Brighton & Hove Albion" + }, + { + new Guid("acc433bf-d505-51fe-831e-45eb44c4d43c"), + "RW", + new DateTime(1987, 6, 23, 0, 0, 0, 0, DateTimeKind.Utc), + "Lionel", + "Messi", + "Ligue 1", + "Andrés", + "Right Winger", + 10, + true, + "Paris Saint-Germain" + }, + { + new Guid("b5b46e79-929e-5ed2-949d-0d167109c022"), + "RW", + new DateTime(1988, 2, 13, 0, 0, 0, 0, DateTimeKind.Utc), + "Ángel", + "Di María", + "Liga Portugal", + "Fabián", + "Right Winger", + 11, + true, + "SL Benfica" + }, + { + new Guid("c096c69e-762b-5281-9290-bb9c167a24a0"), + "CB", + new DateTime(1998, 4, 26, 0, 0, 0, 0, DateTimeKind.Utc), + "Cristian", + "Romero", + "Premier League", + "Gabriel", + "Centre-Back", + 13, + true, + "Tottenham Hotspur" + }, + { + new Guid("d3ba552a-dac3-588a-b961-1ea7224017fd"), + "CM", + new DateTime(2001, 1, 16, 0, 0, 0, 0, DateTimeKind.Utc), + "Enzo", + "Fernández", + "Liga Portugal", + "Jeremías", + "Central Midfield", + 24, + true, + "SL Benfica" + }, + { + new Guid("d5f7dd7a-1dcb-5960-ba27-e34865b63358"), + "CB", + new DateTime(1988, 2, 11, 0, 0, 0, 0, DateTimeKind.Utc), + "Nicolás", + "Otamendi", + "Liga Portugal", + "Hernán Gonzalo", + "Centre-Back", + 19, + true, + "SL Benfica" + }, + { + new Guid("da31293b-4c7e-5e0f-a168-469ee29ecbc4"), + "RB", + new DateTime(1998, 4, 5, 0, 0, 0, 0, DateTimeKind.Utc), + "Nahuel", + "Molina", + "La Liga", + null, + "Right-Back", + 26, + true, + "Altético Madrid" + } + } + ); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("01772c59-43f0-5d85-b913-c78e4e281452") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("0293b282-1da8-562e-998e-83849b417a42") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("2f6f90a0-9b9d-5023-96d2-a2aaf03143a6") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("38bae91d-8519-55a2-b30a-b9fe38849bfb") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("9613cae9-16ab-5b54-937e-3135123b9e0d") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("acc433bf-d505-51fe-831e-45eb44c4d43c") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("b5b46e79-929e-5ed2-949d-0d167109c022") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("c096c69e-762b-5281-9290-bb9c167a24a0") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("d3ba552a-dac3-588a-b961-1ea7224017fd") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("d5f7dd7a-1dcb-5960-ba27-e34865b63358") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("da31293b-4c7e-5e0f-a168-469ee29ecbc4") + ); + } + } +} diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141721_SeedSubstitutes.Designer.cs b/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141721_SeedSubstitutes.Designer.cs new file mode 100644 index 0000000..0881e2b --- /dev/null +++ b/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141721_SeedSubstitutes.Designer.cs @@ -0,0 +1,429 @@ +// +using System; +using Dotnet.Samples.AspNetCore.WebApi.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Dotnet.Samples.AspNetCore.WebApi.Migrations +{ + [DbContext(typeof(PlayerDbContext))] + [Migration("20260409141721_SeedSubstitutes")] + partial class SeedSubstitutes + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "10.0.5"); + + modelBuilder.Entity("Dotnet.Samples.AspNetCore.WebApi.Models.Player", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("AbbrPosition") + .HasColumnType("TEXT"); + + b.Property("DateOfBirth") + .HasColumnType("TEXT"); + + b.Property("FirstName") + .HasColumnType("TEXT"); + + b.Property("LastName") + .HasColumnType("TEXT"); + + b.Property("League") + .HasColumnType("TEXT"); + + b.Property("MiddleName") + .HasColumnType("TEXT"); + + b.Property("Position") + .HasColumnType("TEXT"); + + b.Property("SquadNumber") + .HasColumnType("INTEGER"); + + b.Property("Starting11") + .HasColumnType("INTEGER"); + + b.Property("Team") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("SquadNumber") + .IsUnique(); + + b.ToTable("Players"); + + b.HasData( + new + { + Id = new Guid("01772c59-43f0-5d85-b913-c78e4e281452"), + AbbrPosition = "GK", + DateOfBirth = new DateTime(1992, 9, 1, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Damián", + LastName = "Martínez", + League = "Premier League", + MiddleName = "Emiliano", + Position = "Goalkeeper", + SquadNumber = 23, + Starting11 = true, + Team = "Aston Villa FC" + }, + new + { + Id = new Guid("da31293b-4c7e-5e0f-a168-469ee29ecbc4"), + AbbrPosition = "RB", + DateOfBirth = new DateTime(1998, 4, 5, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Nahuel", + LastName = "Molina", + League = "La Liga", + Position = "Right-Back", + SquadNumber = 26, + Starting11 = true, + Team = "Altético Madrid" + }, + new + { + Id = new Guid("c096c69e-762b-5281-9290-bb9c167a24a0"), + AbbrPosition = "CB", + DateOfBirth = new DateTime(1998, 4, 26, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Cristian", + LastName = "Romero", + League = "Premier League", + MiddleName = "Gabriel", + Position = "Centre-Back", + SquadNumber = 13, + Starting11 = true, + Team = "Tottenham Hotspur" + }, + new + { + Id = new Guid("d5f7dd7a-1dcb-5960-ba27-e34865b63358"), + AbbrPosition = "CB", + DateOfBirth = new DateTime(1988, 2, 11, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Nicolás", + LastName = "Otamendi", + League = "Liga Portugal", + MiddleName = "Hernán Gonzalo", + Position = "Centre-Back", + SquadNumber = 19, + Starting11 = true, + Team = "SL Benfica" + }, + new + { + Id = new Guid("2f6f90a0-9b9d-5023-96d2-a2aaf03143a6"), + AbbrPosition = "LB", + DateOfBirth = new DateTime(1992, 8, 30, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Nicolás", + LastName = "Tagliafico", + League = "Ligue 1", + MiddleName = "Alejandro", + Position = "Left-Back", + SquadNumber = 3, + Starting11 = true, + Team = "Olympique Lyon" + }, + new + { + Id = new Guid("b5b46e79-929e-5ed2-949d-0d167109c022"), + AbbrPosition = "RW", + DateOfBirth = new DateTime(1988, 2, 13, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Ángel", + LastName = "Di María", + League = "Liga Portugal", + MiddleName = "Fabián", + Position = "Right Winger", + SquadNumber = 11, + Starting11 = true, + Team = "SL Benfica" + }, + new + { + Id = new Guid("0293b282-1da8-562e-998e-83849b417a42"), + AbbrPosition = "CM", + DateOfBirth = new DateTime(1994, 5, 23, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Rodrigo", + LastName = "de Paul", + League = "La Liga", + MiddleName = "Javier", + Position = "Central Midfield", + SquadNumber = 7, + Starting11 = true, + Team = "Altético Madrid" + }, + new + { + Id = new Guid("d3ba552a-dac3-588a-b961-1ea7224017fd"), + AbbrPosition = "CM", + DateOfBirth = new DateTime(2001, 1, 16, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Enzo", + LastName = "Fernández", + League = "Liga Portugal", + MiddleName = "Jeremías", + Position = "Central Midfield", + SquadNumber = 24, + Starting11 = true, + Team = "SL Benfica" + }, + new + { + Id = new Guid("9613cae9-16ab-5b54-937e-3135123b9e0d"), + AbbrPosition = "CM", + DateOfBirth = new DateTime(1998, 12, 23, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Alexis", + LastName = "Mac Allister", + League = "Premier League", + Position = "Central Midfield", + SquadNumber = 20, + Starting11 = true, + Team = "Brighton & Hove Albion" + }, + new + { + Id = new Guid("acc433bf-d505-51fe-831e-45eb44c4d43c"), + AbbrPosition = "RW", + DateOfBirth = new DateTime(1987, 6, 23, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Lionel", + LastName = "Messi", + League = "Ligue 1", + MiddleName = "Andrés", + Position = "Right Winger", + SquadNumber = 10, + Starting11 = true, + Team = "Paris Saint-Germain" + }, + new + { + Id = new Guid("38bae91d-8519-55a2-b30a-b9fe38849bfb"), + AbbrPosition = "CF", + DateOfBirth = new DateTime(2000, 1, 30, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Julián", + LastName = "Álvarez", + League = "Premier League", + Position = "Centre-Forward", + SquadNumber = 9, + Starting11 = true, + Team = "Manchester City" + }, + new + { + Id = new Guid("5a9cd988-95e6-54c1-bc34-9aa08acca8d0"), + AbbrPosition = "GK", + DateOfBirth = new DateTime(1986, 10, 16, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Franco", + LastName = "Armani", + League = "Copa de la Liga", + MiddleName = "Daniel", + Position = "Goalkeeper", + SquadNumber = 1, + Starting11 = false, + Team = "River Plate" + }, + new + { + Id = new Guid("c62f2ac1-41e8-5d34-b073-2ba0913d0e31"), + AbbrPosition = "GK", + DateOfBirth = new DateTime(1992, 5, 20, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Gerónimo", + LastName = "Rulli", + League = "Eredivisie", + Position = "Goalkeeper", + SquadNumber = 12, + Starting11 = false, + Team = "Ajax Amsterdam" + }, + new + { + Id = new Guid("5fdb10e8-38c0-5084-9a3f-b369a960b9c2"), + AbbrPosition = "RB", + DateOfBirth = new DateTime(1998, 1, 12, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Juan", + LastName = "Foyth", + League = "La Liga", + MiddleName = "Marcos", + Position = "Right-Back", + SquadNumber = 2, + Starting11 = false, + Team = "Villarreal" + }, + new + { + Id = new Guid("bbd441f7-fcfb-5834-8468-2a9004b64c8c"), + AbbrPosition = "RB", + DateOfBirth = new DateTime(1997, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Gonzalo", + LastName = "Montiel", + League = "Premier League", + MiddleName = "Ariel", + Position = "Right-Back", + SquadNumber = 4, + Starting11 = false, + Team = "Nottingham Forest" + }, + new + { + Id = new Guid("d8bfea25-f189-5d5e-b3a5-ed89329b9f7c"), + AbbrPosition = "CB", + DateOfBirth = new DateTime(1991, 6, 27, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Germán", + LastName = "Pezzella", + League = "La Liga", + MiddleName = "Alejo", + Position = "Centre-Back", + SquadNumber = 6, + Starting11 = false, + Team = "Real Betis Balompié" + }, + new + { + Id = new Guid("dca343a8-12e5-53d6-89a8-916b120a5ee4"), + AbbrPosition = "LB", + DateOfBirth = new DateTime(1991, 10, 28, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Marcos", + LastName = "Acuña", + League = "La Liga", + MiddleName = "Javier", + Position = "Left-Back", + SquadNumber = 8, + Starting11 = false, + Team = "Sevilla FC" + }, + new + { + Id = new Guid("98306555-a466-5d18-804e-dc82175e697b"), + AbbrPosition = "CB", + DateOfBirth = new DateTime(1998, 1, 18, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Lisandro", + LastName = "Martínez", + League = "Premier League", + Position = "Centre-Back", + SquadNumber = 25, + Starting11 = false, + Team = "Manchester United" + }, + new + { + Id = new Guid("9d140400-196f-55d8-86e1-e0b96a375c83"), + AbbrPosition = "DM", + DateOfBirth = new DateTime(1994, 6, 29, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Leandro", + LastName = "Paredes", + League = "Serie A", + MiddleName = "Daniel", + Position = "Defensive Midfield", + SquadNumber = 5, + Starting11 = false, + Team = "AS Roma" + }, + new + { + Id = new Guid("d3b0e8e8-2c34-531a-b608-b24fed0ef986"), + AbbrPosition = "CM", + DateOfBirth = new DateTime(1998, 10, 5, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Exequiel", + LastName = "Palacios", + League = "Bundesliga", + MiddleName = "Alejandro", + Position = "Central Midfield", + SquadNumber = 14, + Starting11 = false, + Team = "Bayer 04 Leverkusen" + }, + new + { + Id = new Guid("7cc8d527-56a2-58bd-9528-2618fc139d30"), + AbbrPosition = "LW", + DateOfBirth = new DateTime(1988, 2, 15, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Alejandro", + LastName = "Gómez", + League = "Serie A", + MiddleName = "Darío", + Position = "Left Winger", + SquadNumber = 17, + Starting11 = false, + Team = "AC Monza" + }, + new + { + Id = new Guid("191c82af-0c51-526a-b903-c3600b61b506"), + AbbrPosition = "DM", + DateOfBirth = new DateTime(1994, 4, 12, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Guido", + LastName = "Rodríguez", + League = "La Liga", + Position = "Defensive Midfield", + SquadNumber = 18, + Starting11 = false, + Team = "Real Betis Balompié" + }, + new + { + Id = new Guid("b1306b7b-a3a4-5f7c-90fd-dd5bdbed57ba"), + AbbrPosition = "RW", + DateOfBirth = new DateTime(1995, 3, 9, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Ángel", + LastName = "Correa", + League = "La Liga", + MiddleName = "Martín", + Position = "Right Winger", + SquadNumber = 15, + Starting11 = false, + Team = "Atlético Madrid" + }, + new + { + Id = new Guid("ecec27e8-487b-5622-b116-0855020477ed"), + AbbrPosition = "AM", + DateOfBirth = new DateTime(2001, 4, 26, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Thiago", + LastName = "Almada", + League = "Major League Soccer", + MiddleName = "Ezequiel", + Position = "Attacking Midfield", + SquadNumber = 16, + Starting11 = false, + Team = "Atlanta United FC" + }, + new + { + Id = new Guid("7941cd7c-4df1-5952-97e8-1e7f5d08e8aa"), + AbbrPosition = "SS", + DateOfBirth = new DateTime(1993, 11, 15, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Paulo", + LastName = "Dybala", + League = "Serie A", + MiddleName = "Exequiel", + Position = "Second Striker", + SquadNumber = 21, + Starting11 = false, + Team = "AS Roma" + }, + new + { + Id = new Guid("79c96f29-c59f-5f98-96b8-3a5946246624"), + AbbrPosition = "CF", + DateOfBirth = new DateTime(1997, 8, 22, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Lautaro", + LastName = "Martínez", + League = "Serie A", + MiddleName = "Javier", + Position = "Centre-Forward", + SquadNumber = 22, + Starting11 = false, + Team = "Inter Milan" + }); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141721_SeedSubstitutes.cs b/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141721_SeedSubstitutes.cs new file mode 100644 index 0000000..53d8e8e --- /dev/null +++ b/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141721_SeedSubstitutes.cs @@ -0,0 +1,327 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace Dotnet.Samples.AspNetCore.WebApi.Migrations +{ + /// + public partial class SeedSubstitutes : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.InsertData( + table: "Players", + columns: new[] + { + "Id", + "AbbrPosition", + "DateOfBirth", + "FirstName", + "LastName", + "League", + "MiddleName", + "Position", + "SquadNumber", + "Starting11", + "Team" + }, + values: new object[,] + { + { + new Guid("191c82af-0c51-526a-b903-c3600b61b506"), + "DM", + new DateTime(1994, 4, 12, 0, 0, 0, 0, DateTimeKind.Utc), + "Guido", + "Rodríguez", + "La Liga", + null, + "Defensive Midfield", + 18, + false, + "Real Betis Balompié" + }, + { + new Guid("5a9cd988-95e6-54c1-bc34-9aa08acca8d0"), + "GK", + new DateTime(1986, 10, 16, 0, 0, 0, 0, DateTimeKind.Utc), + "Franco", + "Armani", + "Copa de la Liga", + "Daniel", + "Goalkeeper", + 1, + false, + "River Plate" + }, + { + new Guid("5fdb10e8-38c0-5084-9a3f-b369a960b9c2"), + "RB", + new DateTime(1998, 1, 12, 0, 0, 0, 0, DateTimeKind.Utc), + "Juan", + "Foyth", + "La Liga", + "Marcos", + "Right-Back", + 2, + false, + "Villarreal" + }, + { + new Guid("7941cd7c-4df1-5952-97e8-1e7f5d08e8aa"), + "SS", + new DateTime(1993, 11, 15, 0, 0, 0, 0, DateTimeKind.Utc), + "Paulo", + "Dybala", + "Serie A", + "Exequiel", + "Second Striker", + 21, + false, + "AS Roma" + }, + { + new Guid("79c96f29-c59f-5f98-96b8-3a5946246624"), + "CF", + new DateTime(1997, 8, 22, 0, 0, 0, 0, DateTimeKind.Utc), + "Lautaro", + "Martínez", + "Serie A", + "Javier", + "Centre-Forward", + 22, + false, + "Inter Milan" + }, + { + new Guid("7cc8d527-56a2-58bd-9528-2618fc139d30"), + "LW", + new DateTime(1988, 2, 15, 0, 0, 0, 0, DateTimeKind.Utc), + "Alejandro", + "Gómez", + "Serie A", + "Darío", + "Left Winger", + 17, + false, + "AC Monza" + }, + { + new Guid("98306555-a466-5d18-804e-dc82175e697b"), + "CB", + new DateTime(1998, 1, 18, 0, 0, 0, 0, DateTimeKind.Utc), + "Lisandro", + "Martínez", + "Premier League", + null, + "Centre-Back", + 25, + false, + "Manchester United" + }, + { + new Guid("9d140400-196f-55d8-86e1-e0b96a375c83"), + "DM", + new DateTime(1994, 6, 29, 0, 0, 0, 0, DateTimeKind.Utc), + "Leandro", + "Paredes", + "Serie A", + "Daniel", + "Defensive Midfield", + 5, + false, + "AS Roma" + }, + { + new Guid("b1306b7b-a3a4-5f7c-90fd-dd5bdbed57ba"), + "RW", + new DateTime(1995, 3, 9, 0, 0, 0, 0, DateTimeKind.Utc), + "Ángel", + "Correa", + "La Liga", + "Martín", + "Right Winger", + 15, + false, + "Atlético Madrid" + }, + { + new Guid("bbd441f7-fcfb-5834-8468-2a9004b64c8c"), + "RB", + new DateTime(1997, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), + "Gonzalo", + "Montiel", + "Premier League", + "Ariel", + "Right-Back", + 4, + false, + "Nottingham Forest" + }, + { + new Guid("c62f2ac1-41e8-5d34-b073-2ba0913d0e31"), + "GK", + new DateTime(1992, 5, 20, 0, 0, 0, 0, DateTimeKind.Utc), + "Gerónimo", + "Rulli", + "Eredivisie", + null, + "Goalkeeper", + 12, + false, + "Ajax Amsterdam" + }, + { + new Guid("d3b0e8e8-2c34-531a-b608-b24fed0ef986"), + "CM", + new DateTime(1998, 10, 5, 0, 0, 0, 0, DateTimeKind.Utc), + "Exequiel", + "Palacios", + "Bundesliga", + "Alejandro", + "Central Midfield", + 14, + false, + "Bayer 04 Leverkusen" + }, + { + new Guid("d8bfea25-f189-5d5e-b3a5-ed89329b9f7c"), + "CB", + new DateTime(1991, 6, 27, 0, 0, 0, 0, DateTimeKind.Utc), + "Germán", + "Pezzella", + "La Liga", + "Alejo", + "Centre-Back", + 6, + false, + "Real Betis Balompié" + }, + { + new Guid("dca343a8-12e5-53d6-89a8-916b120a5ee4"), + "LB", + new DateTime(1991, 10, 28, 0, 0, 0, 0, DateTimeKind.Utc), + "Marcos", + "Acuña", + "La Liga", + "Javier", + "Left-Back", + 8, + false, + "Sevilla FC" + }, + { + new Guid("ecec27e8-487b-5622-b116-0855020477ed"), + "AM", + new DateTime(2001, 4, 26, 0, 0, 0, 0, DateTimeKind.Utc), + "Thiago", + "Almada", + "Major League Soccer", + "Ezequiel", + "Attacking Midfield", + 16, + false, + "Atlanta United FC" + } + } + ); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("191c82af-0c51-526a-b903-c3600b61b506") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("5a9cd988-95e6-54c1-bc34-9aa08acca8d0") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("5fdb10e8-38c0-5084-9a3f-b369a960b9c2") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("7941cd7c-4df1-5952-97e8-1e7f5d08e8aa") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("79c96f29-c59f-5f98-96b8-3a5946246624") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("7cc8d527-56a2-58bd-9528-2618fc139d30") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("98306555-a466-5d18-804e-dc82175e697b") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("9d140400-196f-55d8-86e1-e0b96a375c83") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("b1306b7b-a3a4-5f7c-90fd-dd5bdbed57ba") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("bbd441f7-fcfb-5834-8468-2a9004b64c8c") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("c62f2ac1-41e8-5d34-b073-2ba0913d0e31") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("d3b0e8e8-2c34-531a-b608-b24fed0ef986") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("d8bfea25-f189-5d5e-b3a5-ed89329b9f7c") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("dca343a8-12e5-53d6-89a8-916b120a5ee4") + ); + + migrationBuilder.DeleteData( + table: "Players", + keyColumn: "Id", + keyValue: new Guid("ecec27e8-487b-5622-b116-0855020477ed") + ); + } + } +} diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/PlayerDbContextModelSnapshot.cs b/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/PlayerDbContextModelSnapshot.cs index d1c92e8..f831c50 100644 --- a/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/PlayerDbContextModelSnapshot.cs +++ b/src/Dotnet.Samples.AspNetCore.WebApi/Migrations/PlayerDbContextModelSnapshot.cs @@ -15,7 +15,7 @@ partial class PlayerDbContextModelSnapshot : ModelSnapshot protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "9.0.11"); + modelBuilder.HasAnnotation("ProductVersion", "10.0.5"); modelBuilder.Entity("Dotnet.Samples.AspNetCore.WebApi.Models.Player", b => { @@ -59,6 +59,366 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsUnique(); b.ToTable("Players"); + + b.HasData( + new + { + Id = new Guid("01772c59-43f0-5d85-b913-c78e4e281452"), + AbbrPosition = "GK", + DateOfBirth = new DateTime(1992, 9, 1, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Damián", + LastName = "Martínez", + League = "Premier League", + MiddleName = "Emiliano", + Position = "Goalkeeper", + SquadNumber = 23, + Starting11 = true, + Team = "Aston Villa FC" + }, + new + { + Id = new Guid("da31293b-4c7e-5e0f-a168-469ee29ecbc4"), + AbbrPosition = "RB", + DateOfBirth = new DateTime(1998, 4, 5, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Nahuel", + LastName = "Molina", + League = "La Liga", + Position = "Right-Back", + SquadNumber = 26, + Starting11 = true, + Team = "Altético Madrid" + }, + new + { + Id = new Guid("c096c69e-762b-5281-9290-bb9c167a24a0"), + AbbrPosition = "CB", + DateOfBirth = new DateTime(1998, 4, 26, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Cristian", + LastName = "Romero", + League = "Premier League", + MiddleName = "Gabriel", + Position = "Centre-Back", + SquadNumber = 13, + Starting11 = true, + Team = "Tottenham Hotspur" + }, + new + { + Id = new Guid("d5f7dd7a-1dcb-5960-ba27-e34865b63358"), + AbbrPosition = "CB", + DateOfBirth = new DateTime(1988, 2, 11, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Nicolás", + LastName = "Otamendi", + League = "Liga Portugal", + MiddleName = "Hernán Gonzalo", + Position = "Centre-Back", + SquadNumber = 19, + Starting11 = true, + Team = "SL Benfica" + }, + new + { + Id = new Guid("2f6f90a0-9b9d-5023-96d2-a2aaf03143a6"), + AbbrPosition = "LB", + DateOfBirth = new DateTime(1992, 8, 30, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Nicolás", + LastName = "Tagliafico", + League = "Ligue 1", + MiddleName = "Alejandro", + Position = "Left-Back", + SquadNumber = 3, + Starting11 = true, + Team = "Olympique Lyon" + }, + new + { + Id = new Guid("b5b46e79-929e-5ed2-949d-0d167109c022"), + AbbrPosition = "RW", + DateOfBirth = new DateTime(1988, 2, 13, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Ángel", + LastName = "Di María", + League = "Liga Portugal", + MiddleName = "Fabián", + Position = "Right Winger", + SquadNumber = 11, + Starting11 = true, + Team = "SL Benfica" + }, + new + { + Id = new Guid("0293b282-1da8-562e-998e-83849b417a42"), + AbbrPosition = "CM", + DateOfBirth = new DateTime(1994, 5, 23, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Rodrigo", + LastName = "de Paul", + League = "La Liga", + MiddleName = "Javier", + Position = "Central Midfield", + SquadNumber = 7, + Starting11 = true, + Team = "Altético Madrid" + }, + new + { + Id = new Guid("d3ba552a-dac3-588a-b961-1ea7224017fd"), + AbbrPosition = "CM", + DateOfBirth = new DateTime(2001, 1, 16, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Enzo", + LastName = "Fernández", + League = "Liga Portugal", + MiddleName = "Jeremías", + Position = "Central Midfield", + SquadNumber = 24, + Starting11 = true, + Team = "SL Benfica" + }, + new + { + Id = new Guid("9613cae9-16ab-5b54-937e-3135123b9e0d"), + AbbrPosition = "CM", + DateOfBirth = new DateTime(1998, 12, 23, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Alexis", + LastName = "Mac Allister", + League = "Premier League", + Position = "Central Midfield", + SquadNumber = 20, + Starting11 = true, + Team = "Brighton & Hove Albion" + }, + new + { + Id = new Guid("acc433bf-d505-51fe-831e-45eb44c4d43c"), + AbbrPosition = "RW", + DateOfBirth = new DateTime(1987, 6, 23, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Lionel", + LastName = "Messi", + League = "Ligue 1", + MiddleName = "Andrés", + Position = "Right Winger", + SquadNumber = 10, + Starting11 = true, + Team = "Paris Saint-Germain" + }, + new + { + Id = new Guid("38bae91d-8519-55a2-b30a-b9fe38849bfb"), + AbbrPosition = "CF", + DateOfBirth = new DateTime(2000, 1, 30, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Julián", + LastName = "Álvarez", + League = "Premier League", + Position = "Centre-Forward", + SquadNumber = 9, + Starting11 = true, + Team = "Manchester City" + }, + new + { + Id = new Guid("5a9cd988-95e6-54c1-bc34-9aa08acca8d0"), + AbbrPosition = "GK", + DateOfBirth = new DateTime(1986, 10, 16, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Franco", + LastName = "Armani", + League = "Copa de la Liga", + MiddleName = "Daniel", + Position = "Goalkeeper", + SquadNumber = 1, + Starting11 = false, + Team = "River Plate" + }, + new + { + Id = new Guid("c62f2ac1-41e8-5d34-b073-2ba0913d0e31"), + AbbrPosition = "GK", + DateOfBirth = new DateTime(1992, 5, 20, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Gerónimo", + LastName = "Rulli", + League = "Eredivisie", + Position = "Goalkeeper", + SquadNumber = 12, + Starting11 = false, + Team = "Ajax Amsterdam" + }, + new + { + Id = new Guid("5fdb10e8-38c0-5084-9a3f-b369a960b9c2"), + AbbrPosition = "RB", + DateOfBirth = new DateTime(1998, 1, 12, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Juan", + LastName = "Foyth", + League = "La Liga", + MiddleName = "Marcos", + Position = "Right-Back", + SquadNumber = 2, + Starting11 = false, + Team = "Villarreal" + }, + new + { + Id = new Guid("bbd441f7-fcfb-5834-8468-2a9004b64c8c"), + AbbrPosition = "RB", + DateOfBirth = new DateTime(1997, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Gonzalo", + LastName = "Montiel", + League = "Premier League", + MiddleName = "Ariel", + Position = "Right-Back", + SquadNumber = 4, + Starting11 = false, + Team = "Nottingham Forest" + }, + new + { + Id = new Guid("d8bfea25-f189-5d5e-b3a5-ed89329b9f7c"), + AbbrPosition = "CB", + DateOfBirth = new DateTime(1991, 6, 27, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Germán", + LastName = "Pezzella", + League = "La Liga", + MiddleName = "Alejo", + Position = "Centre-Back", + SquadNumber = 6, + Starting11 = false, + Team = "Real Betis Balompié" + }, + new + { + Id = new Guid("dca343a8-12e5-53d6-89a8-916b120a5ee4"), + AbbrPosition = "LB", + DateOfBirth = new DateTime(1991, 10, 28, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Marcos", + LastName = "Acuña", + League = "La Liga", + MiddleName = "Javier", + Position = "Left-Back", + SquadNumber = 8, + Starting11 = false, + Team = "Sevilla FC" + }, + new + { + Id = new Guid("98306555-a466-5d18-804e-dc82175e697b"), + AbbrPosition = "CB", + DateOfBirth = new DateTime(1998, 1, 18, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Lisandro", + LastName = "Martínez", + League = "Premier League", + Position = "Centre-Back", + SquadNumber = 25, + Starting11 = false, + Team = "Manchester United" + }, + new + { + Id = new Guid("9d140400-196f-55d8-86e1-e0b96a375c83"), + AbbrPosition = "DM", + DateOfBirth = new DateTime(1994, 6, 29, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Leandro", + LastName = "Paredes", + League = "Serie A", + MiddleName = "Daniel", + Position = "Defensive Midfield", + SquadNumber = 5, + Starting11 = false, + Team = "AS Roma" + }, + new + { + Id = new Guid("d3b0e8e8-2c34-531a-b608-b24fed0ef986"), + AbbrPosition = "CM", + DateOfBirth = new DateTime(1998, 10, 5, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Exequiel", + LastName = "Palacios", + League = "Bundesliga", + MiddleName = "Alejandro", + Position = "Central Midfield", + SquadNumber = 14, + Starting11 = false, + Team = "Bayer 04 Leverkusen" + }, + new + { + Id = new Guid("7cc8d527-56a2-58bd-9528-2618fc139d30"), + AbbrPosition = "LW", + DateOfBirth = new DateTime(1988, 2, 15, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Alejandro", + LastName = "Gómez", + League = "Serie A", + MiddleName = "Darío", + Position = "Left Winger", + SquadNumber = 17, + Starting11 = false, + Team = "AC Monza" + }, + new + { + Id = new Guid("191c82af-0c51-526a-b903-c3600b61b506"), + AbbrPosition = "DM", + DateOfBirth = new DateTime(1994, 4, 12, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Guido", + LastName = "Rodríguez", + League = "La Liga", + Position = "Defensive Midfield", + SquadNumber = 18, + Starting11 = false, + Team = "Real Betis Balompié" + }, + new + { + Id = new Guid("b1306b7b-a3a4-5f7c-90fd-dd5bdbed57ba"), + AbbrPosition = "RW", + DateOfBirth = new DateTime(1995, 3, 9, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Ángel", + LastName = "Correa", + League = "La Liga", + MiddleName = "Martín", + Position = "Right Winger", + SquadNumber = 15, + Starting11 = false, + Team = "Atlético Madrid" + }, + new + { + Id = new Guid("ecec27e8-487b-5622-b116-0855020477ed"), + AbbrPosition = "AM", + DateOfBirth = new DateTime(2001, 4, 26, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Thiago", + LastName = "Almada", + League = "Major League Soccer", + MiddleName = "Ezequiel", + Position = "Attacking Midfield", + SquadNumber = 16, + Starting11 = false, + Team = "Atlanta United FC" + }, + new + { + Id = new Guid("7941cd7c-4df1-5952-97e8-1e7f5d08e8aa"), + AbbrPosition = "SS", + DateOfBirth = new DateTime(1993, 11, 15, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Paulo", + LastName = "Dybala", + League = "Serie A", + MiddleName = "Exequiel", + Position = "Second Striker", + SquadNumber = 21, + Starting11 = false, + Team = "AS Roma" + }, + new + { + Id = new Guid("79c96f29-c59f-5f98-96b8-3a5946246624"), + AbbrPosition = "CF", + DateOfBirth = new DateTime(1997, 8, 22, 0, 0, 0, 0, DateTimeKind.Utc), + FirstName = "Lautaro", + LastName = "Martínez", + League = "Serie A", + MiddleName = "Javier", + Position = "Centre-Forward", + SquadNumber = 22, + Starting11 = false, + Team = "Inter Milan" + }); }); #pragma warning restore 612, 618 } diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/Program.cs b/src/Dotnet.Samples.AspNetCore.WebApi/Program.cs index 8e247cc..d4c04bf 100644 --- a/src/Dotnet.Samples.AspNetCore.WebApi/Program.cs +++ b/src/Dotnet.Samples.AspNetCore.WebApi/Program.cs @@ -1,4 +1,6 @@ +using Dotnet.Samples.AspNetCore.WebApi.Data; using Dotnet.Samples.AspNetCore.WebApi.Extensions; +using Microsoft.EntityFrameworkCore; using Serilog; /* ----------------------------------------------------------------------------- @@ -49,6 +51,17 @@ var app = builder.Build(); +/* ----------------------------------------------------------------------------- + * Database Migration + * https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/applying#apply-migrations-at-runtime + * -------------------------------------------------------------------------- */ + +await using (var scope = app.Services.CreateAsyncScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + await db.Database.MigrateAsync(); +} + /* ----------------------------------------------------------------------------- * Middlewares * https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/appsettings.Development.json b/src/Dotnet.Samples.AspNetCore.WebApi/appsettings.Development.json index b749dbc..ce72bc9 100644 --- a/src/Dotnet.Samples.AspNetCore.WebApi/appsettings.Development.json +++ b/src/Dotnet.Samples.AspNetCore.WebApi/appsettings.Development.json @@ -1,7 +1,12 @@ { "Serilog": { "Using": ["Serilog.Sinks.Console", "Serilog.Sinks.File"], - "MinimumLevel": "Information", + "MinimumLevel": { + "Default": "Information", + "Override": { + "Microsoft.EntityFrameworkCore.Database.Command": "Information" + } + }, "WriteTo": [ { "Name": "Console", diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/appsettings.json b/src/Dotnet.Samples.AspNetCore.WebApi/appsettings.json index b749dbc..699816c 100644 --- a/src/Dotnet.Samples.AspNetCore.WebApi/appsettings.json +++ b/src/Dotnet.Samples.AspNetCore.WebApi/appsettings.json @@ -1,7 +1,12 @@ { "Serilog": { "Using": ["Serilog.Sinks.Console", "Serilog.Sinks.File"], - "MinimumLevel": "Information", + "MinimumLevel": { + "Default": "Information", + "Override": { + "Microsoft.EntityFrameworkCore.Database.Command": "Warning" + } + }, "WriteTo": [ { "Name": "Console", diff --git a/src/Dotnet.Samples.AspNetCore.WebApi/storage/players-sqlite3.db b/src/Dotnet.Samples.AspNetCore.WebApi/storage/players-sqlite3.db deleted file mode 100644 index b8899ac..0000000 Binary files a/src/Dotnet.Samples.AspNetCore.WebApi/storage/players-sqlite3.db and /dev/null differ diff --git a/test/Dotnet.Samples.AspNetCore.WebApi.Tests/Utilities/DatabaseFakes.cs b/test/Dotnet.Samples.AspNetCore.WebApi.Tests/Utilities/DatabaseFakes.cs index 5c1af3f..ec0fc99 100644 --- a/test/Dotnet.Samples.AspNetCore.WebApi.Tests/Utilities/DatabaseFakes.cs +++ b/test/Dotnet.Samples.AspNetCore.WebApi.Tests/Utilities/DatabaseFakes.cs @@ -6,10 +6,10 @@ namespace Dotnet.Samples.AspNetCore.WebApi.Tests.Utilities { /// - /// A Fake is a working implementation that’s simpler than the real one. - /// It usually has some “real” logic but is not suitable for production + /// A Fake is a working implementation that's simpler than the real one. + /// It usually has some "real" logic but is not suitable for production /// (e.g., an in‑memory database instead of a full SQL Server). Fakes are - /// useful when you need behavior that’s closer to reality but still want + /// useful when you need behavior that's closer to reality but still want /// to avoid external dependencies. /// public static class DatabaseFakes @@ -44,32 +44,13 @@ DbContextOptions dbContextOptions } /// - /// Creates the database schema for the test database. + /// Applies all pending EF Core migrations to the test database, including seed data. /// Extension method for PlayerDbContext. /// /// The PlayerDbContext instance. - public static void CreateTable(this PlayerDbContext context) + public static async Task MigrateAsync(this PlayerDbContext context) { - using var cmd = context.Database.GetDbConnection().CreateCommand(); - cmd.CommandText = - @" - CREATE TABLE players ( - id INTEGER PRIMARY KEY, - firstName TEXT NOT NULL, - /* ... other columns ... */ - )"; - cmd.ExecuteNonQuery(); - } - - /// - /// Seeds the test database with the starting 11 players. - /// Extension method for PlayerDbContext. - /// - /// The PlayerDbContext instance. - public static void Seed(this PlayerDbContext context) - { - context.Players.AddRange(PlayerFakes.MakeStarting11()); - context.SaveChanges(); + await context.Database.MigrateAsync(); } } }