November 22, 2024
3 min

6 Tips for Migrating Bubble.io to PostgreSQL Database (2024 Guide)

6 Tips for Easier Bubble.io to PostgreSQL Database Migration

Thinking about migrating your Bubble.io app to use an external PostgreSQL database? While Bubble.io is great for rapid development, there may come a time when you need to scale or integrate with external systems. Here are five practical tips to make your migration journey smoother.

1. Be Strategic with Option Sets


One of the trickiest parts of migration is dealing with Bubble's option sets. In PostgreSQL, these typically become ENUM types or simple text strings. To make your future migration easier, stick to using option sets only for string constants (like predefined categories, status types, or color choices). Avoid using option sets for numbers or complex data types – this will save you countless hours of data transformation later.

2. Structure Your Privacy Rules Thoughtfully


Privacy rules in Bubble need to map to row-based security in PostgreSQL. Here's a pro tip: name your privacy rules based on roles rather than permissions. Instead of "allow_users_to_read_customer_data", use role-based names like "client_manager" or "admin". This makes it much easier to translate your security model to PostgreSQL's row-level security system.

3. Be Cautious with Two-Way Joins


While Bubble makes two-way relationships feel natural (like books having authors and authors having books), implementing these in PostgreSQL with proper referential integrity can be challenging. Only use two-way joins when absolutely necessary, and document when you're creating joins specifically for privacy rules. Sometimes, it's easier to refactor these relationships during migration rather than maintaining complex bidirectional relationships.

4. Consider Your Table Types


Think about how your data changes over time. You essentially have two types of tables:
- Log-style tables that grow by appending (like transaction histories)
- Frequently updated tables with changing records (like user profiles)

Log-style tables are much easier to migrate and sync because you can simply track the last synchronized record. For frequently updated tables, keep them as small as possible and minimize the number of frequently changing fields.

5. Plan Your Naming Conventions Early


Unlike Bubble, where renaming things is relatively painless, changing table or column names in PostgreSQL can be risky and time-consuming. Establish clear naming conventions early in your Bubble development that will work well in PostgreSQL. This forethought will save you significant refactoring work during migration.

Remember, while Bubble.io doesn't enforce referential integrity like PostgreSQL does, this isn't a limitation – it's just a different approach. Moving to PostgreSQL gives you additional data integrity tools, but it requires careful planning to implement them effectively.

By following these tips during your Bubble.io development, you'll be setting yourself up for a smoother transition when it's time to migrate to PostgreSQL. Your future self will thank you for the forethought!

6. Plan for changing your File Storage


It's convenient to use Bubble for file storage. It's likely a time will come when you want to use alternative external storage - like Supabase - or any S3 bucket service (AWS, Wasabi, Backblaze - there are numerous). When you do you need a way to manage the change in the location of the files - the URL to the file.

Rather than store on your Bubble tables the "Image" or "File" Bubble type - create your own table to describe the files your are storing, and where they are being stored under which keys - ie Bucket Provider, and bucket name (eg Bubble and blank when you get started), the URL to the object, and other meta data about the file stored, especially the content-type. Then when you come to migrating of the File Store, you can map into this table the new Storage provider, bucket name, URL.