To interact with DoltHub from your Hosted instance, you can use DoltHub as a remote. We have SQL remote operations such as dolt_clone, dolt_pull, and dolt_push that let you interact with remotes using SQL. You can add Dolt credentials to your Hosted instance to authenticate certain operations, like cloning a private database from DoltHub or pushing changes to a DoltHub database you have write permissions to.
Hosted and DoltHub have different use cases depending on your goals, but there are also reasons to use DoltHub and Hosted together. Easily build an online application based on a crowd-sourced database on DoltHub or isolate changes to your production database and sync on your schedule.
How Dolt credentials work on Hosted
When you use Dolt on the command line to interact with DoltHub or DoltLab to pull private databases or push to databases you have permission to, you're required to run dolt login. This creates a new public/private keypair for authenticating with doltremoteapi and adds it to your global Dolt configuration. It then opens up your browser to your credential settings page on DoltHub where you can add the public key.
Since you don't have access to the command line from your Hosted instance, the process for adding credentials is a little different. When you create a deployment and select "Expose Dolt credentials" or add credentials to an existing deployment, our deployment manager service will generate Dolt credentials and add them to the global Dolt configuration on your instance. We store the public key so it is available in the settings tab of your deployment. Once you add this key to DoltHub, you can use SQL remote commands to clone, push, pull, and fetch from public or private databases.
Example
1. Find a database on DoltHub to clone
We have an example user metrics database on DoltHub named dolthub/user_metrics. Since we don't want our metrics to be publicly accessible, the database is private.
We want to host this data on Hosted Dolt so that we can use Google Looker Studio to visualize our data. Learn more about that process here.
2. Create a new deployment on Hosted
Next, I create a new deployment on Hosted and check the Expose Dolt credentials check box from the form.
Once the deployment has started, the public key will be populated in the settings tab of the deployment page (this may take a few minutes). Note that any deployment administrator will have access to this key.
If I accidentally expose my key or decide I want to remove it, I also have those options there.
3. Add public key to DoltHub
I click on "Add to DoltHub" to add my public key to DoltHub. This will open my DoltHub credentials settings page.
4. Connect to Hosted instance and clone DoltHub database
Now that I have my credentials set up, I can connect to the Hosted instance using the information in the Connectivity tab and clone my dolthub/user_metrics database.
% mysql -h"dolthub-metrics-example.dbs.hosted.doltdb.com"-u"[username]"-p"[password]"mysql: [Warning] Using a passwordon the command line interface can be insecure.Welcome to the MySQL monitor. Commands endwith ; or \g.Your MySQL connection id is2Serverversion: 5.7.9-VitessCopyright (c) 2000, 2022, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type'help;'or'\h'for help. Type'\c'toclear the current input statement.mysql>call dolt_clone('dolthub/user_metrics');+--------+| status |+--------+| 0 |+--------+1rowinset (0.71 sec)mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || user_metrics |+--------------------+3rowsinset (0.05 sec)mysql>use user_metrics;Reading table information for completion of tableand column namesYou can turn off this feature toget a quicker startup with-ADatabase changedmysql> show tables;+------------------------+| Tables_in_user_metrics |+------------------------+| user_counts |+------------------------+1rowinset (0.04 sec)
Now I can do whatever I want with my metrics data, including following these steps to connect my Hosted instance to Looker.
5. Make changes to database on DoltHub
Finance reviews our metrics charts and finds a hole in the data suggesting an outage.
Finance decides they want to show estimated metrics for the missing days, but we don't trust Finance to have direct access to our production database. Instead, they can fill in the estimated user_counts for the missing metrics on DoltHub using the spreadsheet editor and create a pull request. They don't even need to know SQL!
6. Pull new DoltHub branch to Hosted instance for testing
We want to review the new chart from the change before we merge it to main. We can pull that branch to our Hosted instance and use it to create a new branch in Looker.
7. Make a change from Hosted and push it back to DoltHub
We are mostly satisfied with the new chart, but I want to make a small update to the metrics for one of the days. I can make the change from Hosted on a branch and push it back to DoltHub using dolt_push.