Console: no in-process command dispatch, so a tenant cannot be migrated or seeded on its own connection

Open
#797 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
mysql, rust
Domain
backend, databases

Research direction

Start with src/db/commands.rs around migrator and on_database, then review laravel-rust-database/src/db/seeders.rs and docs/console.md to understand the public command and database APIs. Decide which proposed API path fits the framework and how it should support tenant migrations and seeding. Done means application code can run the framework's migration or seeder work on a named connection without reimplementing its bookkeeping.

Written by the indexing model from the issue text.

Description

What I'm building

A database-per-tenant application. Each tenant's connection is registered at runtime:

db::manager().add_connection("ws4", with_database(template, "ws4"))?;
db::manager().using_connection("ws4", future).await

That part works well — the scoped switch is exactly what a tenant needs.

What works

The built-in commands already take a connection name: migrate --database=ws4, migrate:fresh --database=ws4, migrate:status --database=ws4 (laravel-rust/src/db/commands.rs:189, :283).

What's missing

An application command cannot reuse any of that for a tenant.

  1. No in-process command dispatch. There is no Artisan::call() equivalent — no Console::call, and no mention of one in docs/console.md — so a workspaces:migrate command cannot invoke migrate --database=ws4.

  2. The per-connection runner is crate-private. fn migrator(manager, database, migrations) (src/db/commands.rs:507) and pub(in crate::db) async fn on_database(..) (src/db/commands.rs:522) — the function that makes --database the default while migrations and seeders run — are unreachable from an application. Migrator itself is public (laravel-rust-database/src/db/migrations.rs:170), its construction and bookkeeping are not.

  3. Seeding is default-connection only. laravel_rust_database::db::seeders::run(..) (laravel-rust-database/src/db/seeders.rs:181) takes no connection and runs "in one transaction on the default connection". There is no standalone seed command either — seeding is reached only through migrate --seed, which is inside the private path above.

Why it matters

Provisioning a tenant becomes a reimplementation: a hand-written migrator loop and its migrations bookkeeping, plus a hand-written seeder runner, instead of the framework's own. On a multi-tenant host that is the core operation — workspaces:migrate, workspaces:seed, workspaces:run <command> all need "run this on that connection", and none of them can be written against today's public API.

What would fix it

Any one of these is sufficient:

  • Console::call("migrate", ["--database", "ws4"]) — Laravel's Artisan::call, which makes the other two unnecessary;
  • or pub on migrator(..) and on_database(..), so an application can compose the existing runner;
  • or a --database option on a standalone db:seed command.

Reproduction

Register a second connection at runtime (db::manager().add_connection("ws4", ..)), then try to run the framework's migrations or seeders against it from application code. The CLI does it (migrate --database=ws4); there is no public API entry point to do the same from a command or a test.

(I'm on laravel-rust 0.1.4, Rust 2024, MySQL.)

Dominant language
Rust
Stars
847
Forks
174
Avg merge
5h 40m
Merged PRs (30d)
167

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from laravel/rust-framework

All issues in laravel/rust-framework

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.