1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 14:14:04 +00:00

Use % for CREATE % GRANT queries

This commit is contained in:
Samuel Štancl 2020-05-20 14:33:24 +02:00
parent 1329356b4b
commit e6e4548a22
5 changed files with 61 additions and 6 deletions

View file

@ -30,14 +30,14 @@ class PermissionControlledMySQLDatabaseManager extends MySQLDatabaseManager impl
throw new TenantDatabaseUserAlreadyExistsException($username);
}
$this->database()->statement("CREATE USER `{$username}`@`{$hostname}` IDENTIFIED BY '{$password}'");
$this->database()->statement("CREATE USER `{$username}`@`%` IDENTIFIED BY '{$password}'");
$grants = implode(', ', static::$grants);
if ($this->isVersion8()) { // MySQL 8+
$grantQuery = "GRANT $grants ON `$database`.* TO `$username`@`$hostname`";
$grantQuery = "GRANT $grants ON `$database`.* TO `$username`@`%`";
} else { // MySQL 5.7
$grantQuery = "GRANT $grants ON `$database`.* TO `$username`@`$hostname` IDENTIFIED BY '$password'";
$grantQuery = "GRANT $grants ON `$database`.* TO `$username`@`%` IDENTIFIED BY '$password'";
}
return $this->database()->statement($grantQuery);