January 18, 2025
4 min

How to Set Up Supabase Branches to achieve database Versioning with Bubble.io

How to Set Up Supabase Branches to achieve Database Versioning with Bubble.io - A Complete Guide

Database versioning is crucial for maintaining separate development and production environments when building applications. In this guide, we'll explore how to effectively manage Supabase branching with Bubble.io, enabling you to maintain separate test and live databases for your application.

tl:dr

supabase db pull --db-url postgresql://postgres......
git add .
git commit -m "test auto"
git push my-db
echo "Supabase Test schema promoted to Live"

Why Use Supabase Branching with Bubble.io?

When developing applications in Bubble.io that use Supabase as an external database, you'll typically need:

  • A test environment for development and testing
  • A live environment (also known as production) for your deployed application
  • A way to safely promote changes from test to live

Supabase branching provides an elegant solution to these requirements, allowing you to maintain separate database versions for your test and live environments.

Understanding the Cost

One of the most attractive aspects of Supabase branching is its cost-effectiveness. Running a branch costs approximately $0.32 per day, or about $10 per month. This makes it an affordable solution for maintaining separate development and live databases.

How Supabase Branching Works

The Core Concept

Supabase branching works by connecting your database to a Github repository. Here's how it functions:

  1. Your Supabase database monitors a connected Github repository
  2. When changes are detected in the repository with an attached branch
  3. These changes are automatically applied to the corresponding Supabase branch

Branch Types

Supabase offers two types of branches:

  • Ephemeral branches: Temporary branches for short-term development
  • Persistent branches: Long-term branches for ongoing development and production

For Bubble.io integration, you'll want to use persistent branches for both your test and live environments.

Setting Up the Workflow

Initial Setup

  1. Create two Supabase branches:
    • A test version for development
    • A live version (production) for your deployed application eg main
  2. Connect your Bubble.io environments:
    • Point your Bubble test branch to your Supabase test database
    • Point your Bubble live branch to your Supabase live database

Development Process

  1. Make schema changes in your test environment using the Supabase web console
  2. Use Supabase CLI tools to:
    • Pull down the schema from your test branch (the CLI tooling does this all for your)
    • Generate migration scripts
    • Push changes to your Github repository

Note: While current workflow requires CLI tools, Supabase is likely to release web-based tools in the future to simplify this process. This would eliminate the need for command-line operations and make the versioning workflow more accessible to Bubble.io developers.

Promoting Changes to Live

The promotion process involves:

  1. Using CLI tools to capture schema differences
  2. Generating SQL migration scripts (ALTER, CREATE, DELETE statements)
  3. Pushing these changes to your main branch
  4. Allowing Supabase to automatically apply the changes to your live database

Important Considerations

Local Development vs. Bubble.io

Unlike traditional local development setups, when working with Bubble.io:

  • You don't need a local Supabase instance
  • You can't connect Bubble to a local PostgreSQL database
  • Meaning persistent branches rather than local development databases

Future Improvements

The current workflow relies on command-line tools, which may feel unfamiliar to many Bubble.io developers. However, Supabase is actively working on improving their tooling. We can expect to see web-based interfaces for managing database versions in the future, which will make this process much more user-friendly and accessible to no-code developers.

Conclusion

While the tooling might seem complex at first, Supabase versioning provides a robust solution for managing separate development and live databases with Bubble.io. The key is understanding that you need persistent branches rather than local development environments, and that all schema changes should be managed through your test version before promotion to live.

By following this approach, you can maintain a professional development workflow while ensuring your live environment remains stable and reliable. The affordable pricing and automatic change application make it an excellent choice for Bubble.io developers working with Supabase.

Technical Insight

An interesting observation is that this PostgreSQL versioning approach is likely similar to how Bubble.io manages its own database versioning internally. While this is an educated guess, it makes technical sense - Bubble.io needs to maintain separate database versions for test and live environments for millions of applications. Using PostgreSQL's native versioning capabilities would be an elegant and scalable solution for managing this complexity. This parallel between Supabase's versioning approach and Bubble.io's probable internal architecture shows how enterprise-grade database management techniques are becoming accessible to no-code developers.