GithubHelp home page GithubHelp logo

azure / run-sqlpackage-action Goto Github PK

View Code? Open in Web Editor NEW
2.0 5.0 6.0 10 KB

A GitHub Action to run the SqlPackage command line utility on any Azure Synapse, Azure SQL Database or Azure SQL Managed Instance

License: MIT License

run-sqlpackage-action's Introduction

SqlPackage command-line Action

SqlPackage.exe is a command-line utility that automates validation and deployment of database projects for SQL Server, Azure SQL Database and Azure Synapse. This actions provides support for implement CI/CD workflows on GitHub Actions for database projects running on Azure. When combined with Visual Studio Database Projects, it provides a convenient way to define the desired state of a database and apply, deploy and evolve the schema in different databases on different environments.

When to use it

Use run-sqlpackage GitHub action to implement CI/CD workflows that automate the evolution of the schema in a database running on Azure. It provides tools to validate changes, detect data integration errors, data loss issues and perform changes in target databases accross different environments.

About database projects

You can use database projects to create new databases and to update existing databases enabling you to apply version control and project management techniques to your database development efforts in much the same way that you apply those techniques to managed or native code. You can help your development team manage changes to databases and database servers by creating a database project, or a server project and putting it under version control. Members of your team can then check out files to make, build, and test changes in an isolated development environment, or sandbox, before sharing them with the team. To help ensure code quality, your team can finish and test all changes for a particular release of the database in a staging environment before you deploy the changes into production.

How SqlPackage and Database Projects work together

The output of a database project is a file in dacpac extension, which describes the final desired state of a database. SqlPackage then can use such file to detect the evolution of the schema and compute the requered changes that need to be performed in a given target database in order to make it match the given final state described in the dacpac. By doing that, you keep on asset that describes you database, while SqlPackage compute the deltas for each target database that you want to deploy to.

Getting Started

Prerequisites

  • An Azure Synapse SQL Pool, Azure SQL Database or Azure SQL Managed Instance.
  • If you are using SQL Authentication
    • A SQL Login created in the target database.
    • The SQL Login and SQL Password.
  • If you are using Azure Active Directory Authentication
    • A Service Principal created in the tenant.
    • A database user created on the target database associated with the mentioned Service Principal. Follow the documentation at Create contained users mapped to Azure AD identities
    • An authentication token issued for the mentioned Service Principal and targeting the given database. You can use the GitHub Action azure-resource-login to generate such a token.
  • A Visual Studio Database Project created either using Azure Data Studio, VS Code or Microsoft Visual Studio. See Working with an already existing database if you want to create a project based on an existing database.
  • A publishing profile in the format of an XML file indicating how deployment should be done. A sample file is provided in the repository for your convenience.

Working with an already existing database

More often than not you are not starting a new database from scratch, but you already have a database from were you want to start from. If that's the case, then you can build a database project based on such existing database. Follow the documentation Create a database project from an existing database.

Inputs

Name Description Required
action Action parameter to run with SqlPackage. Supported values are: Publish, DeployReport, DriftReport, Script. true
sourcepath The path where to look for the DACPAC file. If multiple files exists, all of them are processed. true
profile The publishing profile path to use during the execution (in xml format). true
database-server Database server URL (without protocol). If not indicated in the publishing profile, it has to be indicated here. false
database-name Database name. If not indicated in the publishing profile, it has to be indicated here. false
authtoken The authentication token used to connect to the database, if credentials not indicated in the connection string. false
outputpath The output folder where assets will be generated if any. If not indicated, the current path is used. false
outputfile The output file name. The final name of the file will be [dacpac_name].[outputfile]. The extension of the file depends on the action performed false

Example usage

Generate a deployment report

id: deploy-report
name: Identifying proposed changes
uses: Azure/[email protected]
with:
   action: 'DeployReport'
   sourcepath: build
   outputpath: reports
   outputfile: 'deployreport.xml'
   profile: profile.xml
   authtoken: ${{ steps.sql-login.outputs.token }}

Note 1: The parameter authtoken is provided as the output of another step.

Note 2: The target database is not indicated in the action but in the profile. Parameters TargetConnectionString and TargetDatabaseName need to be supplied in the file profile.xml.

Deploy changes in a target database

id: deploy-target
name: Deploying changes to target
uses: Azure/[email protected]
with:
   action: 'Publish'
   sourcepath: build
   profile: profile.xml
   authtoken: ${{ steps.sql-login.outputs.token }}

Note 1: The parameter authtoken is provided as the output of another step.

Note 2: The target database is not indicated in the action but in the profile. Parameters TargetConnectionString and TargetDatabaseName need to be supplied in the file profile.xml.

Deploy changes in a target database specified as parameters

id: deploy-target
name: Deploying changes to target
uses: Azure/[email protected]
with:
   action: 'Publish'
   sourcepath: build
   profile: profile.xml
   database-server: mysynapse.sql.azuresynapse.net
   database-name: adventureworks
   authtoken: ${{ steps.sql-login.outputs.token }}

Note 1: The parameter authtoken is provided as the output of another step.

Note 2: In this example adventureworks is a database inside of the mysynapse Synapse Workspace.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

run-sqlpackage-action's People

Contributors

microsoftopensource avatar santiagxf avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

run-sqlpackage-action's Issues

Command Not found - Exit code 127

Hello,

Working on utilizing this to automatically deploy my DB project to a SQL Azure database. However, when I try it, I'm getting the following:

_> Run Azure/[email protected]

with:
action: Publish
sourcepath: .\Northwinds\Northwinds\bin\debug
profile: .\Northwinds\Northwinds\PublishProfiles\dev.publish.xml
outputpath: .
outputfile: deployreport.xml
env:
SOLUTION_FILE_PATH: .\Northwinds\Northwinds
BUILD_CONFIGURATION: debug
Run if test -f "/opt/sqlpackage/sqlpackage"; then
if test -f "/opt/sqlpackage/sqlpackage"; then
echo "::debug::SqlPackage already installed in the context"
else
sudo apt-get install libunwind8
wget -progress=bar:force -q -O sqlpackage.zip
https://aka.ms/sqlpackage-linux
&& unzip -qq sqlpackage.zip -d /opt/sqlpackage
&& chmod a+x /opt/sqlpackage/sqlpackage
&& rm sqlpackage.zip
fi
shell: C:\Program Files\Git\bin\bash.EXE --noprofile --norc -e -o pipefail {0}
env:
SOLUTION_FILE_PATH: .\Northwinds\Northwinds
BUILD_CONFIGURATION: debug

D:\a_temp\5f5fc9d2-9be6-47c5-9d32-d9a0401fbf52.sh: line 4: sudo: command not found
Error: Process completed with exit code 127._

You should be able to find the code and runs here: GitHub\PASS2022Demo
BuildProject.txt

The BuildProject.txt is a copy of the yml action file being used.

Code in question:
- name: run-sqlpackage
uses: Azure/[email protected]
with:
action: 'Publish'
sourcepath: ${{env.SOLUTION_FILE_PATH}}\bin\debug\
profile: ${{env.SOLUTION_FILE_PATH}}\PublishProfiles\dev.publish.xml

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.