-
Notifications
You must be signed in to change notification settings - Fork 10
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
1 parent
b9ba154
commit bc700ad
Showing
5 changed files
with
440 additions
and
0 deletions.
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,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20240829143857 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Creates/Drops organization table'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql('CREATE TABLE organization ( | ||
id UUID NOT NULL, | ||
owner_id UUID NOT NULL, | ||
created_by UUID NOT NULL, | ||
name VARCHAR(100) NOT NULL, | ||
description VARCHAR(255) DEFAULT NULL, | ||
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, | ||
updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, | ||
deleted_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, | ||
PRIMARY KEY(id) | ||
)'); | ||
$this->addSql('CREATE INDEX IDX_C1EE637C7E3C61F9 ON organization (owner_id)'); | ||
$this->addSql('CREATE INDEX IDX_C1EE637CDE12AB56 ON organization (created_by)'); | ||
$this->addSql('COMMENT ON COLUMN organization.id IS \'(DC2Type:uuid)\''); | ||
$this->addSql('COMMENT ON COLUMN organization.owner_id IS \'(DC2Type:uuid)\''); | ||
$this->addSql('COMMENT ON COLUMN organization.created_by IS \'(DC2Type:uuid)\''); | ||
$this->addSql('COMMENT ON COLUMN organization.created_at IS \'(DC2Type:datetime_immutable)\''); | ||
$this->addSql('CREATE TABLE organizations_agents ( | ||
organization_id UUID NOT NULL, | ||
agent_id UUID NOT NULL, | ||
PRIMARY KEY(organization_id, agent_id) | ||
)'); | ||
$this->addSql('CREATE INDEX IDX_FAEB3B732C8A3DE ON organizations_agents (organization_id)'); | ||
$this->addSql('CREATE INDEX IDX_FAEB3B73414710B ON organizations_agents (agent_id)'); | ||
$this->addSql('COMMENT ON COLUMN organizations_agents.organization_id IS \'(DC2Type:uuid)\''); | ||
$this->addSql('COMMENT ON COLUMN organizations_agents.agent_id IS \'(DC2Type:uuid)\''); | ||
$this->addSql('ALTER TABLE organization ADD CONSTRAINT fk_organization_owner_id_agent FOREIGN KEY (owner_id) REFERENCES agent (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('ALTER TABLE organization ADD CONSTRAINT fk_organization_agent_id_agent FOREIGN KEY (created_by) REFERENCES agent (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('ALTER TABLE organizations_agents ADD CONSTRAINT fk_organizations_agents_organization_id_organization FOREIGN KEY (organization_id) REFERENCES organization (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('ALTER TABLE organizations_agents ADD CONSTRAINT fk_organizations_agents_agent_id_agent FOREIGN KEY (agent_id) REFERENCES agent (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql('CREATE SCHEMA public'); | ||
$this->addSql('ALTER TABLE organization DROP CONSTRAINT fk_organization_owner_id_agent'); | ||
$this->addSql('ALTER TABLE organization DROP CONSTRAINT fk_organization_agent_id_agent'); | ||
$this->addSql('ALTER TABLE organizations_agents DROP CONSTRAINT fk_organizations_agents_organization_id_organization'); | ||
$this->addSql('ALTER TABLE organizations_agents DROP CONSTRAINT fk_organizations_agents_agent_id_agent'); | ||
$this->addSql('DROP TABLE organization'); | ||
$this->addSql('DROP TABLE organizations_agents'); | ||
} | ||
} |
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,192 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\DataFixtures; | ||
|
||
use App\Entity\Organization; | ||
use Doctrine\Bundle\FixturesBundle\Fixture; | ||
use Doctrine\Common\DataFixtures\DependentFixtureInterface; | ||
use Doctrine\Persistence\ObjectManager; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
final class OrganizationFixtures extends Fixture implements DependentFixtureInterface | ||
{ | ||
public const string ORGANIZATION_ID_PREFIX = 'project'; | ||
public const string ORGANIZATION_ID_1 = 'f077aecd-4830-1b8c-c607-72090dc31f71'; | ||
public const string ORGANIZATION_ID_2 = 'a65aa657-c537-1f33-c06e-31c2e219136e'; | ||
public const string ORGANIZATION_ID_3 = 'd12ead05-ef32-157a-c59e-4a83147ed9ec'; | ||
public const string ORGANIZATION_ID_4 = 'd68da96e-a834-1bb1-cb3d-5ac2c2dbae7b'; | ||
public const string ORGANIZATION_ID_5 = 'd430ade5-7f3d-1817-cae0-7152674ade73'; | ||
public const string ORGANIZATION_ID_6 = '5d85a939-263f-19b5-c912-7825967271a4'; | ||
public const string ORGANIZATION_ID_7 = '26c2aaf2-bf38-11d9-c036-7d6b4e56c350'; | ||
public const string ORGANIZATION_ID_8 = '7241a715-453a-12db-c707-725dc3ab988c'; | ||
public const string ORGANIZATION_ID_9 = '7cb6a1b8-f33e-1218-cb41-820b0f74e4d1'; | ||
public const string ORGANIZATION_ID_10 = '8c4ca8bd-6e33-1b62-c58b-a66969c49f66'; | ||
|
||
public const array ITEMS = [ | ||
[ | ||
'id' => self::ORGANIZATION_ID_1, | ||
'name' => 'PHP com Rapadura', | ||
'description' => 'Comunidade de devs PHP do Estado do Ceará', | ||
'createdBy' => AgentFixtures::AGENT_ID_1, | ||
'owner' => AgentFixtures::AGENT_ID_1, | ||
'agents' => [], | ||
'parent' => null, | ||
'space' => null, | ||
'createdAt' => '2024-07-10T11:30:00+00:00', | ||
'updatedAt' => null, | ||
'deletedAt' => null, | ||
], | ||
[ | ||
'id' => self::ORGANIZATION_ID_2, | ||
'name' => 'Grupo de Capoeira Axé Zumbi', | ||
'description' => 'Grupo de Capoeira Axé Zumbi', | ||
'createdBy' => AgentFixtures::AGENT_ID_1, | ||
'owner' => AgentFixtures::AGENT_ID_1, | ||
'agents' => [ | ||
AgentFixtures::AGENT_ID_1, | ||
AgentFixtures::AGENT_ID_2, | ||
], | ||
'parent' => null, | ||
'space' => null, | ||
'createdAt' => '2024-07-11T10:49:00+00:00', | ||
'updatedAt' => null, | ||
'deletedAt' => null, | ||
], | ||
[ | ||
'id' => self::ORGANIZATION_ID_3, | ||
'name' => 'Devs do Sertão', | ||
'description' => 'Grupo de devs que se reúnem velas veredas do sertão', | ||
'createdBy' => AgentFixtures::AGENT_ID_3, | ||
'owner' => AgentFixtures::AGENT_ID_3, | ||
'parent' => null, | ||
'space' => null, | ||
'createdAt' => '2024-07-16T17:22:00+00:00', | ||
'updatedAt' => null, | ||
'deletedAt' => null, | ||
], | ||
[ | ||
'id' => self::ORGANIZATION_ID_4, | ||
'name' => 'SertãoDev', | ||
'description' => 'Cooperativa de devs do Estado do Ceará', | ||
'createdBy' => AgentFixtures::AGENT_ID_1, | ||
'owner' => AgentFixtures::AGENT_ID_1, | ||
'parent' => null, | ||
'space' => null, | ||
'createdAt' => '2024-07-17T15:12:00+00:00', | ||
'updatedAt' => null, | ||
'deletedAt' => null, | ||
], | ||
[ | ||
'id' => self::ORGANIZATION_ID_5, | ||
'name' => 'De RapEnte', | ||
'description' => 'Grupo de Rap e Repente da caatinga nordestina', | ||
'createdBy' => AgentFixtures::AGENT_ID_3, | ||
'owner' => AgentFixtures::AGENT_ID_3, | ||
'parent' => null, | ||
'space' => null, | ||
'createdAt' => '2024-07-22T16:20:00+00:00', | ||
'updatedAt' => null, | ||
'deletedAt' => null, | ||
], | ||
[ | ||
'id' => self::ORGANIZATION_ID_6, | ||
'name' => 'Comunidade Vida com Cristo', | ||
'description' => 'Grupo de oração destinado a cristãos de boa fé', | ||
'createdBy' => AgentFixtures::AGENT_ID_2, | ||
'owner' => AgentFixtures::AGENT_ID_2, | ||
'parent' => null, | ||
'space' => null, | ||
'createdAt' => '2024-08-10T11:26:00+00:00', | ||
'updatedAt' => null, | ||
'deletedAt' => null, | ||
], | ||
[ | ||
'id' => self::ORGANIZATION_ID_7, | ||
'name' => 'Candomblé Raizes do Brasil ', | ||
'description' => 'Grupo de praticantes do candomblé - Natal-RN', | ||
'createdBy' => AgentFixtures::AGENT_ID_1, | ||
'owner' => AgentFixtures::AGENT_ID_1, | ||
'parent' => null, | ||
'space' => null, | ||
'createdAt' => '2024-08-11T15:54:00+00:00', | ||
'updatedAt' => null, | ||
'deletedAt' => null, | ||
], | ||
[ | ||
'id' => self::ORGANIZATION_ID_8, | ||
'name' => 'Baião de Dev', | ||
'description' => 'Grupo de desenvolvedores do nordeste', | ||
'createdBy' => AgentFixtures::AGENT_ID_1, | ||
'owner' => AgentFixtures::AGENT_ID_1, | ||
'parent' => null, | ||
'space' => null, | ||
'createdAt' => '2024-08-12T14:24:00+00:00', | ||
'updatedAt' => null, | ||
'deletedAt' => null, | ||
], | ||
[ | ||
'id' => self::ORGANIZATION_ID_9, | ||
'name' => 'PHPeste', | ||
'description' => 'Organização da Conferencia de PHP do Nordeste', | ||
'createdBy' => AgentFixtures::AGENT_ID_1, | ||
'owner' => AgentFixtures::AGENT_ID_1, | ||
'parent' => self::ORGANIZATION_ID_8, | ||
'space' => null, | ||
'createdAt' => '2024-08-13T20:25:00+00:00', | ||
'updatedAt' => null, | ||
'deletedAt' => null, | ||
], | ||
[ | ||
'id' => self::ORGANIZATION_ID_10, | ||
'name' => 'Banda de Forró tô nem veno', | ||
'description' => 'Banda de forró formada com pessoas de baixa ou nenhuma visão', | ||
'createdBy' => AgentFixtures::AGENT_ID_1, | ||
'owner' => AgentFixtures::AGENT_ID_1, | ||
'parent' => self::ORGANIZATION_ID_9, | ||
'space' => null, | ||
'createdAt' => '2024-08-14T10:00:00+00:00', | ||
'updatedAt' => null, | ||
'deletedAt' => null, | ||
], | ||
]; | ||
|
||
public function __construct( | ||
private readonly SerializerInterface $serializer, | ||
) { | ||
} | ||
|
||
public function getDependencies(): array | ||
{ | ||
return [ | ||
AgentFixtures::class, | ||
]; | ||
} | ||
|
||
public function load(ObjectManager $manager): void | ||
{ | ||
foreach (self::ITEMS as $objectData) { | ||
$agents = $objectData['agents'] ?? []; | ||
unset($objectData['agents']); | ||
|
||
/* @var Organization $object */ | ||
$object = $this->serializer->denormalize($objectData, Organization::class); | ||
|
||
foreach ($agents ?? [] as $agentId) { | ||
$object->addAgent( | ||
$this->getReference(sprintf('%s-%s', AgentFixtures::AGENT_ID_PREFIX, $agentId)) | ||
); | ||
} | ||
|
||
$object->setCreatedBy($this->getReference(sprintf('%s-%s', AgentFixtures::AGENT_ID_PREFIX, $objectData['createdBy']))); | ||
$object->setOwner($this->getReference(sprintf('%s-%s', AgentFixtures::AGENT_ID_PREFIX, $objectData['owner']))); | ||
|
||
$this->setReference(sprintf('%s-%s', self::ORGANIZATION_ID_PREFIX, $objectData['id']), $object); | ||
|
||
$manager->persist($object); | ||
} | ||
|
||
$manager->flush(); | ||
} | ||
} |
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
Oops, something went wrong.