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

How to Install TestNG framework (Step by Step installation process)

Steps to Install Eclipse using install new Software:Step 1: In Eclipse, on top menu bar, Under Help ...

Read More >

Azure Function : A quick start with database

This blog intended to see how Azure Functions can be used with database.Azure Function is a solution...

Read More >

Animation with Xamarin Forms

In this Article I am going to show you how we can add animation in our Xamarin Forms Application.

Read More >

⚡ Angular — Protect your unsaved data

using CanDeactivate class route guard to prevent users from navigating with unsaved entries.

Read More >

Introduction on SignalR

Introduction on SignalRReal–Time Web ApplicationThe real-time web is a set of technologies tha...

Read More >

Microsoft Azure Webinars Registration

Date : 28th Jan 2016 | Day  : Thursday | Time : 03:30 PM IST | Duration : 1 HourREGISTER yourse...

Read More >

Overview of Microsoft Dynamics CRM 2013

What is CRM  Today’s world is fast changing and full of challenges, which fundamenta...

Read More >

Introduction to KnockOut.Js in Asp.Net

What is KnockOut.Js?Knockout.Js (simply KO) is a powerful JavaScript library which allows developers...

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
Text/HTML
Contact Us
  • *
  • *