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

Open
#795 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@rheatkhs is already working on this.

Since Dec 3, 2026.

  • #816 by @rheatkhs — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
backend, database

Research direction

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.

Written by the indexing model from the issue text.

Description

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.

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.