Skip to content

Remove usergroup from primary key of pma__users - #20358

Open
MoonE wants to merge 1 commit into
phpmyadmin:QA_5_2from
MoonE:pma-user-groups-table-primary-key
Open

Remove usergroup from primary key of pma__users#20358
MoonE wants to merge 1 commit into
phpmyadmin:QA_5_2from
MoonE:pma-user-groups-table-primary-key

Conversation

@MoonE

@MoonE MoonE commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Description

Each user can only belong to a single pma usergroup, so the primary key should only be on username.

See the code that assigns users to groups. If a username already exists in the table it updates this row instead of inserting a new one.

$sqlQuery = 'SELECT `usergroup` FROM ' . $userTable
. " WHERE `username` = '" . $this->dbi->escapeString($username) . "'";
$oldUserGroup = $this->dbi->fetchValue($sqlQuery, 0, DatabaseInterface::CONNECT_CONTROL);
if ($oldUserGroup === false) {
$updQuery = 'INSERT INTO ' . $userTable . '(`username`, `usergroup`)'
. " VALUES ('" . $this->dbi->escapeString($username) . "', "
. "'" . $this->dbi->escapeString($userGroup) . "')";
} else {
if (empty($userGroup)) {
$updQuery = 'DELETE FROM ' . $userTable
. " WHERE `username`='" . $this->dbi->escapeString($username) . "'";
} elseif ($oldUserGroup != $userGroup) {
$updQuery = 'UPDATE ' . $userTable
. " SET `usergroup`='" . $this->dbi->escapeString($userGroup) . "'"
. " WHERE `username`='" . $this->dbi->escapeString($username) . "'";
}
}
if (! isset($updQuery)) {
return;
}
$this->dbi->queryAsControlUser($updQuery);

Is there a mechanism in place to update existing pma tables?

So the primary key should be just username.

Signed-off-by: Maximilian Krög <maxi_kroeg@web.de>
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.

1 participant