Skip to content

[Fix] Mysql Users + Postgres Host fix#1161

Merged
RichardAnderson merged 3 commits into
vitodeploy:4.xfrom
RichardAnderson:fix/mysql-users
Jun 14, 2026
Merged

[Fix] Mysql Users + Postgres Host fix#1161
RichardAnderson merged 3 commits into
vitodeploy:4.xfrom
RichardAnderson:fix/mysql-users

Conversation

@RichardAnderson

@RichardAnderson RichardAnderson commented Jun 13, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Conditional host field shown only for handlers that support it; PostgreSQL hides host controls.
    • Table now shows colour-coded permission/status and database badges; improved per-row actions (Edit, Link, Delete).
    • Host input defaults to sensible values when omitted.
  • Bug Fixes

    • Prevent duplicate username+host combinations and host collision on update.
    • Reject malicious host input and improve host validation.
  • Tests

    • Added feature tests covering host/username uniqueness, host validation, and UI column visibility.

@RichardAnderson RichardAnderson requested a review from Copilot June 13, 2026 18:46
@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: 8493f652-4275-4054-8e5b-ac7a0cc2b8a3

📥 Commits

Reviewing files that changed from the base of the PR and between d97a79b and 41470f7.

📒 Files selected for processing (2)
  • app/Http/Controllers/DatabaseUserController.php
  • resources/js/pages/database-users/index.tsx

📝 Walkthrough

Walkthrough

Host-aware database user logic added: service contract methods (usesHost, databaseUserExists), host resolution/validation in create/update actions, enums updated for table display, controller and resource use a new DatabaseUserTable with conditional host column, UI components updated, and comprehensive tests added.

Changes

Database User Host Support & Table Refactor

Layer / File(s) Summary
Database service contract and host support methods
app/Services/Database/Database.php, app/Services/Database/AbstractDatabase.php, app/Services/Database/Postgresql.php
Database interface adds usesHost() and databaseUserExists() methods. AbstractDatabase implements both with host checking; Postgresql overrides usesHost() to return false.
Database user creation and update validation with host resolution
app/Actions/Database/CreateDatabaseUser.php, app/Actions/Database/UpdateDatabaseUser.php
Create/Update now centralise host handling via resolveHost()/changedHost(). Username uniqueness is validated via databaseUserExists() and host rules are applied conditionally based on handler->usesHost(), including regex constraints and required/nullable logic.
Enum table display contracts
app/Enums/DatabaseUserPermission.php, app/Enums/DatabaseUserStatus.php
Both enums implement HasTableDisplay alongside VitoEnum to support table rendering.
Resource serialization and controller table integration
app/Http/Resources/DatabaseUserResource.php, app/Http/Controllers/DatabaseUserController.php
DatabaseUserResource emits permission as human-readable text and adds permission_color. Controller index() uses DatabaseUserTable::withHost($handler->usesHost())->paginate() and exposes usesHost to the Inertia payload.
Database user table component
app/Tables/Servers/DatabaseUserTable.php
New table class with withHost() toggle, pagination, ordering, and columns for username, conditional host column, permission, linked databases, timestamps, status, and row actions.
Create and edit form components with conditional host display
resources/js/pages/database-users/components/create-database-user.tsx, resources/js/pages/database-users/components/edit-database-user.tsx
Components accept usesHost prop and only render remote/host fields when true. Create form submit is wired to the form element.
Database users page refactor with VitoTable and row actions
resources/js/pages/database-users/index.tsx, resources/js/vito-table-setup.ts
Page switches to VitoTable, derives usesHost from page props, registers DatabaseUserDatabases cell, and renders per-row action dropdown (Edit, Link, Delete) with confirm-delete wiring.
Component registration and type updates
resources/js/components/database-user-databases.tsx, resources/js/types/database-user.d.ts
Adds DatabaseUserDatabases cell component that renders linked databases as badges (or a muted dash). DatabaseUser type gains permission_color literal union.
Comprehensive test coverage for host validation and visibility
tests/Feature/DatabaseUserTest.php
Adds tests for same-username different-host success, duplicate username+host failure, PostgreSQL uniqueness, update host collision failure, malicious host rejection, empty-host defaulting, PostgreSQL synced-user update behaviour, and index host-column visibility. Includes usePostgresql() test helper.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • saeedvaziry
🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is vague and uses generic terms like 'fix' without clearly conveying the primary change; it abbreviates database names without explaining what issues are being addressed. Revise the title to be more specific and descriptive. For example: 'Add host-based database user management for MySQL and PostgreSQL' or 'Implement per-host validation for database users'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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 database-user handling differences between MySQL-style engines (user identity includes host) and PostgreSQL (no host-based user identity), and updates the database-users UI to use the app’s VitoTable/InertiaTable setup.

