Skip to content

Conversation

@PalmarHealer
Copy link
Contributor

Fixes two critical bugs in the plugin uninstallation process that caused incomplete migration rollback and cache-related errors.

  1. The rollbackPluginMigrations() method used migrate: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.

  2. After uninstalling a plugin, users encountered "Table not found" errors (e.g., SQLSTATE[42S02]: Base table or view not found).

@coderabbitai
Copy link

coderabbitai bot commented Dec 21, 2025

📝 Walkthrough

Walkthrough

Replaced 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

Cohort / File(s) Summary
Plugin Service
app/Services/Helpers/PluginService.php
Replaced migrator->rollback($migrations) with migrator->reset([$migrations]) to change how a single plugin's migrations are reversed; after uninstalling packages, iterate Filament::getPanels() and call clearCachedComponents() on each to clear UI caches.

Possibly related PRs

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: fixing plugin migration rollback behavior and adding cache clearing on uninstall.
Description check ✅ Passed The description clearly explains the two bugs being fixed and relates directly to the changes in PluginService.php.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@PalmarHealer
Copy link
Contributor Author

Collides with #2031

@PalmarHealer PalmarHealer marked this pull request as draft December 21, 2025 21:03
…r improved error handling and code clarity
@PalmarHealer PalmarHealer marked this pull request as ready for review December 21, 2025 23:22
@Boy132 Boy132 self-assigned this Dec 22, 2025
Copy link

@coderabbitai coderabbitai bot left a 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 since Filament is already imported at line 10. The same call works without the qualifier in installPlugin() 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

📥 Commits

Reviewing files that changed from the base of the PR and between d435c6b and c171d36.

📒 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 Migrator for migration execution and Model::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 with setContainer() called to provide container access.


232-237: Key fix: Using Migrator::reset() correctly addresses the migration rollback bug.

This change replaces migrate:rollback with Migrator::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 $migrations is the correct signature for the reset() 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.

Copy link
Member

@lancepioch lancepioch left a 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.

@lancepioch lancepioch requested a review from Boy132 December 28, 2025 01:39
@Boy132
Copy link
Member

Boy132 commented Dec 30, 2025

@PalmarHealer Please merge main and resolve the conflicts.

Boy132 added 2 commits January 3, 2026 23:35
# Conflicts:
#	app/Services/Helpers/PluginService.php
Copy link

@coderabbitai coderabbitai bot left a 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 imported Filament::getPanels() without the leading backslash. Since Filament\Facades\Filament is 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6f1f888 and c8e6f71.

📒 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 $migrations as a string is correct. Laravel's Migrator signature is reset(string[]|string $paths = []), which handles both formats.

@Boy132 Boy132 merged commit 3141fe6 into pelican-dev:main Jan 3, 2026
25 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants