[Fix] Prevent database users page crash when a linked database is deleted - #1222
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe change keeps linked database lists indexed after deletion, adds migration support for sparse JSON objects, and allows the frontend component to render object values. Feature tests cover deletion and migration behaviour. ChangesDatabase list normalisation
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@database/migrations/2026_08_01_090402_reindex_database_users_databases.php`:
- Around line 8-10: Remove the redundant PHPDoc blocks above the migration
methods, including both the “Run the migrations” and corresponding rollback
documentation blocks; leave the method signatures and migration behavior
unchanged.
- Around line 13-23: Update the migration’s database_users rewrite inside the
chunkById callback to use an optimistic conditional update: include the original
databases value in the update predicate, and retry the read/transform/update
when the condition no longer matches. Ensure stale JSON cannot overwrite
concurrent database-link changes, while preserving the existing filtering and
array normalization behavior.
In `@resources/js/components/database-user-databases.tsx`:
- Line 5: Update the databases value normalization expression to accept only
arrays whose elements are strings or objects whose values are all strings; use
Object.values only after validating the object shape, and return an empty list
for null, scalar, or otherwise malformed values.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 7472a55d-84f4-4dcf-8ea4-3c6af48c68d8
📒 Files selected for processing (5)
app/Models/Database.phpdatabase/migrations/2026_08_01_090402_reindex_database_users_databases.phpresources/js/components/database-user-databases.tsxtests/Feature/DatabaseTest.phptests/Feature/DatabaseUserDatabasesMigrationTest.php
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/Feature/DatabaseUserDatabasesMigrationTest.php`:
- Around line 58-61: Update the database assertion in the migration test to use
assertDatabaseHas('database_users', [...]) for the row identified by
$databaseUser->id, preserving the exact JSON string
["db_one","db_three","db_six"] as the databases value and removing the direct
DB::table(...)->value() assertion.
- Line 56: Update the manual recovery statement in the DatabaseUser migration
test to modify only records whose databases value is non-null and an array,
preserving NULL and scalar values unchanged. Avoid applying array_values to
invalid types, and add fixtures/assertions covering both NULL and non-array
databases values.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 2cd115c1-132e-46b4-9015-7e27805b2e22
📒 Files selected for processing (3)
database/migrations/2026_08_01_090402_reindex_database_users_databases.phpresources/js/components/database-user-databases.tsxtests/Feature/DatabaseUserDatabasesMigrationTest.php
💤 Files with no reviewable changes (1)
- database/migrations/2026_08_01_090402_reindex_database_users_databases.php
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/Feature/DatabaseUserDatabasesMigrationTest.php`:
- Around line 52-56: Replace the three DB::table('database_users') fixture
updates with DatabaseUser::query()->whereKey(...) updates, preserving the
existing sparse JSON object, null, and scalar values and bypassing model casts.
- Line 58: Replace the unbounded DatabaseUser::all() scan with a
DatabaseUser::query() pipeline using whereNotNull('databases') and lazyById(100)
or chunkById(), while preserving the existing is_array($u->databases) guard and
update behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 5c02ca2a-75b2-4fc5-8c58-6e81d2b25a48
📒 Files selected for processing (1)
tests/Feature/DatabaseUserDatabasesMigrationTest.php
Deleting a mid-list linked database left a gap in the user's
databasesarray, which serialized to a JSON object instead of an array and crashed the database users page on render - reindexed on delete, added a migration to heal existing rows, and hardened the cell component.Single line tinker fix for 4.0.1 implementations unable or unwilling to update, however, if the root cause happens again, this will need to be rerun, use at your own risk, run a backup first.
Summary by CodeRabbit
Summary by CodeRabbit
Bug Fixes
Data Migration