Changes:

  • Introduces engine-aware “uses host” + “user exists” behavior on the database service layer, and updates create/update validations accordingly.
  • Migrates the Database Users index page to VitoTable, including a custom cell renderer for linked databases and conditional display of the host column.
  • Expands feature tests to cover host-collision rules, PostgreSQL behavior, and host validation/hardening.

Reviewed changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/Feature/DatabaseUserTest.php Adds coverage for host uniqueness rules (MySQL) and host-less behavior (PostgreSQL), plus UI column visibility assertions.
resources/js/vito-table-setup.ts Registers a custom cell component for InertiaTable rendering.
resources/js/types/database-user.d.ts Adds permission_color to match UI/table display needs.
resources/js/pages/database-users/index.tsx Switches to VitoTable + dropdown actions; passes usesHost into dialogs/components.
resources/js/pages/database-users/components/edit-database-user.tsx Hides remote/host fields when the engine doesn’t use hosts.
resources/js/pages/database-users/components/create-database-user.tsx Adds usesHost gating and switches submit to a real form submit button.
resources/js/pages/database-users/components/columns.tsx Removes old TanStack table column definitions (replaced by InertiaTable).
resources/js/components/database-user-databases.tsx New cell component to render linked databases as badges (or “-” when empty).
app/Tables/Servers/DatabaseUserTable.php New InertiaTable definition with conditional host column and component-based databases column.
app/Services/Database/Postgresql.php Declares usesHost() = false and overrides existence checks to be username-only.
app/Services/Database/Database.php Extends the database service contract with usesHost() and databaseUserExists().
app/Services/Database/AbstractDatabase.php Provides default host-based implementations for engines like MySQL/MariaDB.
app/Http/Resources/DatabaseUserResource.php Returns permission text + color (consistent with enum UI display expectations).
app/Http/Controllers/DatabaseUserController.php Uses DatabaseUserTable for the index payload and toggles host column based on engine.
app/Enums/DatabaseUserStatus.php Implements HasTableDisplay for InertiaTable enum rendering.
app/Enums/DatabaseUserPermission.php Implements HasTableDisplay for InertiaTable enum rendering.
app/Actions/Database/UpdateDatabaseUser.php Normalizes host-change logic and adds engine-aware collision checks.
app/Actions/Database/CreateDatabaseUser.php Introduces engine-aware existence checks and host validation/normalization.

Comment thread app/Actions/Database/CreateDatabaseUser.php
Comment thread app/Actions/Database/CreateDatabaseUser.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/database-users/index.tsx`:
- Line 26: Replace the frontend's derived usesHost boolean (currently computed
as page.props.server.services['database'] !== 'postgresql' in usesHost) with an
explicit Inertia prop provided by the backend; update DatabaseUserController to
compute usesHost using the existing backend logic
(AbstractDatabase::usesHost()/Postgresql::usesHost()) and include it in the
Inertia props sent to the page, then change the frontend to read
page.props.usesHost (or the chosen prop name) instead of inspecting
page.props.server.services['database'], so the frontend stays aligned with
backend handlers and future DB types.
🪄 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: dde527a5-3e52-4a08-9763-bb3b5329134b

📥 Commits

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

📒 Files selected for processing (18)
  • app/Actions/Database/CreateDatabaseUser.php
  • app/Actions/Database/UpdateDatabaseUser.php
  • app/Enums/DatabaseUserPermission.php
  • app/Enums/DatabaseUserStatus.php
  • app/Http/Controllers/DatabaseUserController.php
  • app/Http/Resources/DatabaseUserResource.php
  • app/Services/Database/AbstractDatabase.php
  • app/Services/Database/Database.php
  • app/Services/Database/Postgresql.php
  • app/Tables/Servers/DatabaseUserTable.php
  • resources/js/components/database-user-databases.tsx
  • resources/js/pages/database-users/components/columns.tsx
  • resources/js/pages/database-users/components/create-database-user.tsx
  • resources/js/pages/database-users/components/edit-database-user.tsx
  • resources/js/pages/database-users/index.tsx
  • resources/js/types/database-user.d.ts
  • resources/js/vito-table-setup.ts
  • tests/Feature/DatabaseUserTest.php
💤 Files with no reviewable changes (1)
  • resources/js/pages/database-users/components/columns.tsx

Comment thread resources/js/pages/database-users/index.tsx Outdated
@RichardAnderson RichardAnderson merged commit e676018 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