Data Management

Migrate Data Between Data Source Environments

Summary

If you're using the Xano Scale plan, you have access to different data source environments, such as Live and Test. While these environments share the same schema, the data itself is not automatically transferred between them. In this guide, we'll walk you through the steps to migrate data from your Live environment to your Test environment (or vice versa) using Xano's API and visual builder.

Step 1: Access Your Data Source Environments

  1. Log into your Xano account and navigate to the Data Sources section.
  2. Switch between your Live and Test environments using the toggle at the top of the page.
  3. Explore the data in each environment by viewing your database tables.

Step 2: Create an API Endpoint to Fetch Live Data

  1. In the API Builder, create a new API endpoint or use an existing one.
  2. Add an "External API Request" block to your function stack.
  3. Paste the URL of the API endpoint that retrieves all records from the table you want to migrate. (You can find this by creating a new API endpoint that queries the desired table.)
  4. Add a header to the request with the key `X-Data-Source` and the value `live` to specify that you want to fetch data from the Live environment.

Step 3: Store the Live Data in a Variable

  1. After the "External API Request" block, add a new variable to store the fetched data.
  2. Use the `.result` subpath to access the array of records returned by the API endpoint.
  3. You can test this by adding a "Return Value" block and running the API endpoint in the debugger to ensure the variable contains the expected data.

Step 4: Loop Through the Live Data and Insert into Test Environment

  1. Add a "For Each" loop block to your function stack, using the variable containing the live data as the input array.
  2. Inside the loop, add a "Database Request" block to insert a new record into the corresponding table in your Test environment.
  3. Map the input fields of the "Database Request" block to the properties of the current item in the loop (e.g., `item.name`, `item.description`).
  4. Make sure the "Database Request" block is set to use the Test data source environment.

Step 5: Run the API Endpoint and Verify the Migration

  1. Save your changes and run the API endpoint in the debugger.
  2. Switch to the Test environment in the Data Sources section and verify that the migrated data has been inserted into the corresponding table.

By following these steps, you can easily migrate data between your Live and Test environments in Xano, allowing you to set up realistic test scenarios or move data between environments as needed.

Remember, this process can be reversed to migrate data from the Test environment to the Live environment by adjusting the `X-Data-Source` header value and the target environment for the "Database Request" block.

This transcript was AI generated to allow users to quickly answer technical questions about Xano.

Was this helpful?

I found it helpful

I need more support
Sign up for XanoSign up for Xano

Build without limits on a secure, scalable backend.

Unblock your team’s progress and create a backend that will scale for free.

Start building for free