Allow packages to hook into migrate:fresh before tables are dropped
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
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:
- An event or hook that fires before
migrate:freshdrops tables, with the connection name (ideally only for the default/central connection), so a package can register a listener. - Making the built-in
migrate:freshcommand 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from laravel/rust-framework
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
laravel/rust-framework#864 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 64/100
laravel/rust-framework#876 ·
Maintainers usually reply within 1 day
-
Case-sensitive contains, starts_with and ends_with that match % and _ literally on every databaseOpen
Difficulty 4/5 3-5 days Newbie friendliness 58/100
laravel/rust-framework#874 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
laravel/rust-framework#873 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 58/100
laravel/rust-framework#872 ·
Maintainers usually reply within 1 day
All issues in laravel/rust-framework
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
neuralmagic/crucible#579 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
eclipse-score/kyron#249 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
seanmonstar/reqwest#3157 ·
Maintainers usually reply within 2 days