-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20231101200039 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Add User username'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE "user" ADD username VARCHAR(80) NOT NULL'); | ||
$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D649F85E0677 ON "user" (username)'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql('CREATE SCHEMA public'); | ||
$this->addSql('DROP INDEX UNIQ_8D93D649F85E0677'); | ||
$this->addSql('ALTER TABLE "user" DROP username'); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,13 +46,15 @@ private function createUser(int $number): User | |
{ | ||
return ($user = new User()) | ||
->setEmail("mail$number@mail.com") | ||
->setUsername("user-$number") | ||
->setPassword($this->userPasswordHasher->hashPassword($user, 'dev')); | ||
} | ||
|
||
private function createAdmin(): User | ||
{ | ||
return ($user = new User()) | ||
->setEmail('[email protected]') | ||
->setUsername('admin') | ||
->setRoles([User::ROLE_ADMIN]) | ||
->setPassword($this->userPasswordHasher->hashPassword($user, 'dev')); | ||
} | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
trait UsernameableTrait | ||
{ | ||
#[ORM\Column(type: 'string', length: 80, unique: true)] | ||
private ?string $username = null; | ||
|
||
final public function getUsername(): string | ||
{ | ||
return $this->username; | ||
} | ||
|
||
final public function setUsername(string $username): self | ||
{ | ||
$this->username = $username; | ||
|
||
return $this; | ||
} | ||
} |