Skip to content

Dispatch DatabaseRefreshing and DatabaseRefreshed around migrate:fresh - #816

Open
rheatkhs wants to merge 1 commit into
laravel:0.xfrom
rheatkhs:feat/migrate-fresh-events
Open

rheatkhs wants to merge 1 commit into
laravel:0.xfrom
rheatkhs:feat/migrate-fresh-events

Conversation

@rheatkhs

@rheatkhs rheatkhs commented Dec 3, 2026

Copy link
Copy Markdown

Fixes #795.

Packages such as multi-tenancy providers need to clean up external databases or schemas before migrate:fresh drops the central tables (such as tenants) that track them.

Summary

  • Add laravel::db::events::{DatabaseRefreshing, DatabaseRefreshed} (#[non_exhaustive]) with connection: String and default: bool (computed before --database switches the task-local default connection).
  • Dispatch DatabaseRefreshing in migrate:fresh before drop_all runs, with the task-local default connection already switched to the target connection. Returning an error from a listener aborts migrate:fresh before any tables are dropped.
  • Dispatch DatabaseRefreshed after migrations and any --seed seeder succeed.
  • Document both events in docs/migrations.md.
  • Add integration tests in tests/migrations.rs verifying event ordering, default flag / scoped connection behavior for --database, and aborting before table drops on listener error.

Add laravel::db::events::{DatabaseRefreshing, DatabaseRefreshed} and dispatch them from migrate:fresh before dropping tables and after migrations and any --seed seeder succeed.

Listeners receive the target connection name and whether it is the configured default connection, run with the task-local default connection switched to the target connection, and can return an error to abort migrate:fresh before any tables are dropped.

Fixes laravel#795
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants