Data Management

Migrating from Bubble to Xano | Part 2 - Relationships, Pagination, & Sync

Summary

In this comprehensive guide, we'll walk you through the process of setting up a seamless integration between your Bubble and Xano databases. This integration will allow you to maintain a synchronized relationship between the two platforms, ensuring consistent and up-to-date data across your applications.

Prerequisites

Before we begin, make sure you have the following:

  1. A Bubble account with an existing database
  2. A Xano account with access to the Xano dashboard
  3. The necessary API credentials and access keys for both platforms

Part 1: Initial Setup and Data Ingestion

In the first part of this tutorial, we set up a basic synchronization between the Bubble and Xano databases, ingesting all records from the Bubble API response. If you haven't completed this step, refer to the previous guide on setting up the initial data ingestion.

Part 2: Maintaining Relationships

In this section, we'll focus on setting up and maintaining relationships between the Bubble and Xano databases. We'll cover how to handle company and deal relationships, as well as deal with pagination to ensure all records are synchronized.

Step 1: Identify Existing Relationships

First, let's identify the existing relationships in your Bubble database. In our example, we have a `company` relationship and a `deal` relationship associated with the `customers` table.

Inside the Xano `customers` table, we have corresponding table relationships set up with `company_id` and `deal_id` fields.

Step 2: Set Up Conditional Checks for Relationships

To maintain these relationships in Xano, we'll use conditional checks to verify if a relationship exists before adding or updating records. Here's how we'll do it:

  1. Create a conditional group within the existing `for each` loop that iterates over the `customers` records.
  2. Use the `get` filter to check if the `company` relationship exists for the current customer record.
  3. If the `company` relationship exists (doesn't equal `null`), add the record to the `companies` table in Xano using the `add or edit record` step.
  4. Retrieve the Xano ID of the newly added or existing `company` record from the output.
  5. Repeat steps 2-4 for the `deal` relationship, adding records to the `deals` table in Xano.

By following this approach, we ensure that relationships are only created or updated in Xano if they exist in the Bubble data.

Step 3: Handle Pagination

To handle pagination and ensure all records are synchronized, we'll use a `while` loop instead of a `for each` loop. Here's how it works:

  1. Create a `pagination_continue` variable and set it to `true`.
  2. Create a `cursor_count` variable and initialize it to `0`.
  3. Set up a `while` loop that continues running as long as `pagination_continue` is `true`.
  4. Inside the `while` loop, include the logic for adding customer records and handling relationships (from the previous steps).
  5. After processing the current set of records, increment the `cursor_count` by the number of records processed (e.g., 100).
  6. Update the API request URL with the `cursor_count` parameter to fetch the next set of records.
  7. Check if the `remaining_record_count` from the API response is `0`. If so, set `pagination_continue` to `false` to stop the loop.

By implementing this pagination logic, you'll be able to fetch and process all records from the Bubble API, regardless of the total number of records.

Step 4: Handle List of Relationships

In some cases, you may have a list of relationships associated with a record. In our example, we have a `list_of_deals` relationship in the Bubble data. To handle this, follow these steps:

  1. Check if the `list_of_deals` exists and is not `null` for the current customer record.
  2. If it exists, create an empty array to store the Xano IDs of the associated deals.
  3. Iterate over the `list_of_deals` and perform the following for each deal:
  • Check if the deal exists in the `deals` table in Xano using the `add or edit record` step.
  • If the deal doesn't exist, add it to the `deals` table.
  • Retrieve the Xano ID of the deal from the output.
  • Add the Xano ID to the array created in step 2.
  1. After iterating over all deals, add the array of Xano IDs to the `deals_list` field in the `customers` table.

By following these steps, you'll ensure that the list of relationships is properly maintained in the Xano database.

Part 3: Automating the Synchronization Process

Now that we've set up the logic for synchronizing data between Bubble and Xano, it's time to automate the process using Xano's task feature.

  1. Navigate to the Tasks section in the Xano dashboard.
  2. Create a new task, e.g., "Bubble Customer Sync."
  3. In the task configuration, set the desired timing (e.g., daily at a specific time) for the synchronization to occur.
  4. Select the function you created in the previous steps from the "Custom Functions" section.
  5. Publish and enable the task.

Once enabled, the task will run according to the specified schedule, keeping your Bubble and Xano databases synchronized.

Conclusion

Congratulations! You've successfully set up a seamless integration between your Bubble and Xano databases, maintaining relationships and ensuring consistent data across both platforms. This integration will streamline your development process and provide a solid foundation for building robust applications.

Remember, if you encounter any issues or have suggestions for improvement, feel free to leave a comment or reach out to the community for support. Happy coding!

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