[Fix] utf8mb4 for MariaDB missing#1156
Conversation
📝 WalkthroughWalkthroughThe PR refactors getCharsets() to accumulate per-charset collation lists and set defaults only when rows mark 'Yes', updates DatabaseController to return {default,list}, adjusts the CreateDatabase component to consume that shape and select collations via a new helper, and adds a MariaDB 11.4 test case plus a tightened PHPDoc. ChangesCharset Retrieval Fix
Sequence DiagramsequenceDiagram
participant Frontend as CreateDatabase
participant Server as DatabaseController
participant Service as AbstractDatabase
Frontend->>Server: GET /collations?charset=<charset>
Server->>Service: getCharsets()
Service-->>Server: { <charset>: { default, list } }
Server-->>Frontend: { default, list }
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This pull request fixes MariaDB charset/collation parsing so charsets are still returned even when the server reports rows with a NULL charset (as seen on MariaDB 11.4), preventing charsets like utf8mb4 from disappearing from the selectable list.
Changes:
- Refactors
AbstractDatabase::getCharsets()to build charset entries for every non-NULLcharset row (not only those with aDefault=Yescollation). - Skips rows where the parsed charset name is empty/
NULL, avoiding the “last row” edge case that previously dropped the preceding charset. - Adds a unit test covering MariaDB 11.4 output that includes
NULLcharset rows.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
app/Services/Database/AbstractDatabase.php |
Refactors charset/collation parsing to be resilient to NULL charset rows and to always include charsets even without a default collation flagged. |
tests/Unit/SSH/Services/Database/GetCharsetsTest.php |
Adds a MariaDB 11.4 fixture ensuring utf8mb4 remains present when SHOW COLLATION includes NULL charset entries. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/Unit/SSH/Services/Database/GetCharsetsTest.php`:
- Around line 130-132: Update the PHPDoc for the $expected fixture variable to
allow null for the "default" key: change the type from array<string,
string|array<string>> to a more accurate shape such as array<string,
array{default: string|null, list: array<int, string>}> so the docblock reflects
that 'utf8mb4' (and similar fixtures) can have default => null; edit the
`@param/`@var annotation for $expected accordingly to match the actual fixture
structure.
🪄 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: 44a5cd16-0b40-4f4c-89d6-2321db8e4d30
📒 Files selected for processing (2)
app/Services/Database/AbstractDatabase.phptests/Unit/SSH/Services/Database/GetCharsetsTest.php
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@resources/js/pages/databases/components/create-database.tsx`:
- Around line 69-78: The collation fetches need to be guarded against stale
async responses and network errors: introduce a request-sequencing guard (e.g.,
a component-scoped incrementing latestCollationRequestId or an AbortController)
and use it in both places that call axios.get(route('databases.collations',
...)) — specifically inside fetchCharsets and the other collation-fetch path
around lines ~103-108 — by capturing the current request id/abort signal before
the call, wrapping the axios call in try/catch, and only calling
setCollations(...) and form.setData('collation', ...) if the captured id still
matches the latest (or the request was not aborted); on error (catch) handle by
not leaving stale UI state (e.g., clear collations or leave existing but don’t
overwrite) and optionally set an error flag. Ensure both fetch locations use the
same guarding mechanism so a slower earlier response cannot overwrite newer
state.
🪄 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: 97b06468-2b4e-4ffd-a827-f6e95a2e8284
📒 Files selected for processing (3)
app/Http/Controllers/DatabaseController.phpresources/js/pages/databases/components/create-database.tsxtests/Unit/SSH/Services/Database/GetCharsetsTest.php
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@resources/js/pages/databases/components/create-database.tsx`:
- Around line 89-98: The fetchCharsets function lacks error handling; wrap its
axios call and subsequent logic in a try/catch similar to fetchCollations so
failures clear state and reset the form fields: on success keep existing
behavior (setCharsets, setCollations when appropriate, update
fetchedServer.current), and on error call setCharsets([]), setCollations([]) and
reset form data for charset and collation (e.g., form.setData({ charset: null,
collation: null })) and optionally surface/log the error for user feedback;
reference the fetchCharsets and fetchCollations functions, plus state setters
setCharsets and setCollations and fetchedServer.current when making the changes.
🪄 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: ed9fe37e-a58e-46ca-9a20-c7de2fa7fa9d
📒 Files selected for processing (1)
resources/js/pages/databases/components/create-database.tsx
This pull request refactors the logic for parsing and returning database charsets and their collations, making it more robust in handling edge cases such as
NULLcharset values. It also adds a new unit test to ensure correct behavior when encountering such cases, specifically for MariaDB 11.4.closes #1155
Summary by CodeRabbit