Xata
Connecting to Xata Database from a DevZero workspace.
Comprehensive guide for connecting to Xata Workspace Database from your DevBox.
If you're more of a visual learner, check out the video tutorial!
Architecture Diagram
Xata is a serverless data platform for PostgreSQL that optimizes reliability, scalability, and developer experience. Xata provides features that make it easier to build modern applications, such as Branching, Zero-downtime schema migrations, File attachments, and more. In this guide, we will walk you through the entire process of connecting your Xata Database to your DevBox step by step.
Prerequisites
Before you begin, create your account with Xata and create a new Workspace.
Existing Xata Database - PostgreSQL
Step 1: Creating the API Key
First, you need to get the API access key so that we can connect to the Database:
- Go to Xata Account Settings.
- In the Personal API keys section, click on Add a key and enter the name of the key.
- Note down the secret API key.
Step 2: Creating the Recipe for Workspace
You will need to create a Recipe in DevZero equipped with the necessary tools like psql and store your API keys as well:
- Go to DevZero Dashboard and open the Recipes tab.
- Click on New Recipe and enter the recipe's name.
- Click on Create a recipe, and your recipe will be created.
- Replace the recipe
yaml
file with the snippet below. Remember to replace the placeholder API key with the key you noted down in the above steps:
- After editing the recipe, click on Save and Build.
- When the build is successful, click on Launch.
- With the recipe already selected, click on Launch and your workspace will be created.
Step 3: Connecting to the Database
Follow the below steps to connect to the database instance:
- Go to Xata Dashboard.
- Open the Database that you want to access through DevBox.
- Copy the connection string for PostgreSQL endpoint and then use the following command to connect to the Database:
New Xata Database - PostgreSQL
If you need to make a new Xata database and access it through DevBox, then follow the below steps:
Step 1: Creating a Workspace Database
- Go to Xata Dashboard.
- If you haven't created a database, the dashboard will automatically prompt you to create one, but if you have completed the initial setup, you need to click on Add Database.
- Enter the database Name, choose the Region and enable the Enable direct access to Postgres option.
- Click on Create, and your Database will be created and shown on your dashboard.
Step 2: Creating the API Key
First, you need to get the API access key so that we can connect to the Database:
- Go to Xata Account Settings.
- In the Personal API keys section, click on Add a key and enter the name of the key.
- Note down the secret API key.
Step 3: Creating the Recipe for Workspace
You will need to create a Recipe in DevZero equipped with the necessary tools like psql
and store your API keys as well:
- Go to DevZero Dashboard and open the Recipes tab.
- Click on New Recipe and enter the recipe's name.
- Click on Create a recipe, and your recipe will be created.
- Replace the recipe
yaml
file with the snippet below. Remember to replace the placeholder API key with the Key you noted down in the above steps:
- After editing the recipe, click on Save and Build.
- When the build is successful, click on Launch.
- With the recipe already selected, click on Launch and your workspace will be created.
Step 4: Connecting to the Database
Follow the below steps to connect to the database instance:
- Go to Xata Dashboard.
- Open the database which you want to access through the DevBox.
- Copy the connection string for PostgreSQL endpoint and then use the following command to connect to the database: