[FIX] v3.x: Match synced MySQL users by (username, host) to avoid collapsing multi-host accounts#1075
Merged
saeedvaziry merged 1 commit intovitodeploy:3.xfrom May 2, 2026
Conversation
…g multi-host accounts SyncDatabaseUsers previously matched existing database_users rows by username only. MySQL and MariaDB treat 'user'@'localhost' and 'user'@'127.0.0.1' as independent accounts with potentially different passwords and grants, so collapsing them onto a single row caused silent data corruption: the databases column was overwritten in an order-dependent way, additional host variants were never inserted, and the stored host no longer matched the grants shown under it. The lookup now scopes by (username, host) whenever the handler returns a non-empty host, aligning sync with CreateDatabaseUser, UpdateDatabaseUser and DeleteDatabaseUser. PostgreSQL keeps the original username-only match because its get-users-list view returns an empty host (roles are host-agnostic); an unconditional composite filter would miss the existing UI-created row and insert a duplicate (rolname, '') record on every sync. Adds regression tests covering MySQL multi-host sync, MySQL sync idempotency and the PostgreSQL no-duplicate-row invariant.
Member
|
@erhanurgun I appreceate the efforts on the issues and PRs however I rather to skip the long reads with AI generated too much details. Lets keep the issues and PR descriptions for us humans with our own words. Thanks |
Contributor
Author
|
Sorry for the wall of text, you're right. Trimmed both the PR description and the issue. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1074
SyncDatabaseUserswas looking up existing rows by username only, so on a server with both'app'@'localhost'and'app'@'127.0.0.1'one row kept being overwritten on every sync and the second one was never inserted. The Vito UI then ended up showing adatabaseslist that didn't match the host above it.Fix is one extra
where('host', ...)when the handler returns a non-empty host. Postgres is left on the username-only path because itsget-users-listview returns''for host (roles are host-agnostic) and an unconditional composite filter would insert a duplicate(rolname, '')row on every sync.vendor/bin/phpunit tests/Feature/DatabaseUserTest.php-> 15/15 green; three new tests cover the multi-host case, idempotent re-sync, and the Postgres no-duplicate regression.CreateDatabaseUser,UpdateDatabaseUser, andDeleteDatabaseUseralready scope by(username, host), so this just brings sync in line.No migration. A composite unique index on
(server_id, username, host)would be a natural follow-up but felt out of scope.