Allow packages to hook into migrate:fresh before tables are dropped

Aperta
#795 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@rheatkhs ci sta già lavorando.

Dal 3/12/2026.

  • #816 di @rheatkhs — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
rust
Ambito
backend, database

Direzione di ricerca

Start with src/db/commands.rs, where the issue says the built-in migrate:fresh command and its private options are defined, then check docs/console.md for command registration behavior. The issue proposes a pre-drop hook or an extendable command; done means packages can clean up before tables are dropped while the built-in fresh migration behavior remains available. An open linked pull request indicates work is already underway.

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

Descrizione

Following up on this thread on X with the details in an issue.

Building tenancy-laravel-rust, a multi-tenancy package inspired by stancl/tenancy. Each tenant has its own database (or PostgreSQL schema), tracked in a tenants table in the central database. Very much the rust stancl v4 tenancy conversion (I need it faster than probably it'd arrive)

The problem

migrate:fresh drops every table in the central database, including tenants. That leaves those tenant databases and schemas orphaned, with nothing left that records they exist.

Previously this was handled with an opt-in drop_tenant_databases_on_migrate_fresh setting that hooks into Laravel's migrate:fresh. Right now my workaround is a separate tenants:drop command (in the commands docs) that users have to remember to run before migrate:fresh... and I kinda hate that anything "needs to be remembered"

Why a package can't do this today

As of v0.1.6, registering a command with the same name replaces the previous definition (docs/console.md). The built-in command is a private Fresh struct with private MigrateOptions in src/db/commands.rs, so a package that replaces migrate:fresh can't call the original afterwards.

To do it that way, the package would have to reimplement migrate:fresh (dropping everything, schema dump loading, seeding, --database, --force prompts, missing-database creation), which I'd rather not duplicate. An app's own migrate:fresh command would also override the package's anyway.

What would solve this

I'm happy with whatever shape fits the framework, but either of these would work:

  1. An event or hook that fires before migrate:fresh drops tables, with the connection name (ideally only for the default/central connection), so a package can register a listener.
  2. Making the built-in migrate:fresh command callable or extendable so a package can wrap it: run its cleanup, then hand off to the original.

A before hook is the minimum; I don't need an after hook, never going to complain about more hooks though.

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.