add username migration
This commit is contained in:
parent
5b045335a1
commit
c25ba2dd28
20
database/migrations/data/20230923_1905_username.php
Normal file
20
database/migrations/data/20230923_1905_username.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use MapGuesser\PersistentData\Model\User;
|
||||
use MapGuesser\Repository\UserRepository;
|
||||
use MapGuesser\Util\UsernameGenerator;
|
||||
use SokoWeb\Database\Query\Select;
|
||||
|
||||
$select = new Select(Container::$dbConnection);
|
||||
$users = Container::$persistentDataManager->selectMultipleFromDb($select, User::class);
|
||||
$userRepository = new UserRepository();
|
||||
$usernameGenerator = new UsernameGenerator();
|
||||
|
||||
foreach ($users as $user) {
|
||||
do {
|
||||
$username = $usernameGenerator->generate();
|
||||
} while ($userRepository->getByUsername($username));
|
||||
|
||||
$user->setUsername($username);
|
||||
Container::$persistentDataManager->saveToDb($user);
|
||||
}
|
3
database/migrations/structure/20230923_1905_username.sql
Normal file
3
database/migrations/structure/20230923_1905_username.sql
Normal file
@ -0,0 +1,3 @@
|
||||
ALTER TABLE `users`
|
||||
ADD `username` VARCHAR(255) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL AFTER `email`,
|
||||
ADD UNIQUE `username` (`username`);
|
Loading…
Reference in New Issue
Block a user