You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* adding migration documentation to readme
* add Aspire CLI into dependencies and added both options for adding migrations
* Add optional attribute to Aspire dependency
Co-authored-by: Daniel Mackay [SSW] <2636640+danielmackay@users.noreply.github.com>
---------
Co-authored-by: Daniel Mackay [SSW] <2636640+danielmackay@users.noreply.github.com>
3. Open https://localhost:7255/scalar/v1 in your browser to see it running ️🏃♂️
186
187
188
+
### EF Migrations
189
+
Due to .NET Aspire orchestrating the application startup and migration runner, EF migrations need to be handled a little differently to normal.
190
+
191
+
#### Adding a Migration
192
+
Adding new migrations is still the same old command you would expect, but with a couple of specific parameters to account for the separation of concerns. This can be performed via native dotnet tooling or through the Aspire CLI:
193
+
194
+
1. Run either of following commands from the root of the solution.
aspire exec --resource api -- dotnet ef migrations add YourMigrationName --project ../Infrastructure/Infrastructure.csproj --output-dir ./Persistence/Migrations
202
+
```
203
+
204
+
#### Applying a Migration
205
+
.NET Aspire handles this for you - just start the project!
206
+
207
+
#### Removing a Migration
208
+
This is where things need to be done a little differently and requires the Aspire CLI.
209
+
210
+
1. Enable the `exec` function:
211
+
212
+
```bash
213
+
aspire config set features.execCommandEnabled true
214
+
```
215
+
216
+
2. Pass the EF migration shell command through Aspire from the root of the solution:
217
+
218
+
```bash
219
+
aspire exec --resource api -- dotnet ef migrations remove --project ..\Infrastructure --force
220
+
```
221
+
> [!NOTE]
222
+
> The `--force` flag is needed because .NET Aspire will start the application when this command is run, which triggers the migrations to run. This will apply your migrations to the database, and make EF Core unhappy when it tries to delete the latest migration. This should therefore be used with caution - a safer approach is to "roll forward" and create new migrations that safely undo the undesired change(s).
0 commit comments