diff --git a/symfony/fixtures/projects.yaml b/symfony/fixtures/projects.yaml index 4f9b6593..d3c80cb4 100644 --- a/symfony/fixtures/projects.yaml +++ b/symfony/fixtures/projects.yaml @@ -21,4 +21,5 @@ App\Entity\Project: projectManagerTel: projectManagerPhoto: 'https://randomuser.me/api/portraits/men/.jpg' website: - logo: \ No newline at end of file + logo: + createdBy: '@user_*' \ No newline at end of file diff --git a/symfony/migrations/Version20241016122346.php b/symfony/migrations/Version20241016124248.php similarity index 55% rename from symfony/migrations/Version20241016122346.php rename to symfony/migrations/Version20241016124248.php index 36cbb771..c53569c7 100644 --- a/symfony/migrations/Version20241016122346.php +++ b/symfony/migrations/Version20241016124248.php @@ -10,7 +10,7 @@ /** * Auto-generated Migration: Please modify to your needs! */ -final class Version20241016122346 extends AbstractMigration +final class Version20241016124248 extends AbstractMigration { public function getDescription(): string { @@ -20,23 +20,31 @@ public function getDescription(): string public function up(Schema $schema): void { // this up() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE project ADD created_by INT DEFAULT NULL'); + $this->addSql('ALTER TABLE project ADD updated_by INT DEFAULT NULL'); $this->addSql('ALTER TABLE project ADD deliverables TEXT DEFAULT NULL'); $this->addSql('ALTER TABLE project ADD calendar TEXT DEFAULT NULL'); - $this->addSql('ALTER TABLE project ADD created_by VARCHAR(255) DEFAULT NULL'); - $this->addSql('ALTER TABLE project ADD updated_by VARCHAR(255) DEFAULT NULL'); $this->addSql('ALTER TABLE project ADD slug VARCHAR(128) DEFAULT NULL'); + $this->addSql('ALTER TABLE project ADD CONSTRAINT FK_2FB3D0EEDE12AB56 FOREIGN KEY (created_by) REFERENCES "user" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE project ADD CONSTRAINT FK_2FB3D0EE16FE72E1 FOREIGN KEY (updated_by) REFERENCES "user" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('CREATE UNIQUE INDEX UNIQ_2FB3D0EE989D9B62 ON project (slug)'); + $this->addSql('CREATE INDEX IDX_2FB3D0EEDE12AB56 ON project (created_by)'); + $this->addSql('CREATE INDEX IDX_2FB3D0EE16FE72E1 ON project (updated_by)'); } public function down(Schema $schema): void { // this down() migration is auto-generated, please modify it to your needs $this->addSql('CREATE SCHEMA public'); + $this->addSql('ALTER TABLE project DROP CONSTRAINT FK_2FB3D0EEDE12AB56'); + $this->addSql('ALTER TABLE project DROP CONSTRAINT FK_2FB3D0EE16FE72E1'); $this->addSql('DROP INDEX UNIQ_2FB3D0EE989D9B62'); - $this->addSql('ALTER TABLE project DROP deliverables'); - $this->addSql('ALTER TABLE project DROP calendar'); + $this->addSql('DROP INDEX IDX_2FB3D0EEDE12AB56'); + $this->addSql('DROP INDEX IDX_2FB3D0EE16FE72E1'); $this->addSql('ALTER TABLE project DROP created_by'); $this->addSql('ALTER TABLE project DROP updated_by'); + $this->addSql('ALTER TABLE project DROP deliverables'); + $this->addSql('ALTER TABLE project DROP calendar'); $this->addSql('ALTER TABLE project DROP slug'); } } diff --git a/symfony/src/Entity/Project.php b/symfony/src/Entity/Project.php index 1f05d1d5..de8be5ad 100644 --- a/symfony/src/Entity/Project.php +++ b/symfony/src/Entity/Project.php @@ -13,13 +13,13 @@ use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\QueryParameter; use App\Controller\Project\SimilarProjectsAction; -use App\Entity\Trait\SluggableEntity; use App\Repository\ProjectRepository; +use App\Entity\Trait\SluggableEntity; use App\Entity\Trait\TimestampableEntity; +use App\Entity\Trait\BlameableEntity; use Doctrine\Common\Collections\Collection; use Jsor\Doctrine\PostGIS\Types\PostGISType; use Doctrine\Common\Collections\ArrayCollection; -use Gedmo\Blameable\Traits\BlameableEntity; use Symfony\Component\Serializer\Attribute\Groups; #[ORM\Entity(repositoryClass: ProjectRepository::class)] diff --git a/symfony/src/Entity/Trait/BlamableEntity.php b/symfony/src/Entity/Trait/BlameableEntity.php similarity index 97% rename from symfony/src/Entity/Trait/BlamableEntity.php rename to symfony/src/Entity/Trait/BlameableEntity.php index 85dbd4b0..c807df62 100644 --- a/symfony/src/Entity/Trait/BlamableEntity.php +++ b/symfony/src/Entity/Trait/BlameableEntity.php @@ -8,7 +8,7 @@ use Gedmo\Mapping\Annotation as Gedmo; use Symfony\Component\Serializer\Attribute\Groups; -trait BlameableEntityTrait +trait BlameableEntity { #[ORM\ManyToOne(targetEntity: User::class)] #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL', name: 'created_by')]