Skip to content

Let applications name the migrations table, like Laravel's database.migrations.table - #613

Open
MElkmeshi wants to merge 1 commit into
laravel:0.xfrom
MElkmeshi:feat/configurable-migrations-table
Open

MElkmeshi wants to merge 1 commit into
laravel:0.xfrom
MElkmeshi:feat/configurable-migrations-table

Conversation

@MElkmeshi

@MElkmeshi MElkmeshi commented Dec 2, 2026 •

Copy link
Copy Markdown

When a Rust app shares its database with an existing app that already has a migrations table (for example, an app moving from PHP Laravel to Laravel Rust that keeps its database), the two apps can't keep separate migration histories. laravel-rust hardcodes the table name:

PHP Laravel lets you rename it in config/database.php:

'migrations' => [
    'table' => 'migrations',
    'update_date_on_publish' => true,
],

Since Laravel 11 this has no env variable, and the migrator, migrate:status and the schema dump all read it.

Repro

# The database already has another app's `migrations` table.
laravel migrate

Rust adds its rows to the other app's migrations table, migrate:status lists the other app's migrations as "ran, not registered", and schema:dump dumps the other app's rows.

Fix

  • Add Database::migrations_table, which defaults to "migrations". Like Laravel, it isn't read from the environment. You set it in src/config/database.rs:
    let mut database = Database::from_env(env);
    database.migrations_table = "rust_migrations".into();
  • DatabaseManager gives the name to every connection it registers. So migrate, migrate:fresh, migrate:status, schema:dump (pg_dump -t, mysqldump, sqlite3 .dump), loading a schema dump, and refresh_database test databases all use it. Nothing else needed changing.
  • The name is quoted in the migrator's SQL. Like the session, cache and queue tables, it is also checked at startup: anything other than letters, digits and underscores is a StartupError::Migrations. Schema-qualified names are rejected because the dump clients can't target them consistently.
  • Documented under "Naming the migrations table" in docs/migrations.md.

This doesn't overlap #412 (which changes shadow-table filtering in dump_sqlite) or #457 (which changes make:migration timestamps).

Tests

  • tests/migrations.rs: with migrations_table = "rust_migrations", migrate records into rust_migrations, leaves a pre-existing migrations table and its row alone, and migrate:status doesn't list the other app's migration. An invalid or schema-qualified name stops startup.
  • tests/schema_dump.rs: schema:dump writes the rust_migrations rows, and migrate:fresh loads the dump back with no migrations table created.
  • cargo test --all-features --test database -- --include-ignored migrations:: schema_dump:: against local PostgreSQL 18 and MySQL 8.0: 30 passed. This covers the PostgreSQL $1, $2 insert path and the existing pg_dump/mysqldump round trips.
  • cargo clippy --workspace --all-targets --all-features -- -D warnings, cargo fmt --all -- --check, cargo check --no-default-features --all-targets and the core/database lib tests all pass.

Created with Claude Opus 5.5 in Claude Code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants