Skip to content

Commit

Permalink
Create the Space (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquelopeslima authored Aug 27, 2024
1 parent 83ec5c1 commit bf4773a
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 31 deletions.
8 changes: 3 additions & 5 deletions migrations/Version20240819123854.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ public function up(Schema $schema): void
)
');

$this->addSql('COMMENT ON COLUMN "app_user".id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN "app_user".created_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN "app_user".updated_at IS \'(DC2Type:datetime_mutable)\'');
$this->addSql('COMMENT ON COLUMN "app_user".deleted_at IS \'(DC2Type:datetime_mutable)\'');
$this->addSql('COMMENT ON COLUMN app_user.id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN app_user.created_at IS \'(DC2Type:datetime_immutable)\'');

$this->addSql('CREATE UNIQUE INDEX UNIQ_1483A5E9E7927C74 ON app_user (email)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_88BDF3E9E7927C74 ON app_user (email)');
}

public function down(Schema $schema): void
Expand Down
24 changes: 9 additions & 15 deletions migrations/Version20240822192752.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@ public function up(Schema $schema): void
)
');

$this->addSql('COMMENT ON COLUMN "agent".id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN "agent".created_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN "agent".updated_at IS \'(DC2Type:datetime_mutable)\'');
$this->addSql('COMMENT ON COLUMN "agent".deleted_at IS \'(DC2Type:datetime_mutable)\'');
$this->addSql('COMMENT ON COLUMN agent.id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN agent.created_at IS \'(DC2Type:datetime_immutable)\'');

$this->addSql('
CREATE TABLE project (
id UUID NOT NULL,
name VARCHAR(100) NOT NULL,
created_by UUID NOT NULL,
created_by_id UUID NOT NULL,
parent_id UUID DEFAULT NULL,
space_id UUID DEFAULT NULL,
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL DEFAULT NOW(),
Expand All @@ -46,13 +44,11 @@ public function up(Schema $schema): void
)
');

$this->addSql('COMMENT ON COLUMN "project".id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN project.created_by IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN project.id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN project.created_by_id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN project.parent_id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN project.space_id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN "project".created_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN "project".updated_at IS \'(DC2Type:datetime_mutable)\'');
$this->addSql('COMMENT ON COLUMN "project".deleted_at IS \'(DC2Type:datetime_mutable)\'');
$this->addSql('COMMENT ON COLUMN project.created_at IS \'(DC2Type:datetime_immutable)\'');

$this->addSql('
CREATE TABLE space (
Expand All @@ -65,12 +61,10 @@ public function up(Schema $schema): void
)
');

$this->addSql('COMMENT ON COLUMN "space".id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN "space".created_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN "space".updated_at IS \'(DC2Type:datetime_mutable)\'');
$this->addSql('COMMENT ON COLUMN "space".deleted_at IS \'(DC2Type:datetime_mutable)\'');
$this->addSql('COMMENT ON COLUMN space.id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN space.created_at IS \'(DC2Type:datetime_immutable)\'');

$this->addSql('ALTER TABLE project ADD CONSTRAINT fk_project_created_by_agent FOREIGN KEY (created_by) REFERENCES agent (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE project ADD CONSTRAINT fk_project_created_by_id_agent FOREIGN KEY (created_by_id) REFERENCES agent (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE project ADD CONSTRAINT fk_project_parent_id_project FOREIGN KEY (parent_id) REFERENCES project (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE project ADD CONSTRAINT fk_project_space_id_space FOREIGN KEY (space_id) REFERENCES space (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
}
Expand Down
37 changes: 37 additions & 0 deletions migrations/Version20240826174829.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20240826174829 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add the columns parent_id and created_by_id in space table';
}

public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE space ADD created_by_id UUID');
$this->addSql('ALTER TABLE space ADD parent_id UUID DEFAULT NULL');

$this->addSql('COMMENT ON COLUMN space.created_by_id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN space.parent_id IS \'(DC2Type:uuid)\'');

$this->addSql('ALTER TABLE space ADD CONSTRAINT fk_space_created_by_id_agent FOREIGN KEY (created_by_id) REFERENCES agent (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE space ADD CONSTRAINT fk_space_parent_id_space FOREIGN KEY (parent_id) REFERENCES space (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE space DROP CONSTRAINT fk_space_created_by_id_agent');
$this->addSql('ALTER TABLE space DROP CONSTRAINT fk_space_parent_id_space');

$this->addSql('ALTER TABLE space DROP created_by_id');
$this->addSql('ALTER TABLE space DROP parent_id');
}
}
23 changes: 17 additions & 6 deletions src/DataFixtures/ProjectFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class ProjectFixtures extends Fixture implements DependentFixtureInterface
'name' => 'Vozes do Sertão',
'createdBy' => AgentFixtures::AGENT_ID_1,
'parent' => null,
'space' => null,
'space' => SpaceFixtures::SPACE_ID_4,
'createdAt' => '2024-07-10T11:30:00+00:00',
'updatedAt' => null,
'deletedAt' => null,
Expand All @@ -50,7 +50,7 @@ final class ProjectFixtures extends Fixture implements DependentFixtureInterface
'name' => 'Ritmos do Mundo',
'createdBy' => AgentFixtures::AGENT_ID_1,
'parent' => null,
'space' => null,
'space' => SpaceFixtures::SPACE_ID_5,
'createdAt' => '2024-07-16T17:22:00+00:00',
'updatedAt' => null,
'deletedAt' => null,
Expand All @@ -70,7 +70,7 @@ final class ProjectFixtures extends Fixture implements DependentFixtureInterface
'name' => 'Repente e Viola',
'createdBy' => AgentFixtures::AGENT_ID_1,
'parent' => null,
'space' => null,
'space' => SpaceFixtures::SPACE_ID_5,
'createdAt' => '2024-07-22T16:20:00+00:00',
'updatedAt' => null,
'deletedAt' => null,
Expand All @@ -80,7 +80,7 @@ final class ProjectFixtures extends Fixture implements DependentFixtureInterface
'name' => 'Pé de Serra Cultural',
'createdBy' => AgentFixtures::AGENT_ID_1,
'parent' => null,
'space' => null,
'space' => SpaceFixtures::SPACE_ID_6,
'createdAt' => '2024-08-10T11:26:00+00:00',
'updatedAt' => null,
'deletedAt' => null,
Expand Down Expand Up @@ -110,7 +110,7 @@ final class ProjectFixtures extends Fixture implements DependentFixtureInterface
'name' => 'Retalhos do Nordeste',
'createdBy' => AgentFixtures::AGENT_ID_1,
'parent' => self::PROJECT_ID_8,
'space' => null,
'space' => SpaceFixtures::SPACE_ID_6,
'createdAt' => '2024-08-13T20:25:00+00:00',
'updatedAt' => null,
'deletedAt' => null,
Expand All @@ -120,7 +120,7 @@ final class ProjectFixtures extends Fixture implements DependentFixtureInterface
'name' => 'Arte da Caatinga',
'createdBy' => AgentFixtures::AGENT_ID_1,
'parent' => self::PROJECT_ID_9,
'space' => null,
'space' => SpaceFixtures::SPACE_ID_3,
'createdAt' => '2024-08-14T10:00:00+00:00',
'updatedAt' => null,
'deletedAt' => null,
Expand All @@ -137,8 +137,19 @@ public function load(ObjectManager $manager): void
foreach (self::PROJECTS as $projectData) {
/* @var Project $project */
$project = $this->serializer->denormalize($projectData, Project::class);

$project->setCreatedBy($this->getReference(sprintf('%s-%s', AgentFixtures::AGENT_ID_PREFIX, $projectData['createdBy'])));

if (null !== $projectData['parent']) {
$parent = $this->getReference(sprintf('%s-%s', self::PROJECT_ID_PREFIX, $projectData['parent']));
$project->setParent($parent);
}

if (null !== $projectData['space']) {
$parent = $this->getReference(sprintf('%s-%s', SpaceFixtures::SPACE_ID_PREFIX, $projectData['space']));
$project->setSpace($parent);
}

$this->setReference(sprintf('%s-%s', self::PROJECT_ID_PREFIX, $projectData['id']), $project);

$manager->persist($project);
Expand Down
41 changes: 38 additions & 3 deletions src/DataFixtures/SpaceFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

use App\Entity\Space;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\Serializer\SerializerInterface;

final class SpaceFixtures extends Fixture
final class SpaceFixtures extends Fixture implements DependentFixtureInterface
{
public const string SPACE_ID_PREFIX = 'space';
public const string SPACE_ID_1 = '69461af3-52f2-4c6b-ad30-ce92e478e9bd';
Expand All @@ -27,69 +28,89 @@ final class SpaceFixtures extends Fixture
[
'id' => self::SPACE_ID_1,
'name' => 'SECULT',
'createdBy' => AgentFixtures::AGENT_ID_1,
'parent' => null,
'createdAt' => '2024-07-10T11:30:00+00:00',
'updatedAt' => null,
'deletedAt' => null,
],
[
'id' => self::SPACE_ID_2,
'name' => 'Sítio das Artes',
'createdBy' => AgentFixtures::AGENT_ID_1,
'parent' => null,
'createdAt' => '2024-07-11T10:49:00+00:00',
'updatedAt' => null,
'deletedAt' => null,
],
[
'id' => self::SPACE_ID_3,
'name' => 'Ritmos do Mundo',
'name' => 'Galeria Caatinga',
'createdBy' => AgentFixtures::AGENT_ID_1,
'parent' => null,
'createdAt' => '2024-07-16T17:22:00+00:00',
'updatedAt' => null,
'deletedAt' => null,
],
[
'id' => self::SPACE_ID_4,
'name' => 'Recanto do Cordel',
'createdBy' => AgentFixtures::AGENT_ID_1,
'parent' => self::SPACE_ID_3,
'createdAt' => '2024-07-17T15:12:00+00:00',
'updatedAt' => null,
'deletedAt' => null,
],
[
'id' => self::SPACE_ID_5,
'name' => 'Galeria Caatinga',
'name' => 'Ritmos do Mundo',
'createdBy' => AgentFixtures::AGENT_ID_1,
'parent' => self::SPACE_ID_3,
'createdAt' => '2024-07-22T16:20:00+00:00',
'updatedAt' => null,
'deletedAt' => null,
],
[
'id' => self::SPACE_ID_6,
'name' => 'Casa do Sertão',
'createdBy' => AgentFixtures::AGENT_ID_1,
'parent' => self::SPACE_ID_3,
'createdAt' => '2024-08-10T11:26:00+00:00',
'updatedAt' => null,
'deletedAt' => null,
],
[
'id' => self::SPACE_ID_7,
'name' => 'Vila do Baião',
'createdBy' => AgentFixtures::AGENT_ID_1,
'parent' => self::SPACE_ID_3,
'createdAt' => '2024-08-11T15:54:00+00:00',
'updatedAt' => null,
'deletedAt' => null,
],
[
'id' => self::SPACE_ID_8,
'name' => 'Centro Cultural Asa Branca',
'createdBy' => AgentFixtures::AGENT_ID_1,
'parent' => null,
'createdAt' => '2024-08-12T14:24:00+00:00',
'updatedAt' => null,
'deletedAt' => null,
],
[
'id' => self::SPACE_ID_9,
'name' => 'Casa da Capoeira',
'createdBy' => AgentFixtures::AGENT_ID_1,
'parent' => null,
'createdAt' => '2024-08-13T20:25:00+00:00',
'updatedAt' => null,
'deletedAt' => null,
],
[
'id' => self::SPACE_ID_10,
'name' => 'Dragão do Mar',
'createdBy' => AgentFixtures::AGENT_ID_1,
'parent' => null,
'createdAt' => '2024-08-14T10:00:00+00:00',
'updatedAt' => null,
'deletedAt' => null,
Expand All @@ -107,11 +128,25 @@ public function load(ObjectManager $manager): void
/* @var Space $space */
$space = $this->serializer->denormalize($spaceData, Space::class);

$space->setCreatedBy($this->getReference(sprintf('%s-%s', AgentFixtures::AGENT_ID_PREFIX, $spaceData['createdBy'])));

if (null !== $spaceData['parent']) {
$parent = $this->getReference(sprintf('%s-%s', self::SPACE_ID_PREFIX, $spaceData['parent']));
$space->setParent($parent);
}

$this->setReference(sprintf('%s-%s', self::SPACE_ID_PREFIX, $spaceData['id']), $space);

$manager->persist($space);
}

$manager->flush();
}

public function getDependencies(): array
{
return [
AgentFixtures::class,
];
}
}
30 changes: 29 additions & 1 deletion src/Entity/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ class Project extends AbstractEntity
#[ORM\Column(length: 100)]
private ?string $name = null;

