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

Aperta
#797 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
mysql, rust
Ambito
backend, databases

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.)

Lingua principale
Rust
Stelle
847
Fork
174
Merge medio
5h 40m
PR unite (30g)
167

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di laravel/rust-framework

Tutte le issue di laravel/rust-framework

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.