For four days Rust lived in someone else's house: PHP created the tables, and Rust only read them and now and then wrote a row or two. Today, for the first time, Rust changes the database schema itself. Sounds like a reason to panic: two migration systems, one database, and neither knows the other exists.
We dug into the source and found out it is too early to panic. Almost.
In short
- What we did: the first migration in Rust — an index for the people search from Day 3.
- The big discovery: Laravel Rust keeps its history in a
migrationstable with the same name and the same columns as PHP. So the two share the table. - How not to step on a rake: every Rust migration has
_rust_in its name, and a test makes sure no name matches a PHP one. Migrations only go forward, andmigrate:freshis banned in production. - In production: the PHP migration from Day 4 was recorded with batch 41, the Rust one with batch 42, in one and the same table.
One table, two owners
First we found where each side creates its history table. In PHP Laravel:
$schema->create($this->table, function ($table) {
// The migrations table is responsible for keeping track of which of the
// migrations have actually run for the application. We'll create the
// table to hold the migration file's path as well as the batch ID.
$table->increments('id');
$table->string('migration');
$table->integer('batch');
});
In Laravel Rust 0.1.5:
self.connection
.schema()
.create("migrations", |table| {
table.increments("id");
table.string("migration");
table.integer("batch");
})
.await
The columns are identical. In Rust the name migrations is hard-coded: no setting, no environment variable. So the question "shared table or not" has been decided for us. All that's left is to figure out whether the two can live under one roof.
The answer turned up in how Rust finds the migrations that have not run yet:
fn pending(&self, ran: &[Ran]) -> Vec<&'m Migration> {
let ran: BTreeSet<_> = ran.iter().map(|ran| ran.name.as_str()).collect();
self.migrations
.by_name()
.into_values()
.filter(|migration| !ran.contains(migration.name))
.collect()
}
Rust takes its own migrations and throws out the ones whose names are already in the table. It simply does not notice the PHP rows, because it only looks for its own. PHP does the same. The batch number is shared: each side takes the maximum and adds one.
Here is how it looks in production after the deploy:
2026_12_15_100000_create_rust_failed_jobs_table 41 ran, not registered
2026_12_16_100000_rust_index_users_lower_slug 42 ran
The first row is the PHP migration from Day 4: Rust sees it in the table but knows no such file, so it says "not registered". The second one is its own. One batch after the other, one table.
House rules
A shared table is safe only as long as both sides follow a few rules. We wrote them down in the README and check them automatically wherever we can.
1. Names never collide. If Rust and PHP give a migration the same name, the second side will decide it has already run and skip it. So every Rust migration has _rust_ in its name, and a test compares both folders:
/// Rust and PHP record migrations in the same `migrations` table by name: a Rust name must
/// say `rust` and must never be the name of a PHP migration, or one side would skip it.
#[test]
fn rust_migration_names_are_marked_and_unique() {
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let rust = names(&root.join("database/migrations"), ".rs");
let php = names(&root.join("../../database/migrations"), ".php");
assert!(!rust.is_empty());
for name in &rust {
assert!(name.contains("_rust_"), "{name}: a Rust migration name must contain `_rust_`");
assert!(!php.contains(name), "{name}: a PHP migration has the same name");
}
}
2. Forward only. Laravel Rust cannot roll migrations back: its commands include migrate, migrate:status and migrate:fresh, but no migrate:rollback. And PHP's migrate:rollback will not roll back a Rust step either. We checked on a local database:
INFO Rolling back migrations.
2026_12_16_100000_rust_index_users_lower_slug .......... Migration not found
To undo a change, we write a new migration that removes it.
3. No migrate:fresh or db:wipe in production. That was a rule before, but now it has a new meaning: both sides have migrate:fresh, and from either side it will drop the other side's tables too. And if Rust loads a schema dump (schema:dump), it first drops the migrations table itself, along with the PHP history.
4. If a Rust migration needs a PHP table, it waits until the PHP migration is in production. PHP and Rust deploys run independently, and nobody guarantees the order between them.
The first migration: an index that does not lock
On Day 3 Rust started searching for people like this:
.filter(db::raw!("lower(slug) like {prefix}") | db::raw!("lower(name) like {part}"))
A plain unique index on slug will not help with that condition: it stores slug, not lower(slug). And if the database uses a non-C locale, even an index on lower(slug) is no good for like 'ann%'. What you need is a functional index with text_pattern_ops. Here is our first Rust migration in full:
//! The team people search (src/teams.rs) looks for `lower(slug) like 'ann%'`. A plain index on
//! `slug` cannot serve that; one on `lower(slug)` with `text_pattern_ops` can, for any collation.
//!
//! The first migration Rust owns. It shares the `migrations` table with PHP, so its name says
//! `rust` and no PHP migration may take it. Built CONCURRENTLY, so `users` stays writable, which
//! PostgreSQL allows only outside a transaction; a failed concurrent build leaves an invalid
//! index behind, hence the DROP first, and the whole migration is safe to run again.
use laravel::db::AnyConnection;
pub async fn migrate(db: &AnyConnection) -> laravel::Result<()> {
db.query("DROP INDEX CONCURRENTLY IF EXISTS users_lower_slug_pattern_index")
.statement()
.await?;
db.query(
"CREATE INDEX CONCURRENTLY users_lower_slug_pattern_index ON users (lower(slug) text_pattern_ops)",
)
.statement()
.await?;
Ok(())
}
The most interesting part here is the argument type.
&mut AnyTransactionis the usual option. Laravel Rust wraps the migration and its record in a single transaction. If the migration fails, PostgreSQL rolls everything back, and the nextmigratestarts with a clean slate.&AnyConnectionis for things that cannot run in a transaction.CREATE INDEX CONCURRENTLYis one of them: PostgreSQL builds the index without blocking writes to the table, but only outside a transaction.
The price is no automatic rollback. If the build fails halfway, the database is left with an unfinished index and no record of the migration. That is why the migration starts with DROP INDEX CONCURRENTLY IF EXISTS: a rerun first clears away the leftovers, then builds from scratch.
For a PHP developer this is a familiar story: PHP Laravel has $withinTransaction = false for exactly the same purpose. In Rust the same choice is made by the function signature, and you cannot get it wrong: inside a transaction you simply have no connection object.
The deploy: migrate first, then swap the binary
Laravel Rust migrations are compiled straight into the binary. Wiring them up takes one line:
// Rust's own migrations (database/migrations, names with `rust`). They share PHP's
// `migrations` table: forward only, no rollback, never `migrate:fresh` in production.
.with_migrations(laravel::db::migrations!("database/migrations"))
The macro reads the folder at compile time. Cargo will not notice a new file on its own, so next to it sits a one-line build.rs that watches the folder.
There is no need to ship source code or a separate migration tool to the server: the new binary can migrate the database itself. So the deploy does this:
# Rust's own migrations (names with `rust`, in the shared `migrations` table), run by the
# new binary before it replaces the old one: if one fails, the old binary keeps serving.
if ! ./devsense-rust.next migrate --force; then
echo "❌ a Rust migration failed: the previous binary stays. Fix the migration and deploy again."
rm -f devsense-rust.next
exit 1
fi
If the migration fails, the old binary stays put and keeps answering, and the deploy turns red. The binary is swapped and restarted only after a successful migration.
The check
Locally, on the Sail database:
- Rust's
migrate:statusshowed all the PHP migrations as "ran, not registered" and its own as "pending". migrate --forceran it. A second run answered "No pending migrations".- PHP's
migrateanswered "Nothing to migrate": it did not notice the Rust row. - PHP's
migrate:rollback --pretendgave "Migration not found" for the Rust step. - The index works: on 30 rows PostgreSQL honestly picks a full scan, but with
enable_seqscan=offthe plan showsIndex Scan using users_lower_slug_pattern_indexwith the condition~>=~ 'ann' AND ~<~ 'ano'.
In production the deploy ran the migration with batch 42, right after the PHP migration from Day 4 with batch 41.
Honest differences and the price
- Rollback only by a new migration. The familiar
migrate:rollbackfor Rust steps exists on neither side, Rust or PHP. - The PHP test database knows nothing about Rust. PHP tests build the database from PHP migrations, so the Rust index is not there. For an index that is no big deal. But if Rust ever creates a table that PHP uses, it will have to be created in the PHP tests too.
- An index to grow into. There are few users for now, and PostgreSQL picks a full scan. The index will kick in on its own once the table grows.
- A shared batch number. It no longer means "one PHP deploy": the deploys of both sides are mixed in a single history.
The scoreboard
- The first Rust migration —
2026_12_16_100000_rust_index_users_lower_slug, in production, batch 42. - A shared
migrationstable with rules:_rust_in the name, forward only, nofreshand nowipein production. - A naming test that will not let the two sides give migrations the same name.
- The deploy: first
migrate --forcewith the new binary, then the swap.
What comes next
Day 6 — seeders. In Laravel Rust they are written as #[seeder], run in a transaction and can upsert. We will see which of our reference data can be seeded from Rust and how to make a rerun break nothing.
And at the end of the series — the promised honest breakdown: speed, memory, the cost of the move and the packages Rust does not have yet.
Links
- Migrations in Laravel Rust — structure, transactions,
migrate --forcein production - Schema builder — indexes and
.online()forCONCURRENTLY - Migrations in PHP Laravel — for comparison
- CREATE INDEX in PostgreSQL —
CONCURRENTLYand operator classes - github.com/laravel/rust-framework — the framework core
- From Laravel to Laravel Rust. Day 4 — the first queue and the first worker
- From Laravel to Laravel Rust. Day 3 — Rust reads the PHP session