Reputation: 194
In Azure DevOps, the way I used to update the SQL Server Database was with Entity Framework Core, using two tasks:
The thing is, now that I'm using a PostgreSQL database, I can't find an easy and clean way to update the database in the same way. I've seen there's another task for MySQL that does exactly the same my release pipeline task did with SQL Server, but nothing for PostgreSQL.
So I thought I could basically execute dotnet ef update database
(with its proper options set) in the pipeline, but I was wondering if there's actually a way to keep updating the database in a smooth way as I did before.
Upvotes: 5
Views: 2613
Reputation: 194
I finally got to fix it.
There are two solutions I found to fix the issue.
And this would be the YAML (in case you want to use it in out of the release pipeline):
- task: DotNetCoreCLI@2
displayName: 'dotnet custom'
inputs:
command: custom
custom: tool
arguments: 'install --global dotnet-ef --version 3.1.4 --ignore-failed-sources'
dotnet ef database update -c <DBCONTEXT> -p <PROJECT> -s <STARTUP_PROJECT> -v --no-build
You just have to add the flag -c in case you have more than one context in your project (sometimes the other DbContexts can come from some nugget packages).
Notice I added the flag --no-build since I already built the project in the build pipeline to follow good practices.
However, if I had to use SQL Server or MySQL I would use a migrations script, since the process it's much easier (you just need to generate a .sql script and then it's the only file required for deploying the migrations).
Upvotes: 5