Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply EF migrations in GitHub workflow

I have a GitHub repository for my Asp Net Core project with EF Core 3.0. I added the following workflow to run each time on updating the develop branch

name: Develop Build
on:
  push:
    branches:
      - develop
  pull_request:
    branches:
      - develop
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 3.0.102-servicing-014397
    - name: Build with dotnet
      run: dotnet build --configuration Release
    - name: Test with dotnet
      run: dotnet test --configuration Release
    - name: Update database
      run: dotnet ef database update --c DataContext --p MyProj --s MyProjFactory

The last line returns with an error:

Could not execute because the specified command or file was not found.
Possible reasons for this include:
  * You misspelled a built-in dotnet command.
  * You intended to execute a .NET Core program, but dotnet-ef does not exist.
  * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
##[error]Process completed with exit code 1.

How can I apply the latest migrations to the target database using this workflow?

like image 697
Waldemar Avatar asked Mar 04 '23 02:03

Waldemar


1 Answers

I also had to add commands to install EF tool and to restore all tools to make my workflow work correctly:

- name: Update database
  run: |
    dotnet tool install --global dotnet-ef
    dotnet tool restore
    dotnet ef database update -c DataContext -p MyProj -s MyProjFactory
  env:
    ASPNETCORE_ENVIRONMENT: Development
like image 177
Waldemar Avatar answered Mar 05 '23 16:03

Waldemar