-
-
Notifications
You must be signed in to change notification settings - Fork 255
fix: plugin migration rollback and cache clearing on uninstall #2033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: plugin migration rollback and cache clearing on uninstall #2033
Conversation
… components after plugin updates
📝 WalkthroughWalkthroughReplaced plugin migration rollback with a migrator reset for single-plugin reversal, and extended the uninstall flow to clear cached Filament panel components after package changes. Changes
Possibly related PRs
Pre-merge checks✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Collides with #2031 |
…r improved error handling and code clarity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
app/Services/Helpers/PluginService.php (1)
339-342: Remove redundant fully qualified name for consistency.The panel cache clearing correctly addresses the "Table not found" errors mentioned in the PR objectives. However, the fully qualified name
\Filament\Facades\Filament::getPanels()is redundant sinceFilamentis already imported at line 10. The same call works without the qualifier ininstallPlugin()at lines 298-300.🔎 Proposed fix for consistency
- // This throws an error when not called with qualifier - foreach (\Filament\Facades\Filament::getPanels() as $panel) { + foreach (Filament::getPanels() as $panel) { $panel->clearCachedComponents(); }
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
app/Services/Helpers/PluginService.php
🧰 Additional context used
🧬 Code graph analysis (1)
app/Services/Helpers/PluginService.php (3)
database/Seeders/DatabaseSeeder.php (1)
run(14-30)app/Providers/Filament/AppPanelProvider.php (1)
panel(13-40)app/Providers/Filament/AdminPanelProvider.php (1)
panel(16-56)
🔇 Additional comments (4)
app/Services/Helpers/PluginService.php (4)
14-15: LGTM! Necessary imports for the refactored migration and seeder logic.These imports support the direct use of
Migratorfor migration execution andModel::unguarded()for seeder operations.
245-250: LGTM! Proper seeder execution pattern.Using
Model::unguarded()is the correct approach for seeders, allowing mass assignment operations. The seeder is properly resolved from the container withsetContainer()called to provide container access.
232-237: Key fix: UsingMigrator::reset()correctly addresses the migration rollback bug.This change replaces
migrate:rollbackwithMigrator::reset(), which rolls back all migrations in the given paths regardless of batch, ensuring complete cleanup when a plugin has migrations across multiple batches. The array wrapper around$migrationsis the correct signature for thereset()method.
219-224: Good refactor to use Migrator directly.Using
Migrator::run()provides better control and improved exception messages with plugin context. The Laravel API correctly supports passing a single path string to the method.
lancepioch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should merge #2031 first then adjust this one.
|
@PalmarHealer Please merge main and resolve the conflicts. |
# Conflicts: # app/Services/Helpers/PluginService.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
app/Services/Helpers/PluginService.php (1)
340-344: Inconsistent namespace usage and misleading comment.The code uses the fully qualified
\Filament\Facades\Filament::getPanels()here, but the same pattern at lines 304-306 uses the importedFilament::getPanels()without the leading backslash. SinceFilament\Facades\Filamentis already imported at line 10, the leading backslash is unnecessary and creates inconsistency.Additionally, the comment "This throws an error when not called with qualifier" is misleading, as line 304 works correctly without the qualifier.
🔎 Proposed fix for consistency
- // This throws an error when not called with qualifier - foreach (\Filament\Facades\Filament::getPanels() as $panel) { + foreach (Filament::getPanels() as $panel) { $panel->clearCachedComponents(); }
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
app/Services/Helpers/PluginService.php
🧰 Additional context used
🧬 Code graph analysis (1)
app/Services/Helpers/PluginService.php (3)
app/Providers/Filament/AdminPanelProvider.php (1)
panel(16-56)app/Providers/Filament/AppPanelProvider.php (1)
panel(13-40)app/Providers/Filament/ServerPanelProvider.php (1)
panel(17-55)
🔇 Additional comments (1)
app/Services/Helpers/PluginService.php (1)
238-238: Parameter format is valid—no changes needed.The
reset()method accepts either a string or an array of paths, so passing$migrationsas a string is correct. Laravel's Migrator signature isreset(string[]|string $paths = []), which handles both formats.
Fixes two critical bugs in the plugin uninstallation process that caused incomplete migration rollback and cache-related errors.
The
rollbackPluginMigrations()method usedmigrate:rollback, which only rolls back the last batch of migrations. If a plugin had migrations run across multiple batches (e.g., initial install in batch 50, update adds migration in batch 75), only the most recent batch was rolled back, leaving orphaned tables and columns in the database.After uninstalling a plugin, users encountered "Table not found" errors (e.g.,
SQLSTATE[42S02]: Base table or view not found).