Database deployment using GitHub Actions - Blogs
X
06Oct

Database deployment using GitHub Actions

In this blog, I will be showing how to export the database file from SQL Server and import the same in another SQL server. When we do the export, we will be having 2 different file formats i.e DACPAC and BACPAC. The major difference between is DACPAC copies only schema whereas BACPAC copies both schema and data.

Export the bacpac file from sql server using SSMS
1.    Connect to SQL server using SSMS by providing the credentialsn
2.    Right Click on database -> Task -> Export data tier application
3.    Save the bacpac at required location.
11

At this point we have extracted the schema along with data from the database and stored in bacpac file.

Note: If we select Extract data tier application from the task, we will only be getting dacpac file i.e. we will only be getting schema of the database.

Next, we will push our backup file stored in GitHub along with the source code of the respective application in GitHub.

Before restoring the database, we need to have sqlpackage installed on the machine from where we will be initiating the import task, once the package is installed, we can proceed with the restoration part. 

What is SQLPACKAGE??

SQLPACKAGE.EXE is a command line utility that can be helpful for automations of various database deployment task. Mainly it can be used to export and import Data-tier Applications.

For more information on sql package checkout the below reference:

https://docs.microsoft.com/en-us/sql/tools/sqlpackage

When using the above utility, you must be using various options along with it. Above link can be helpful in using the utility and it also provides few examples which can be handy while using the package. Installing the sqlpackage can be done manually (for self-hosted runners) using this link or else we can do the same using the setup-sqlpackage action from the GitHub marketplace.

Below is the sample snippet for installing the sqlpackage using action from marketplace and command/action to import the database on the target sql server.

jobs:
  build:
    runs-on: windows-latest
    steps:
    - name: Checkout the source code
      uses: actions/checkout@v2

    - name: setup-sqlpackage
      uses: coreywebber/setup-sqlpackage@v1.0.0

    - name: Restoring the database
      run: sqlpackage /Action:Import /sf:${{github.workspace}}\partsnew.bacpac /tsn:${{secrets.DB_SERVER}} /tdn:${{env.database}} /tu:${{env.db_user}} /tp:${{ secrets.db_password }} /p:DatabaseMaximumSize=2 /p:DatabaseEdition=Basic

In the above snippet, I am executing all my tasks on windows runner machine (GitHub runner). Then in the tasks section, we need to check out the code from the repository using checkout action and then we will be installing the sqlpacakage utility on the same machine. Next, step will be the important step where we need to prepare the command to restore the database. I have prepared a command based on my requirement by providing the required options. Here, various options for the command have been passed as a GitHub action variable (using secrets) and some variables as environment variables in my workflow file (hidden in above snippet) and values for the variable are provided in respective sections.

Once everything is setup, we can trigger the action.

Special note: When importing to Azure SQL Server you will need to validate the database configuration that will be used with the utility (sqlpackage). Most important are the max size of the database which will define the size and the edition.

 For example, using /p:DatabaseMaximumSize=150 will result in a premium SKU edition with a database size of 150 GB. Please do not forget this because Azure SQL DB can be costly.

Related

Bugzilla to TFS Migrator (Part 3 of 4) – Configuration

This is the third part of the Bugzilla to TFS Migrator blog series covering the configuration of the...

Read More >

India’s First - Microsoft Gold Competency in Application Lifecycle Management

By earning the Microsoft Gold Competency in Application Lifecycle Management, Canarys became the Fir...

Read More >

Azure Consulting Service

We are Microsoft Cloud Solution Providers (CSP) Canarys helps you achieve higher productivity, ...

Read More >

VSTS Team project Monitor

Let us discuss how to install VSTS team project monitor and how we can make use of it easily.Particu...

Read More >

HOW TO DO BACKUP AND RESTORE ENTIRE K8S CLUSTER?

If you have deployed different applications on k8s cluster using various objects like deployments, p...

Read More >

Microsoft Azure : Running JAVA Web Application using template

We will create Java web app in Azure App Service by using the Azure portal. The Azure...

Read More >

Deploying an Outlook 2010 Add-in Using C#.NET And Visual Studio 2010

How to deploy an Outlook 2010 Add-in Using C#.NET And Visual Studio 2010In the previous blog, we wal...

Read More >

How to make your software demos effective.

 I have been involved in Software demonstrations for the last 15+ years. I have done a lot of s...

Read More >

Microsoft Dynamics ERP & CRM Solutions

Canarys has been a prominent Microsoft Dynamics NAV partner since the inception of the practice. We ...

Read More >

Share

Try DevOpSmartBoard Ultimate complete Azure DevOps End-to end reporting tool

Sign Up

  • Recent
  • Popular
  • Tag
Tags
Monthly Archive
Subscribe
Name

Text/HTML
Contact Us
  • *
  • *