[Fix] Resolve postgresql collation issue#1162
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 (3)
📝 WalkthroughWalkthroughAdds stricter charset/collation validation, swaps the collation Select for a searchable Combobox, updates psql queries to handle provider-aware collations and collencoding edge cases, generates CREATE DATABASE via a here-doc with locale/provider clauses, and adds tests for ICU collations and validation. ChangesPostgreSQL Collation & Locale Support
Sequence DiagramsequenceDiagram
participant Blade as create.blade.php
participant psql as PostgreSQL
participant App as Application (validation/tests)
Blade->>psql: Query pg_collation to validate requested collation
Blade->>Blade: Format CREATE DATABASE with encoding and optional locale/provider clauses
Blade->>psql: Execute formatted CREATE DATABASE via \gexec
psql-->>Blade: Success or error result
App->>App: Validation enforces charset/collation regex rules
App->>App: Tests assert creation, rejection, script contents, and sync preservation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 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 PR addresses PostgreSQL collation handling (notably ICU/builtin locale providers) by improving how available collations are discovered, how database collations are reported during sync, and how database creation applies locale/collation settings.
Changes:
- Update PostgreSQL SSH scripts to correctly surface collations for PG 18+ (including ICU/builtin locale provider details) and to return accurate database collations during sync.
- Add backend input validation hardening for
charset/collation, and expand test coverage for PostgreSQL ICU collations and malicious collation input. - Update the database creation UI to use a searchable combobox for collations.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Unit/SSH/Services/Database/GetCharsetsTest.php | Adds PG 18 charset/collation fixture to ensure collencoding=-1 collations are included. |
| tests/Feature/DatabaseTest.php | Adds feature coverage for PG ICU collation create/sync behavior and malicious input rejection. |
| resources/views/ssh/services/database/postgresql/get-db-list.blade.php | Computes collation values correctly for ICU/builtin providers instead of relying on datcollate alone. |
| resources/views/ssh/services/database/postgresql/get-charsets.blade.php | Includes collencoding=-1 collations by mapping them to server_encoding, improving PG 18+ results. |
| resources/views/ssh/services/database/postgresql/create.blade.php | Creates DBs with locale-provider-aware options (ICU/builtin/libc) using format(...)\n\\gexec. |
| resources/js/pages/databases/components/create-database.tsx | Switches collation selector from <Select> to searchable <Combobox>. |
| resources/js/components/ui/combobox.tsx | Adds optional id support to connect <Label htmlFor> to the trigger button. |
| app/Providers/ServiceTypeServiceProvider.php | Removes PostgreSQL 14 from the selectable versions list. |
| app/Actions/Database/CreateDatabase.php | Adds regex validation constraints for charset and collation inputs. |
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 `@app/Actions/Database/CreateDatabase.php`:
- Around line 72-76: The collation validator in CreateDatabase.php is too strict
and rejects valid locale modifiers containing '@'; update the 'collation' rule
(the array under the 'collation' key) to allow '@' (for example change the regex
from '/^[A-Za-z0-9._-]+$/' to '/^[A-Za-z0-9._@-]+$/') so values like
"sr_RS@latin" pass validation.
In `@resources/views/ssh/services/database/postgresql/get-charsets.blade.php`:
- Line 14: Replace the positional ORDER BY clause "ORDER BY 2, 1" in the SQL
string with explicit column names to improve clarity and guard against column
reordering; specifically change "ORDER BY 2, 1" to "ORDER BY charset, collation"
in the SQL that builds the PostgreSQL charsets/collations query.
🪄 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: fa72e97d-548f-4416-889f-7fc533254f3b
📒 Files selected for processing (9)
app/Actions/Database/CreateDatabase.phpapp/Providers/ServiceTypeServiceProvider.phpresources/js/components/ui/combobox.tsxresources/js/pages/databases/components/create-database.tsxresources/views/ssh/services/database/postgresql/create.blade.phpresources/views/ssh/services/database/postgresql/get-charsets.blade.phpresources/views/ssh/services/database/postgresql/get-db-list.blade.phptests/Feature/DatabaseTest.phptests/Unit/SSH/Services/Database/GetCharsetsTest.php
💤 Files with no reviewable changes (1)
- app/Providers/ServiceTypeServiceProvider.php
Summary by CodeRabbit
New Features
Bug Fixes
Deprecations
Tests