-
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.
see: #20
- Loading branch information
Showing
3 changed files
with
124 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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20231101092817 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Add User'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql('CREATE TABLE "user" (id UUID NOT NULL, email VARCHAR(180) NOT NULL, roles JSON NOT NULL, password VARCHAR(255) NOT NULL, archived_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, slug VARCHAR(255) NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))'); | ||
$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D649E7927C74 ON "user" (email)'); | ||
$this->addSql('COMMENT ON COLUMN "user".id IS \'(DC2Type:uuid)\''); | ||
$this->addSql('COMMENT ON COLUMN "user".archived_at IS \'(DC2Type:datetime_immutable)\''); | ||
$this->addSql('COMMENT ON COLUMN "user".created_at IS \'(DC2Type:datetime_immutable)\''); | ||
$this->addSql('COMMENT ON COLUMN "user".updated_at IS \'(DC2Type:datetime_immutable)\''); | ||
$this->addSql('ALTER TABLE category ALTER name SET NOT NULL'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql('CREATE SCHEMA public'); | ||
$this->addSql('DROP TABLE "user"'); | ||
$this->addSql('ALTER TABLE category ALTER name DROP NOT NULL'); | ||
} | ||
} |
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,54 @@ | ||
<?php | ||
|
||
namespace App\DataFixtures; | ||
|
||
use App\Entity\User; | ||
use App\Repository\ProjectRepository; | ||
use Doctrine\Bundle\FixturesBundle\Fixture; | ||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface; | ||
use Doctrine\Persistence\ObjectManager; | ||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; | ||
|
||
final class UserFixtures extends Fixture implements OrderedFixtureInterface | ||
{ | ||
public const QUANTITY = 10; | ||
|
||
public function __construct( | ||
private readonly ProjectRepository $projectRepository, | ||
private readonly UserPasswordHasherInterface $userPasswordHasher | ||
) { | ||
} | ||
|
||
public function load(ObjectManager $manager): void | ||
{ | ||
$admin = $this->createAdmin(); | ||
$manager->persist($admin); | ||
|
||
for ($i = 1; $i <= self::QUANTITY; ++$i) { | ||
$user = $this->createUser($i); | ||
$manager->persist($user); | ||
} | ||
|
||
$manager->flush(); | ||
} | ||
|
||
private function createUser(int $number): User | ||
{ | ||
return ($user = new User()) | ||
->setEmail("mail$number@mail.com") | ||
->setPassword($this->userPasswordHasher->hashPassword($user, 'dev')); | ||
} | ||
|
||
private function createAdmin(): User | ||
{ | ||
return ($user = new User()) | ||
->setEmail('[email protected]') | ||
->setRoles([User::ROLE_ADMIN]) | ||
->setPassword($this->userPasswordHasher->hashPassword($user, 'dev')); | ||
} | ||
|
||
public function getOrder(): int | ||
{ | ||
return 3; | ||
} | ||
} |
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