How to Deploy Azure SQL database using dacpac and Azure DevOps

 



Prerequisites 

  1. Azure SQL Server with a source and target database instance
  2. GitHub repo
  3. Visual code for SQL Server Database Objects
  4. Familiarity about dacpac
  5. Azure DevOps Account
Things I didn't check 
Since I was an admin on azure, DevOps, I am not sure on the permissions required. Ideally contrubutor access should be enough to implement this solution. 

Problem Statement and Solution

We are using dacpac for deploying our SQL artifacts from source to target server/database. The SQL server code, as well as the dacpac, is checked inside the GitHub repo. We need to develop an azure DevOps pipeline that uses the dacpac and does the deployment. 

I have found if you change the dacpac location to a custom folder and sync it to the Github repo, we could achieve what we had set out to. 

Logical Steps

1. Create a SSDT project 

2. Link SSDT to github repo with a local repo

3. Create a folder for dacpac in local repo

4. Add settings in visual studio to point dacpac creation to this folder

5. Build the solution

6. Dacpac should be created in the new folder

7. Push the code and sync it to github repo

8. Verify the new folder is available in github repo

9. Create a devops pipeline with dacpac option 

10. Configure and link it to github repo/branch

11. Test and run the pipeline on target server/database

12. SQL Objects should be deployed and should be available on the target server/database

DEMO

1. Create a new repo inside GitHub



 




2. Create a new SQL Server Database Project









3. Import source database 














4. Link it to GitHub repo and push the code to the newly created repository.


















5. Confirm if the code is checked in 











6. Change the build output path (this will be the path where dacpac will be created)












7. Create a new folder and specify this as build path













8. Build the solution to create dacpac and confirm if its created.
























9. Push and Sync these changes to GitHub repo












10. Login to azure DevOps account. Navigate to org-->project-->release pipeline










11. Click on create a pipeline and select GitHub as the source

















12. Link it to your GitHub repo and branch












13. Create an empty job















14. Save the pipeline











15. Add a step for azure sql server deployment





16. Configure all the details such as subscription, server user name and password, target database (which SQL objects need to be deployed)













17. Run the pipeline
















18. It's good that we got this error, we need to change the project settings to azure SQL Server project













19. Run the pipeline again and ensure it is successful. 














20. Compare target database with the source to verify if the deployment was successful.















Hope this was helpful, let me know your suggestions or any blockers where you might have got stuck!

Happy programming!

Comments

  1. Full demo available here

    https://www.youtube.com/watch?v=rKhEWQK-VQo

    ReplyDelete

Post a Comment

Popular posts from this blog

Issues Integrating Azure Data Factory with GITHUB | IN spite of admin rights on repository

SQL QUERY NIGHTMARE

Handling decimal and non numeric types using Case statement