Skip to content

[Fix] utf8mb4 for MariaDB missing#1156

Merged
RichardAnderson merged 3 commits into
vitodeploy:4.xfrom
RichardAnderson:fix/mariadb-sync
Jun 13, 2026
Merged

[Fix] utf8mb4 for MariaDB missing#1156
RichardAnderson merged 3 commits into
vitodeploy:4.xfrom
RichardAnderson:fix/mariadb-sync

Conversation

@RichardAnderson

@RichardAnderson RichardAnderson commented Jun 13, 2026

Copy link
Copy Markdown
Member

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 NULL charset 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

  • Improvements
    • Charset/collation handling now returns a per‑charset object with explicit default and list keys, improving selection accuracy.
  • UI
    • Create Database modal fetches charsets/collations more reliably, ignores stale responses, and auto‑selects an appropriate collation when charset or server changes.
  • Tests
    • Added MariaDB 11.4 fixture to validate charset/collation behaviour.

@RichardAnderson RichardAnderson requested a review from Copilot June 13, 2026 10:32
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Charset Retrieval Fix

Layer / File(s) Summary
Charset accumulation logic refactor
app/Services/Database/AbstractDatabase.php
The getCharsets() loop now skips empty/'NULL' charset names, initialises a per-charset result on first encounter, appends collations into a list, and sets default when a row's flag equals 'Yes'.
Controller response shape change
app/Http/Controllers/DatabaseController.php
collations() now returns a JSON object with default and list for the requested charset (with fallbacks) instead of a single list value.
Frontend: fetchCharsets, resolveCollation & handler updates
resources/js/pages/databases/components/create-database.tsx
Removes useEffect import, adds refs and resolveCollation, rewrites fetchCollations/fetchCharsets to async/await with request-id staleness protection, and updates modal open/charset handlers to use the new helpers and the {default,list} response shape.
Tests: PHPDoc tighten and MariaDB 11.4 case
tests/Unit/SSH/Services/Database/GetCharsetsTest.php
Updates the @param PHPDoc for the expected charset shape and adds a MariaDB 11.4 provider case that stubs SHOW COLLATION output and verifies big5 and utf8mb4 are returned with the updated default/list structure.

Sequence Diagram

sequenceDiagram
  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 }
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main issue: enabling utf8mb4 selection for MariaDB installations lacking default collation markers.
Linked Issues check ✅ Passed The code changes implement the solution to issue #1155 by refactoring charset/collation handling to work when no default collations are marked, allowing utf8mb4 selection.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the MariaDB utf8mb4 issue: backend charset parsing, response format, and frontend collation resolution logic.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-NULL charset row (not only those with a Default=Yes collation).
  • 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 NULL charset 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 51d5a26 and 1e1ec39.

📒 Files selected for processing (2)
  • app/Services/Database/AbstractDatabase.php
  • tests/Unit/SSH/Services/Database/GetCharsetsTest.php

Comment thread tests/Unit/SSH/Services/Database/GetCharsetsTest.php

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1e1ec39 and 87290aa.

📒 Files selected for processing (3)
  • app/Http/Controllers/DatabaseController.php
  • resources/js/pages/databases/components/create-database.tsx
  • tests/Unit/SSH/Services/Database/GetCharsetsTest.php

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread resources/js/pages/databases/components/create-database.tsx

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 87290aa and bc4b508.

📒 Files selected for processing (1)
  • resources/js/pages/databases/components/create-database.tsx

Comment thread resources/js/pages/databases/components/create-database.tsx
@RichardAnderson RichardAnderson merged commit c9568a0 into vitodeploy:4.x Jun 13, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: utf8mb4 for MariaDB missing

3 participants