EF Migrations
All EF related commands must be run in the context of the Infrastructure project. So first, cd into its directory:
cd apps/api/src/Eventuras.InfrastructureAdding a migration
dotnet ef migrations add MigrationDescription -s ../Eventuras.WebApi/Eventuras.WebApi.csprojThere is also a Github action that adds an release of the eventuras db tool, which can be used to run migrations from the command line. The tool is available in the release section of the eventuras.
Applying a Migration
Either run the sql script generated by the previous command or run the following command:
dotnet ef database update -s ../Eventuras.WebApi/Eventuras.WebApi.csprojIf you need to run migrations from ssh, you might use the eventurasdb tool. The efbundle is a self-contained executable that can be run on the server. It is available in the release section of the eventuras.
First add an appsettings.json file to the directory where you want to run the migrations. For example touch appsettings.json && nano appsettings.json.
The file should look like this:
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Database=eventuras;Port=5432;User Id=eventuras;Password=eventuras;Ssl Mode=Require;Trust Server Certificate=True"
},
"Sentry": {
"Dsn": ""
}
}Then run the following commands:
apt-get update
apt-get install jq
# Find the latest release of the eventurasdb tool and download it
curl -L -o eventurasdb "$(curl -s 'https://api.github.com/repos/losol/eventuras/releases' | jq -r '.[0].assets[] | select(.name == "eventurasdb") | .browser_download_url')"
chmod +x eventurasdb
./eventurasdbRead more