Today I have a .NET 6 application that uses the Code First approach to the database, where I generate migrations and put my code on GitHub.
I use GitHub Actions to deploy my application using a .yml file:
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
name: Build and deploy ASP.Net Core app to Azure Web App - petshop-dogstyle-api
on:
push:
branches:
- master
jobs:
build-and-deploy:
runs-on: windows-latest
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- uses: actions/checkout@v2
- name: Set up .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.x'
include-prerelease: true
- name: Build with dotnet
run: dotnet build --configuration Release
- name: Install EF Tool
run: |
dotnet new tool-manifest
dotnet tool install dotnet-ef
- name: dotnet publish
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
- name: Generate scripts
run: dotnet ef migrations script --output ${{env.DOTNET_ROOT}}/sql/migration-script.sql --idempotent --project PetShop.API
- name: Azure SQL Deploy
uses: Azure/[email protected]
with:
# Name of the Azure SQL Server name, like dotnetthoughts.database.windows.net.
server-name: tcp:petshop-sqlserver.database.windows.net
# The connection string, including authentication information, for the Azure SQL Server database.
connection-string: ${{ secrets.CONNECTION_STRING }}
# Path to SQL script file to deploy
sql-file: ${{env.DOTNET_ROOT}}/sql/migration-script.sql
- name: Run Azure webapp deploy action using publish profile credentials
uses: azure/webapps-deploy@v2
with:
app-name: 'petshop-dogstyle-api'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_394CE20008F94B01AF05CA0673305854 }}
package: ${{env.DOTNET_ROOT}}/myapp
But because Azure doesn't have the option to have a free database, I'm migrating it to Heroku and using Postgres.
But I don't know how to run my migrations script on Heroku. How can I do this?