Protect queries with Source Control
Learn how to protect and sync queries in Query Library using Source Control.
Protected queries is available on Retool Cloud and self-hosted Retool version 3.6 or later.
Using protected queries in Source Control, you can safely share queries in Query Library across multiple instances of Retool, similar to protected resources.
Prerequisites
You must set up your Source Control provider to start using protected queries.
You also need to be able to protect underlying resources if you want to share queries that depend on resources across instances. See protected resources for more.
Protect queries
To protect a query and start tracking its changes, you need to merge an initial commit for the query to your remote repository.
1. Start protecting a query
You can start protecting your resource by selecting Protect query from the dropdown menu.
When you click Protect query, Retool creates a new branch on your SCM provider.
Note that you will see a warning to protect the underlying resource if it is not protected yet. Protected queries will only work across different instances if their resources are also protected and shared.
2. Open a new pull request
After you click Open pull request, you’ll be redirected to your SCM provider to create an initial commit for the resource. This commit contains a Toolscript file with relevant details for your query.
3. Merge pull request
Query is not protected until your repository contains the files from your initial commit. After you merge this commit, the query syncs to all other instances.
Edit protected queries
Use the following steps to make changes to protected queries.
1. Select a branch to edit
When you edit a protected query, you must select a branch to edit. You can either continue on the previously selected branch or create a new branch from the menu.
2. Commit your changes
Make your changes to the query and commit your changes by clicking on the Commit button on the top right corner. Note that you have to save your changes first before you can commit. If you have unsaved changes, the commit button will be disabled.
3. Open and merge a pull request
Once you've committed your changes, open a pull request to get your changes reviewed. Click branch name in the lower left corner, and select Create pull request. You'll be redirected to your SCM provider to open a pull request. Once it's reviewed, you can merge the changes into the main branch of your repository.
After a few seconds, your changes appear in the main branch of the Retool application.
Unprotect queries
You can unprotect a query by selecting Unprotect query from the dropdown menu.
A query must be unprotected before you can delete it.