{"id":15002503,"url":"https://github.com/azure/sql-action","last_synced_at":"2025-05-16T12:12:39.833Z","repository":{"id":37605592,"uuid":"210791655","full_name":"Azure/sql-action","owner":"Azure","description":"🚀 Deploy changes to your SQL database easily with SQL projects or SQL scripts and sql-action for GitHub workflows","archived":false,"fork":false,"pushed_at":"2025-02-18T01:44:30.000Z","size":34878,"stargazers_count":118,"open_issues_count":29,"forks_count":60,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-05-16T12:12:31.673Z","etag":null,"topics":["azure","azure-sql","azure-sql-database","github-actions","sql-server"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Azure.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-09-25T08:15:34.000Z","updated_at":"2025-04-30T00:57:54.000Z","dependencies_parsed_at":"2024-01-23T23:31:19.128Z","dependency_job_id":"57cc8051-5818-4c9a-a21b-9cde4f4ea563","html_url":"https://github.com/Azure/sql-action","commit_stats":{"total_commits":127,"total_committers":27,"mean_commits":4.703703703703703,"dds":0.7637795275590551,"last_synced_commit":"e76d5506e767fee1ba59b79cfc2aaacb7e0d4000"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure%2Fsql-action","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure%2Fsql-action/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure%2Fsql-action/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure%2Fsql-action/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Azure","download_url":"https://codeload.github.com/Azure/sql-action/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254527099,"owners_count":22085919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure","azure-sql","azure-sql-database","github-actions","sql-server"],"created_at":"2024-09-24T18:50:49.614Z","updated_at":"2025-05-16T12:12:34.818Z","avatar_url":"https://github.com/Azure.png","language":"TypeScript","readme":"# Azure SQL Deploy\r\n\r\nThis repository contains the sql-action GitHub Action for deploying changes to Azure SQL Database, Azure SQL Managed Instance, or SQL Server in a dacpac, SQL scripts, or an SDK-style SQL project. With the Azure SQL Action for GitHub, you can automate your workflow to deploy updates to Azure SQL or SQL Server.\r\n\r\n\r\n\r\nGet started today with a [free Azure account](https://azure.com/free/open-source)!\r\n\r\n\r\nLooking to develop with SQL for free, locally and offline, before deploying with GitHub?  Check out the [Azure SQL local emulator](https://aka.ms/azuredbemulator) and [SQL Server Developer Edition](https://www.microsoft.com/sql-server/sql-server-downloads)!\r\n\r\n\r\n## 🚀 Usage\r\nThe definition of this GitHub Action is in [action.yml](https://github.com/Azure/sql-action/blob/master/action.yml).  Learn more in the [user guide](#📓-user-guide).\r\n\r\n```yaml\r\n- uses: azure/sql-action@v2.3\r\n  with:\r\n    # required, connection string incl the database and user authentication information\r\n    connection-string:\r\n\r\n    # required, path to either a .sql, .dacpac, or .sqlproj file\r\n    path:\r\n\r\n    # optional when using a .sql script, required otherwise\r\n    # sqlpackage action on the .dacpac or .sqlproj file, supported options are: Publish, Script, DeployReport, DriftReport\r\n    action:\r\n\r\n    # optional additional sqlpackage or go-sqlcmd arguments\r\n    arguments:\r\n\r\n    # optional SqlPackage executable location, overrides default locations\r\n    sqlpackage-path:\r\n\r\n    # optional additional dotnet build options when building a database project file\r\n    build-arguments:\r\n\r\n    # optional, set this to skip checking if the runner has access to the server. Default is false.\r\n    skip-firewall-check:\r\n```\r\n\r\n## 🎨 Samples\r\n\r\n### Build and deploy a SQL project\r\n\r\n\u003e **Note:** The database project must use the [Microsoft.Build.Sql](https://www.nuget.org/packages/microsoft.build.sql/) SDK.\r\n\r\n```yaml\r\n# .github/workflows/sql-deploy.yml\r\non: [push]\r\n\r\njobs:\r\n  build:\r\n    runs-on: ubuntu-latest\r\n    steps:\r\n    - uses: actions/checkout@v3\r\n    - uses: azure/sql-action@v2.3\r\n      with:        \r\n        connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }}\r\n        path: './Database.sqlproj'\r\n        action: 'publish'\r\n        build-arguments: '-c Release'                 # Optional build options passed to dotnet build\r\n        arguments: '/p:DropObjectsNotInSource=true'   # Optional properties and parameters for SqlPackage Publish\r\n```\r\n\r\n### Deploy SQL scripts to an Azure SQL Database with a temporary firewall rule\r\n\r\n```yaml\r\n# .github/workflows/sql-deploy.yml\r\non: [push]\r\n\r\njobs:\r\n  build:\r\n    runs-on: ubuntu-latest\r\n    steps:\r\n    - uses: actions/checkout@v3\r\n    - uses: azure/login@v1                            # Azure login required to add a temporary firewall rule\r\n      with:\r\n        creds: ${{ secrets.AZURE_CREDENTIALS }}\r\n    - uses: azure/sql-action@v2.3\r\n      with:        \r\n        connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }}\r\n        path: './sqlscripts/*.sql'\r\n```\r\n\r\n### Deploy a DACPAC to an Azure SQL database with Allow Azure Services access enabled\r\n\r\n```yaml\r\n# .github/workflows/sql-deploy.yml\r\non: [push]\r\n\r\njobs:\r\n  build:\r\n    runs-on: windows-latest\r\n    steps:\r\n    - uses: actions/checkout@v3\r\n    - uses: azure/sql-action@v2.3\r\n      with:\r\n        connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }}\r\n        path: './Database.dacpac'\r\n        action: 'publish'\r\n        arguments: '/p:DropObjectsNotInSource=true'   # Optional properties parameters for SqlPackage Publish\r\n```\r\n\r\n\r\n## 📓 User Guide\r\n\r\n### Authentication and Connection String\r\n\r\nThe v1.x version of sql-action supports SQL authentication only in the connection string. Starting in v2, AAD Password, AAD Service Principal, and AAD Default authentications are also supported.  **Read more about implementing sql-action with different authentication methods in the [connection](CONNECTION.md) guide.**\r\n\r\n### Arguments\r\n\r\nsql-action supports passing arguments to SqlPackage, go-sqlcmd, and dotnet build.\r\n- **SqlPackage**: SqlPackage publish properties are passed to the SqlPackage utility from the `arguments` property. More information on these properties is available in the [SqlPackage publish](https://docs.microsoft.com/sql/tools/sqlpackage/sqlpackage-publish#properties-specific-to-the-publish-action) documentation. SqlPackage [parameters](https://docs.microsoft.com/sql/tools/sqlpackage/sqlpackage-publish#parameters-for-the-publish-action) that do not impact the source or target setting are also valid, including `/Profile:` for a publish profile, `/DeployReportPath:` for a deployment report, and `/Variables:` to set SQLCMD variable values.\r\n- **go-sqlcmd**: go-sqlcmd parameters are passed to the go-sqlcmd utility from the `arguments` property. This enables SQLCMD variables `-v` to be passed  to scripts as seen in the [go-sqlcmd documentation](https://learn.microsoft.com/sql/tools/sqlcmd/sqlcmd-utility?tabs=go%2Cwindows). Note: sql-action uses go-sqlcmd for SQL script deployments, which contains some breaking changes from the ODBC-based sqlcmd utility.\r\n- **dotnet build**: dotnet build options are passed to the SQL project build step from the `build-arguments` property. More information on options is available in the [dotnet build documentation](https://docs.microsoft.com/dotnet/core/tools/dotnet-build#options).\r\n\r\n### Environments\r\n\r\nsql-action is supported on both Windows and Linux environments.  The [default images](https://github.com/actions/virtual-environments) include the prerequisites:\r\n\r\n- sqlpackage (for sqlproj or dacpac deployment)\r\n- dotnet (for sqlproj build)\r\n\r\nOn Windows, sql-action attempts to locate SqlPackage as a dotnet tool, in the [default MSI install location](https://learn.microsoft.com/sql/tools/sqlpackage/sqlpackage-download#windows-net-framework) `C:\\Program Files\\Microsoft SQL Server\\160\\DAC\\bin`, and as a last resort for versions installed by Visual Studio. On Linux, sql-action attempts to locate SqlPackage as a dotnet tool before falling back to PATH.  In both operating systems, the input `sqlpackage-path` can be used to override the default locations. For custom images installing SqlPackage as a [dotnet tool](https://learn.microsoft.com/sql/tools/sqlpackage/sqlpackage-download#installation-cross-platform) is recommended.\r\n\r\nsql-action installs [go-sqlcmd](https://github.com/microsoft/go-sqlcmd) at runtime for SQL script deployments.\r\n\r\n### Firewall Rules/Access\r\n\r\n\u003e [!NOTE]\r\n\u003e This Firewall Rules section of the document is specific to Azure SQL Database. For Azure SQL Managed Instance and SQL Server it is recommended to review the [connection](CONNECTION.md) guide.\r\n\r\nIf you *can* use the option [Allow Azure Services and resources to access this server](https://docs.microsoft.com/azure/azure-sql/database/firewall-configure#connections-from-inside-azure) on Azure SQL Database, you are all set and you don't need to to anything else to allow GitHub Action to connect to your Azure SQL Database.\r\n\r\nIf you *cannot* use the aforementioned option on Azure SQL Database, the action can automatically add and remove a [SQL server firewall rule](https://docs.microsoft.com/azure/sql-database/sql-database-server-level-firewall-rule) specific to the GitHub Action runner's IP address. Without the firewall rule, the runner cannot communicate with Azure SQL Database. Read more about this in the [connection](CONNECTION.md) guide.\r\n\r\n\r\n#### Azure Credentials for Login (quickstart)\r\n\r\n**To enable the action to automatically add/remove a firewall rule, add an [`Azure/login`](https://github.com/Azure/login) step before the `sql-action` step.** Also, the service principal used in the Azure login action needs to have elevated permissions, i.e. membership in SQL Security Manager RBAC role, or a similarly high permission in the database to create the firewall rule. Read more about this and other authentication methods in the [connection](CONNECTION.md) guide.\r\n\r\nPaste the output of the below [az cli](https://docs.microsoft.com/cli/azure/?view=azure-cli-latest) command as the value of secret variable, for example `AZURE_CREDENTIALS`.\r\n\r\n```bash\r\naz ad sp create-for-rbac --role contributor --sdk-auth --name \"sqldeployserviceprincipal\" \\\r\n  --scopes /subscriptions/{subscription-id}/resourceGroups/{resource-group}\r\n```\r\nReplace {subscription-id}, {resource-group} with the subscription ID and resource group of the Azure SQL server\r\n\r\nThe command should output a JSON object similar to this:\r\n\r\n```\r\n{\r\n  \"clientId\": \"\u003cGUID\u003e\",\r\n  \"clientSecret\": \"\u003cGUID\u003e\",\r\n  \"subscriptionId\": \"\u003cGUID\u003e\",\r\n  \"tenantId\": \"\u003cGUID\u003e\",\r\n  // ...\r\n} \r\n```\r\n\r\n### Secrets\r\n\r\nAll the above examples use `{{secrets.AZURE_SQL}}` syntax for sensitive information, where content such as connection strings are stored in GitHub secrets. To create [secrets](https://help.github.com/en/github/automating-your-workflow-with-github-actions/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables) in GitHub, navigate within your repository to **Settings** and then **Secrets**. Be careful to check the connection string which you copy from Azure SQL as the connection string has this **Password={your_password}** and you will need to supply the correct password for your connection string.\r\n\r\n\r\n\r\n## 📦 End-to-End Examples\r\n\r\n### Create Azure SQL Database + SQL Projects\r\n\r\n1. Follow the tutorial [Azure SQL Quickstart to create a single database](https://docs.microsoft.com/azure/azure-sql/database/single-database-create-quickstart?tabs=azure-portal#create-a-single-database)\r\n2. Copy the below template and paste the contents in `.github/workflows/` in your project repository as `sql-workflow.yml`.\r\n```yaml\r\n# .github/workflows/sql-workflow.yml\r\non: [push]\r\n\r\njobs:\r\n  build:\r\n    runs-on: ubuntu-latest\r\n    steps:\r\n    - uses: actions/checkout@v3\r\n    - uses: azure/sql-action@v2.3\r\n      with:        \r\n        connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }}\r\n        path: './Database.sqlproj'\r\n        action: 'publish'\r\n```\r\n3. Place the connection string from the Azure Portal in GitHub secrets as `AZURE_SQL_CONNECTION_STRING`. Connection string format is: `Server=\u003cserver.database.windows.net\u003e;User ID=\u003cuser\u003e;Password=\u003cpassword\u003e;Initial Catalog=\u003cdatabase\u003e`.\r\n4. Copy the below SQL project template and paste the content in your project repository as `Database.sqlproj`.\r\n```xml\r\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\r\n\u003cProject DefaultTargets=\"Build\"\u003e\r\n  \u003cSdk Name=\"Microsoft.Build.Sql\" Version=\"0.1.3-preview\" /\u003e\r\n  \u003cPropertyGroup\u003e\r\n    \u003cName\u003ereactions\u003c/Name\u003e\r\n    \u003cDSP\u003eMicrosoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider\u003c/DSP\u003e\r\n    \u003cModelCollation\u003e1033, CI\u003c/ModelCollation\u003e\r\n  \u003c/PropertyGroup\u003e\r\n\u003c/Project\u003e\r\n```\r\n5. Place any additional SQL object definitions in the project folder or in subfolders.  An example table to get you started is:\r\n```sql\r\nCREATE TABLE [dbo].[Product](\r\n\t[ProductID] [int] IDENTITY(1,1) PRIMARY KEY NOT NULL,\r\n\t[Name] [nvarchar](100) NOT NULL,\r\n\t[ProductNumber] [nvarchar](25) NOT NULL,\r\n\t[Color] [nvarchar](15) NULL,\r\n\t[StandardCost] [money] NOT NULL,\r\n\t[ListPrice] [money] NOT NULL,\r\n\t[Size] [nvarchar](5) NULL,\r\n\t[Weight] [decimal](8, 2) NULL,\r\n\t[ProductCategoryID] [int] NULL,\r\n\t[ProductModelID] [int] NULL,\r\n\t[ModifiedDate] [datetime] NOT NULL\r\n)\r\n```\r\n6. Commit and push your project to GitHub repository, you should see a new GitHub Action initiated in **Actions** tab.\r\n7. For further use of SQL projects in VS Code and Azure Data Studio, check out [http://aka.ms/azuredatastudio-sqlprojects](http://aka.ms/azuredatastudio-sqlprojects) for more information.\r\n\r\n\r\n### Create Azure SQL Database + Deploy Existing Schema (dacpac)\r\n\r\n1. Create a dacpac from an existing SQL database with either [SSMS](https://docs.microsoft.com/sql/relational-databases/data-tier-applications/extract-a-dac-from-a-database), [Azure Data Studio](https://docs.microsoft.com/sql/azure-data-studio/extensions/sql-server-dacpac-extension) or [SqlPackage CLI](https://docs.microsoft.com/sql/tools/sqlpackage/sqlpackage-extract).  Place the dacpac file at the root of your repository.\r\n2. Follow the tutorial [Azure SQL Quickstart to create a single database](https://docs.microsoft.com/azure/azure-sql/database/single-database-create-quickstart?tabs=azure-portal#create-a-single-database)\r\n3. Copy the below template and paste the contents in `.github/workflows/` in your project repository as `sql-workflow.yml`, changing the dacpac file name as appropriate.\r\n```yaml\r\n# .github/workflows/sql-workflow.yml\r\non: [push]\r\n\r\njobs:\r\n  build:\r\n    runs-on: ubuntu-latest\r\n    steps:\r\n    - uses: actions/checkout@v3\r\n    - uses: azure/sql-action@v2.3\r\n      with:        \r\n        connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }}\r\n        path: './PreviousDatabase.dacpac'\r\n        action: 'publish'\r\n```\r\n4. Place the connection string from the Azure Portal in GitHub secrets as `AZURE_SQL_CONNECTION_STRING`. Connection string format is: `Server=\u003cserver.database.windows.net\u003e;User ID=\u003cuser\u003e;Password=\u003cpassword\u003e;Initial Catalog=\u003cdatabase\u003e`.\r\n5. Commit and push your project to GitHub repository, you should see a new GitHub Action initiated in **Actions** tab.\r\n\r\n\r\n## ✏️ Contributing\r\n\r\nFor more information on contributing to this project, please see [Contributing](CONTRIBUTING.md).\r\n\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazure%2Fsql-action","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazure%2Fsql-action","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazure%2Fsql-action/lists"}