Database
PostgreSQL is used as the database, accessed via EF Core with Npgsql. The ByakkoContext is the single DbContext for the application. Connection is configured via the byakko-db connection string, which Aspire overrides automatically at runtime.
Migrations
This guide outlines how to manage database migrations using Entity Framework Core in the Umiko project.
Pre-requisites
Ensure you have the dotnet-ef tool installed globally:
dotnet tool install --global dotnet-ef
If the tool is already installed, update it to the latest version:
dotnet tool update --global dotnet-ef
Migrations
All commands should be run from the src/MadWorldEU.Byakko.Controllers.Api directory (the startup project).
Create Migration
dotnet ef migrations add <MigrationName> --context ByakkoContext --project ../MadWorldEU.Byakko.Infrastructure.Postgresql -o ../MadWorldEU.Byakko.Infrastructure.Postgresql/Migrations
Apply Migration
To apply the created migration to the database:
dotnet ef database update --context ByakkoContext --project ../MadWorldEU.Byakko.Infrastructure.Postgresql
Rollback
Listing All Migrations
To view all migrations:
dotnet ef migrations list --context ByakkoContext --project ../MadWorldEU.Byakko.Infrastructure.Postgresql
Rolling Back to a Specific Migration
To rollback to a specific migration (e.g., InitialCreate):
dotnet ef database update InitialCreate --context ByakkoContext --project ../MadWorldEU.Byakko.Infrastructure.Postgresql
Rolling Back All Migrations
To revert the database to its initial state (no migrations applied):
dotnet ef database update 0 --context ByakkoContext --project ../MadWorldEU.Byakko.Infrastructure.Postgresql
Removing the Last Migration
If you need to remove the last migration (without applying it to the database):
dotnet ef migrations remove --context ByakkoContext --project ../MadWorldEU.Byakko.Infrastructure.Postgresql -f
The -f (--force) flag skips the check that verifies the migration has not been applied to the database. Without it, the command fails if EF cannot confirm the migration is unapplied (e.g. no active database connection). Only use -f when you are certain the migration has not been applied.