PlanetScale’s branching is the key to unlocking truly safe, zero-downtime deployments with your Laravel application.

Let’s see this in action. Imagine you’re about to deploy a new feature. You’ve got your main branch in PlanetScale, representing your production database schema, and your Laravel app points to it.

# In your PlanetScale dashboard, you'd see something like:
# BRANCHES:
#   main (production)
#   my-new-feature

Now, you create a new schema branch in PlanetScale called my-new-feature. This is not a copy of your data, but an independent schema definition. Your Laravel app, configured to use a separate PlanetScale connection string for this branch, can now interact with this new schema.

// .env file for your development/feature branch
DB_CONNECTION=mysql
DB_HOST=your-branch.region.planetscale.com
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_username
DB_PASSWORD=your_branch_password

You write your Laravel code, create migrations, and run them against this my-new-feature branch.

# On your local machine, connected to the 'my-new-feature' branch
php artisan migrate

Your migrations are applied only to the my-new-feature schema branch. The main branch remains untouched. This means your production application continues to run against the stable main schema without interruption.

Once your feature is fully developed and tested, you open a schema diff in PlanetScale. This shows you exactly what changes you’re proposing to merge from my-new-feature into main.

# PlanetScale Schema Diff for 'my-new-feature' -> 'main'
#
# ADDED TABLE: 'products'
#   id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY
#   name VARCHAR(255) NOT NULL
#   price DECIMAL(10, 2) NOT NULL
#
# ALTERED TABLE: 'users'
#   email VARCHAR(255) NULL -> VARCHAR(255) NOT NULL

You review the diff, and if it looks good, you deploy it. PlanetScale then orchestrates the schema change on the main branch. Because PlanetScale’s schema changes are designed to be online and non-blocking, your application experiences zero downtime.

The core problem PlanetScale solves here is the inherent risk of database schema changes in traditional environments. A bad migration can bring down your entire application, leading to lost revenue and user frustration. By isolating schema changes to branches, you create a safe sandbox. You can experiment, develop, and test schema modifications without any impact on your live production database. The main branch acts as your immutable production schema, and all development happens on ephemeral, isolated branches.

The magic is in how PlanetScale handles schema evolution. When you merge a branch, PlanetScale doesn’t just execute SQL. It analyzes the diff, understands the implications of the changes, and applies them in an online, non-disruptive manner. For example, adding a non-nullable column typically requires a table rewrite, which can lock tables for extended periods. PlanetScale, however, can often perform these operations in the background, allowing your application to continue reading and writing to the table throughout the process. It intelligently handles the "dual-write" problem, ensuring data consistency during the migration.

This granular control extends to your application’s database credentials. You can configure your Laravel application to point to different PlanetScale branches using distinct .env files or environment variables. This allows you to test your application against the exact schema that a specific branch represents, ensuring compatibility before merging.

When you’re ready to make the switch from a feature branch schema to production, you’re not just migrating data; you’re migrating the schema definition itself. PlanetScale then applies this definition to your production branch (main) in a way that’s designed to be non-blocking. This means your Laravel application can keep querying and writing to the database while the schema change is happening. The database schema is updated incrementally, often by adding new columns as nullable, populating them in the background, and then making them non-nullable, all without taking the table offline.

The most surprising thing is that even though you’re working with what feels like entirely separate databases for each branch, you’re actually just manipulating schema definitions. PlanetScale’s underlying storage engine is designed for this kind of rapid, isolated schema evolution without needing to provision entirely new database instances for every single branch. Your data remains on the main branch, and branches are essentially pointers to different versions of the schema applied to that underlying data.

The next step is to explore how PlanetScale’s built-in high availability and read replicas can further enhance your Laravel application’s performance and resilience.

Want structured learning?

Take the full Planetscale course →