Soft Dropping Tables in Migrations #55257
Unanswered
digitalcraftlabs
asked this question in
Ideas
Replies: 1 comment
-
It would also be awesome if there was a dedicated exception for this (this might require a |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Background
Currently, when rolling back a migration in Laravel, tables are dropped immediately using
Schema::dropIfExists('table_name')
. However, in some cases, it would be beneficial to have a "soft drop" mechanism that renames the table instead of deleting it outright. This would allow for easier recovery in case of mistakes or unexpected issues during rollbacks.Proposal
Introduce a new method in Laravel's
Schema
facade, such as:Instead of dropping the table immediately, this method would rename it, appending a timestamp:
This renamed table could then be automatically removed after a configurable period (e.g., 30 days) using a scheduled command or manually deleted if needed.
Benefits
Potential Implementation
Schema::softDrop($tableName)
, which renames the table instead of deleting it.php artisan schema:cleanup
) to permanently delete old tables after a defined retention period.Alternative Approach
Instead of modifying
Schema
, Laravel could introduce a new migration method, such as:This would behave similarly to
dropIfExists()
but would rename the table first.Would love to hear feedback on this idea! 🚀
Beta Was this translation helpful? Give feedback.
All reactions