Skip to content

[Fix] Resolve postgresql collation issue#1162

Merged
RichardAnderson merged 5 commits into
vitodeploy:4.xfrom
RichardAnderson:fix/postgres-colls
Jun 14, 2026
Merged

[Fix] Resolve postgresql collation issue#1162
RichardAnderson merged 5 commits into
vitodeploy:4.xfrom
RichardAnderson:fix/postgres-colls

Conversation

@RichardAnderson

@RichardAnderson RichardAnderson commented Jun 13, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Improved PostgreSQL database creation with enhanced locale and ICU collation support.
    • Replaced collation selector with a searchable combobox for easier selection.
  • Bug Fixes

    • Strengthened validation for database charset and collation inputs to prevent invalid values.
  • Deprecations

    • Removed support for PostgreSQL version 14.
  • Tests

    • Added tests covering ICU collations, validation rejection, creation script behaviour and preservation on sync.

@RichardAnderson RichardAnderson requested a review from Copilot June 13, 2026 20:51
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 8a44a3f8-9389-419d-a5ae-f292fdcbe2b0

📥 Commits

Reviewing files that changed from the base of the PR and between 14ea9ed and a7137f1.

📒 Files selected for processing (3)
  • app/Actions/Database/CreateDatabase.php
  • resources/views/ssh/services/database/postgresql/create.blade.php
  • resources/views/ssh/services/database/postgresql/get-charsets.blade.php

📝 Walkthrough

Walkthrough

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

Changes

PostgreSQL Collation & Locale Support

Layer / File(s) Summary
Input Validation & Service Configuration
app/Actions/Database/CreateDatabase.php, app/Providers/ServiceTypeServiceProvider.php
charset and collation validation rules now include regex constraints limiting allowed characters. PostgreSQL version '14' removed from the registered versions list.
Combobox UI integration for Collation
resources/js/components/ui/combobox.tsx, resources/js/pages/databases/components/create-database.tsx
Combobox accepts an optional id prop forwarded to its Button. The database create form's collation field now uses a searchable Combobox wired with collations, value, and onValueChange.
Collation & charset retrieval SQL updates
resources/views/ssh/services/database/postgresql/get-charsets.blade.php, resources/views/ssh/services/database/postgresql/get-db-list.blade.php
psql queries now compute charset handling collencoding = -1, select distinct collation names, order by charset, collation, and derive collation using datlocprovider/JSON locale fields (ICU/builtin/libc-aware mappings).
Dynamic CREATE DATABASE with locale/provider clauses
resources/views/ssh/services/database/postgresql/create.blade.php
Replaces single-line psql invocation with a here-doc that verifies the collation exists, formats a CREATE DATABASE statement including optional LOCALE_PROVIDER/LC_COLLATE/LC_CTYPE clauses based on collation metadata and server version, executed via \gexec; preserves existing error and success signalling.
Feature & Unit Test Coverage
tests/Feature/DatabaseTest.php, tests/Unit/SSH/Services/Database/GetCharsetsTest.php
Adds feature tests for PostgreSQL ICU collation creation, malicious collation rejection, create-script locale directives, sync preservation; adds PostgreSQL 18 charset dataset for unit tests and imports needed for PostgreSQL-specific tests.

Sequence Diagram

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

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • vitodeploy/vito#1156: Modifies the Collation field handling in create-database.tsx, related to UI collation selection changes.
🚥 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 accurately describes the main objective of the pull request, which addresses PostgreSQL collation handling across validation, UI components, and database creation logic.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 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.

Comment thread resources/views/ssh/services/database/postgresql/create.blade.php
Comment thread tests/Feature/DatabaseTest.php
Comment thread app/Providers/ServiceTypeServiceProvider.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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 56f7e42 and 14ea9ed.

📒 Files selected for processing (9)
  • app/Actions/Database/CreateDatabase.php
  • app/Providers/ServiceTypeServiceProvider.php
  • resources/js/components/ui/combobox.tsx
  • resources/js/pages/databases/components/create-database.tsx
  • resources/views/ssh/services/database/postgresql/create.blade.php
  • resources/views/ssh/services/database/postgresql/get-charsets.blade.php
  • resources/views/ssh/services/database/postgresql/get-db-list.blade.php
  • tests/Feature/DatabaseTest.php
  • tests/Unit/SSH/Services/Database/GetCharsetsTest.php
💤 Files with no reviewable changes (1)
  • app/Providers/ServiceTypeServiceProvider.php

Comment thread app/Actions/Database/CreateDatabase.php
Comment thread resources/views/ssh/services/database/postgresql/get-charsets.blade.php Outdated
@RichardAnderson RichardAnderson merged commit e4282d3 into vitodeploy:4.x Jun 14, 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.

3 participants