#[ORM\ManyToOne(targetEntity: self::class)]
#[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
private ?Project $parent = null;

#[ORM\ManyToOne(targetEntity: Space::class)]
#[ORM\JoinColumn(name: 'space_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
private ?Space $space = null;

#[ORM\ManyToOne(targetEntity: Agent::class)]
#[ORM\JoinColumn(name: 'created_by', referencedColumnName: 'id', nullable: false, onDelete: 'SET NULL')]
#[ORM\JoinColumn(name: 'created_by_id', referencedColumnName: 'id', nullable: false, onDelete: 'SET NULL')]
private Agent $createdBy;

#[ORM\Column]
Expand Down Expand Up @@ -54,6 +62,26 @@ public function setName(string $name): void
$this->name = $name;
}

public function getParent(): ?Project
{
return $this->parent;
}

public function setParent(?Project $parent): void
{
$this->parent = $parent;
}

public function getSpace(): ?Space
{
return $this->space;
}

public function setSpace(?Space $space): void
{
$this->space = $space;
}

public function getCreatedBy(): Agent
{
return $this->createdBy;
Expand Down
28 changes: 28 additions & 0 deletions src/Entity/Space.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ class Space extends AbstractEntity
#[ORM\Column(length: 100)]
private ?string $name = null;

#[ORM\ManyToOne(targetEntity: Agent::class)]
#[ORM\JoinColumn(name: 'created_by_id', referencedColumnName: 'id', nullable: false, onDelete: 'SET NULL')]
private Agent $createdBy;

#[ORM\ManyToOne(targetEntity: self::class)]
#[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
private ?Space $parent = null;

#[ORM\Column]
private DateTimeImmutable $createdAt;

Expand Down Expand Up @@ -50,6 +58,26 @@ public function setName(string $name): void
$this->name = $name;
}

public function getCreatedBy(): Agent
{
return $this->createdBy;
}

public function setCreatedBy(Agent $createdBy): void
{
$this->createdBy = $createdBy;
}

public function getParent(): ?Space
{
return $this->parent;
}

public function setParent(?Space $parent): void
{
$this->parent = $parent;
}

public function getCreatedAt(): ?DateTimeImmutable
{
return $this->createdAt;
Expand Down
Loading

0 comments on commit bf4773a

Please sign in to comment.