feat: update database relation

This commit is contained in:
Maël Gangloff 2024-07-11 22:20:20 +02:00
parent bad27c7b42
commit 6aad09297f
No known key found for this signature in database
GPG Key ID: 11FDC81C24A7F629
11 changed files with 146 additions and 83 deletions

View File

@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240711162405 extends AbstractMigration
final class Version20240711201708 extends AbstractMigration
{
public function getDescription(): string
{
@ -20,21 +20,27 @@ final class Version20240711162405 extends AbstractMigration
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE bookmark_domain_list (token VARCHAR(36) NOT NULL, user_id INTEGER NOT NULL, PRIMARY KEY(token), CONSTRAINT FK_F05EDCECA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE INDEX IDX_F05EDCECA76ED395 ON bookmark_domain_list (user_id)');
$this->addSql('CREATE TABLE bookmark_list (token VARCHAR(36) NOT NULL, user_id INTEGER NOT NULL, PRIMARY KEY(token), CONSTRAINT FK_A650C0C4A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE INDEX IDX_A650C0C4A76ED395 ON bookmark_list (user_id)');
$this->addSql('CREATE TABLE bookmark_lists_domains (bookmark_token VARCHAR(36) NOT NULL, domain_ldh_name VARCHAR(255) NOT NULL, domain_handle VARCHAR(255) NOT NULL, PRIMARY KEY(bookmark_token, domain_ldh_name, domain_handle), CONSTRAINT FK_C12B6400D0B0A7FC FOREIGN KEY (bookmark_token) REFERENCES bookmark_list (token) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_C12B6400AF923913FEE32C10 FOREIGN KEY (domain_ldh_name, domain_handle) REFERENCES domain (ldh_name, handle) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE INDEX IDX_C12B6400D0B0A7FC ON bookmark_lists_domains (bookmark_token)');
$this->addSql('CREATE INDEX IDX_C12B6400AF923913FEE32C10 ON bookmark_lists_domains (domain_ldh_name, domain_handle)');
$this->addSql('CREATE TABLE domain (ldh_name VARCHAR(255) NOT NULL, handle VARCHAR(255) NOT NULL, whois_status VARCHAR(255) NOT NULL, status CLOB NOT NULL --(DC2Type:simple_array)
, PRIMARY KEY(ldh_name, handle))');
$this->addSql('CREATE TABLE domain_nameservers (domain_handle VARCHAR(255) NOT NULL, domain_ldh_name VARCHAR(255) NOT NULL, nameserver_handle VARCHAR(255) NOT NULL, PRIMARY KEY(domain_handle, domain_ldh_name, nameserver_handle), CONSTRAINT FK_B6E6B63AFEE32C10AF923913 FOREIGN KEY (domain_handle, domain_ldh_name) REFERENCES domain (handle, ldh_name) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_B6E6B63A3DC1CB05 FOREIGN KEY (nameserver_handle) REFERENCES nameserver (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE INDEX IDX_B6E6B63AFEE32C10AF923913 ON domain_nameservers (domain_handle, domain_ldh_name)');
$this->addSql('CREATE INDEX IDX_B6E6B63A3DC1CB05 ON domain_nameservers (nameserver_handle)');
$this->addSql('CREATE TABLE domain_entity (domain_id VARCHAR(255) NOT NULL, entity_id VARCHAR(255) NOT NULL, roles CLOB NOT NULL --(DC2Type:simple_array)
, PRIMARY KEY(domain_id, entity_id), CONSTRAINT FK_614B48A1115F0EE5 FOREIGN KEY (domain_id) REFERENCES domain (handle) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_614B48A181257D5D FOREIGN KEY (entity_id) REFERENCES entity (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE INDEX IDX_614B48A1115F0EE5 ON domain_entity (domain_id)');
$this->addSql('CREATE INDEX IDX_614B48A181257D5D ON domain_entity (entity_id)');
$this->addSql('CREATE TABLE domain_event ("action" VARCHAR(255) NOT NULL, domain_id VARCHAR(255) NOT NULL, date DATE NOT NULL --(DC2Type:date_immutable)
, PRIMARY KEY("action", domain_id), CONSTRAINT FK_E8D52271115F0EE5 FOREIGN KEY (domain_id) REFERENCES domain (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE TABLE domain_event (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, domain_id VARCHAR(255) NOT NULL, "action" VARCHAR(255) NOT NULL, date DATETIME NOT NULL --(DC2Type:datetime_immutable)
, CONSTRAINT FK_E8D52271115F0EE5 FOREIGN KEY (domain_id) REFERENCES domain (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE INDEX IDX_E8D52271115F0EE5 ON domain_event (domain_id)');
$this->addSql('CREATE TABLE entity (handle VARCHAR(255) NOT NULL, PRIMARY KEY(handle))');
$this->addSql('CREATE TABLE event (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, entity_id VARCHAR(255) NOT NULL, "action" VARCHAR(255) NOT NULL, date DATETIME NOT NULL --(DC2Type:datetime_immutable)
, CONSTRAINT FK_3BAE0AA781257D5D FOREIGN KEY (entity_id) REFERENCES entity (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE INDEX IDX_3BAE0AA781257D5D ON event (entity_id)');
$this->addSql('CREATE TABLE entity_event (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, entity_id VARCHAR(255) NOT NULL, "action" VARCHAR(255) NOT NULL, date DATETIME NOT NULL --(DC2Type:datetime_immutable)
, CONSTRAINT FK_975A3F5E81257D5D FOREIGN KEY (entity_id) REFERENCES entity (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE INDEX IDX_975A3F5E81257D5D ON entity_event (entity_id)');
$this->addSql('CREATE TABLE nameserver (handle VARCHAR(255) NOT NULL, ldh_name VARCHAR(255) NOT NULL, status CLOB NOT NULL --(DC2Type:simple_array)
, PRIMARY KEY(handle))');
$this->addSql('CREATE TABLE nameserver_entity (nameserver_id VARCHAR(255) NOT NULL, entity_id VARCHAR(255) NOT NULL, roles CLOB NOT NULL --(DC2Type:simple_array)
@ -57,12 +63,14 @@ final class Version20240711162405 extends AbstractMigration
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE bookmark_domain_list');
$this->addSql('DROP TABLE bookmark_list');
$this->addSql('DROP TABLE bookmark_lists_domains');
$this->addSql('DROP TABLE domain');
$this->addSql('DROP TABLE domain_nameservers');
$this->addSql('DROP TABLE domain_entity');
$this->addSql('DROP TABLE domain_event');
$this->addSql('DROP TABLE entity');
$this->addSql('DROP TABLE event');
$this->addSql('DROP TABLE entity_event');
$this->addSql('DROP TABLE nameserver');
$this->addSql('DROP TABLE nameserver_entity');
$this->addSql('DROP TABLE user');

View File

View File

@ -2,14 +2,14 @@
namespace App\Entity;
use App\Repository\BookmarkDomainListRepository;
use App\Repository\BookmarkListRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity(repositoryClass: BookmarkDomainListRepository::class)]
class BookmarkDomainList
#[ORM\Entity(repositoryClass: BookmarkListRepository::class)]
class BookmarkList
{
#[ORM\Id]
#[ORM\Column(length: 36)]
@ -22,7 +22,10 @@ class BookmarkDomainList
/**
* @var Collection<int, Domain>
*/
#[ORM\ManyToMany(targetEntity: Domain::class, mappedBy: 'handle')]
#[ORM\ManyToMany(targetEntity: Domain::class, inversedBy: 'bookmarkLists')]
#[ORM\JoinTable(name: 'bookmark_lists_domains',
joinColumns: [new ORM\JoinColumn(name: 'bookmark_token', referencedColumnName: 'token')],
inverseJoinColumns: [new ORM\JoinColumn(name: 'domain_ldh_name', referencedColumnName: 'ldh_name'), new ORM\JoinColumn(name: 'domain_handle', referencedColumnName: 'handle')])]
private Collection $domains;
public function __construct()

View File

@ -38,16 +38,27 @@ class Domain
#[ORM\Column(type: Types::SIMPLE_ARRAY, enumType: DomainStatus::class)]
private array $status = [];
/**
* @var Collection<int, BookmarkList>
*/
#[ORM\ManyToMany(targetEntity: BookmarkList::class, mappedBy: 'domains')]
private Collection $bookmarkLists;
/**
* @var Collection<int, Nameserver>
*/
#[ORM\ManyToMany(targetEntity: Nameserver::class, mappedBy: 'handle')]
#[ORM\ManyToMany(targetEntity: Nameserver::class, inversedBy: 'domains')]
#[ORM\JoinTable(name: 'domain_nameservers',
joinColumns: [new ORM\JoinColumn(name: 'domain_handle', referencedColumnName: 'handle'), new ORM\JoinColumn(name: 'domain_ldh_name', referencedColumnName: 'ldh_name')],
inverseJoinColumns: [new ORM\JoinColumn(name: 'nameserver_handle', referencedColumnName: 'handle')]
)]
private Collection $nameservers;
public function __construct()
{
$this->events = new ArrayCollection();
$this->domainEntities = new ArrayCollection();
$this->bookmarkLists = new ArrayCollection();
$this->nameservers = new ArrayCollection();
}
@ -162,6 +173,33 @@ class Domain
return $this;
}
/**
* @return Collection<int, BookmarkList>
*/
public function getBookmarkLists(): Collection
{
return $this->bookmarkLists;
}
public function addBookmarkList(BookmarkList $bookmarkList): static
{
if (!$this->bookmarkLists->contains($bookmarkList)) {
$this->bookmarkLists->add($bookmarkList);
$bookmarkList->addDomain($this);
}
return $this;
}
public function removeBookmarkList(BookmarkList $bookmarkList): static
{
if ($this->bookmarkLists->removeElement($bookmarkList)) {
$bookmarkList->removeDomain($this);
}
return $this;
}
/**
* @return Collection<int, Nameserver>
*/

View File

@ -2,50 +2,16 @@
namespace App\Entity;
use App\Config\EventAction;
use App\Repository\DomainEventRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: DomainEventRepository::class)]
class DomainEvent
class DomainEvent extends Event
{
#[ORM\Id]
#[ORM\Column(enumType: EventAction::class)]
private ?EventAction $action = null;
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
private ?\DateTimeImmutable $date = null;
#[ORM\Id]
#[ORM\ManyToOne(targetEntity: Domain::class, inversedBy: 'events')]
#[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)]
private ?Domain $domain = null;
public function getAction(): ?EventAction
{
return $this->action;
}
public function setAction(EventAction $action): static
{
$this->action = $action;
return $this;
}
public function getDate(): ?\DateTimeImmutable
{
return $this->date;
}
public function setDate(\DateTimeImmutable $date): static
{
$this->date = $date;
return $this;
}
public function getDomain(): ?Domain
{
return $this->domain;

View File

@ -0,0 +1,29 @@
<?php
namespace App\Entity;
use App\Config\EventAction;
use App\Repository\EntityEventRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: EntityEventRepository::class)]
class EntityEvent extends Event
{
#[ORM\ManyToOne(targetEntity: Entity::class, inversedBy: 'events')]
#[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)]
private ?Entity $entity = null;
public function getEntity(): ?Entity
{
return $this->entity;
}
public function setEntity(?Entity $entity): static
{
$this->entity = $entity;
return $this;
}
}

View File

@ -3,10 +3,10 @@
namespace App\Entity;
use App\Config\EventAction;
use App\Repository\EventRepository;
use App\Repository\EntityEventRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: EventRepository::class)]
#[ORM\MappedSuperclass]
class Event
{
#[ORM\Id]
@ -20,10 +20,6 @@ class Event
#[ORM\Column]
private ?\DateTimeImmutable $date = null;
#[ORM\ManyToOne(targetEntity: Entity::class, inversedBy: 'events')]
#[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)]
private ?Entity $entity = null;
public function getId(): ?int
{
@ -54,16 +50,4 @@ class Event
return $this;
}
public function getEntity(): ?Entity
{
return $this->entity;
}
public function setEntity(?Entity $entity): static
{
$this->entity = $entity;
return $this;
}
}

View File

@ -28,9 +28,16 @@ class Nameserver
#[ORM\Column(type: Types::SIMPLE_ARRAY, enumType: DomainStatus::class)]
private array $status = [];
/**
* @var Collection<int, Domain>
*/
#[ORM\ManyToMany(targetEntity: Domain::class, mappedBy: 'nameservers')]
private Collection $domains;
public function __construct()
{
$this->nameserverEntities = new ArrayCollection();
$this->domains = new ArrayCollection();
}
public function getHandle(): ?string
@ -102,4 +109,31 @@ class Nameserver
return $this;
}
/**
* @return Collection<int, Domain>
*/
public function getDomains(): Collection
{
return $this->domains;
}
public function addDomain(Domain $domain): static
{
if (!$this->domains->contains($domain)) {
$this->domains->add($domain);
$domain->addNameserver($this);
}
return $this;
}
public function removeDomain(Domain $domain): static
{
if ($this->domains->removeElement($domain)) {
$domain->removeNameserver($this);
}
return $this;
}
}

View File

@ -34,9 +34,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
private ?string $password = null;
/**
* @var Collection<int, BookmarkDomainList>
* @var Collection<int, BookmarkList>
*/
#[ORM\OneToMany(targetEntity: BookmarkDomainList::class, mappedBy: 'user', orphanRemoval: true)]
#[ORM\OneToMany(targetEntity: BookmarkList::class, mappedBy: 'user', orphanRemoval: true)]
private Collection $bookmarkDomainLists;
public function __construct()
@ -121,14 +121,14 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
}
/**
* @return Collection<int, BookmarkDomainList>
* @return Collection<int, BookmarkList>
*/
public function getBookmarkDomainLists(): Collection
{
return $this->bookmarkDomainLists;
}
public function addBookmarkDomainList(BookmarkDomainList $bookmarkDomainList): static
public function addBookmarkDomainList(BookmarkList $bookmarkDomainList): static
{
if (!$this->bookmarkDomainLists->contains($bookmarkDomainList)) {
$this->bookmarkDomainLists->add($bookmarkDomainList);
@ -138,7 +138,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
return $this;
}
public function removeBookmarkDomainList(BookmarkDomainList $bookmarkDomainList): static
public function removeBookmarkDomainList(BookmarkList $bookmarkDomainList): static
{
if ($this->bookmarkDomainLists->removeElement($bookmarkDomainList)) {
// set the owning side to null (unless already changed)

View File

@ -2,22 +2,22 @@
namespace App\Repository;
use App\Entity\BookmarkDomainList;
use App\Entity\BookmarkList;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<BookmarkDomainList>
* @extends ServiceEntityRepository<BookmarkList>
*/
class BookmarkDomainListRepository extends ServiceEntityRepository
class BookmarkListRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, BookmarkDomainList::class);
parent::__construct($registry, BookmarkList::class);
}
// /**
// * @return BookmarkDomainList[] Returns an array of BookmarkDomainList objects
// * @return BookmarkList[] Returns an array of BookmarkList objects
// */
// public function findByExampleField($value): array
// {
@ -31,7 +31,7 @@ class BookmarkDomainListRepository extends ServiceEntityRepository
// ;
// }
// public function findOneBySomeField($value): ?BookmarkDomainList
// public function findOneBySomeField($value): ?BookmarkList
// {
// return $this->createQueryBuilder('b')
// ->andWhere('b.exampleField = :val')

View File

@ -2,22 +2,23 @@
namespace App\Repository;
use App\Entity\EntityEvent;
use App\Entity\Event;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Event>
* @extends ServiceEntityRepository<EntityEvent>
*/
class EventRepository extends ServiceEntityRepository
class EntityEventRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Event::class);
parent::__construct($registry, EntityEvent::class);
}
// /**
// * @return Event[] Returns an array of Event objects
// * @return EntityEvent[] Returns an array of EntityEvent objects
// */
// public function findByExampleField($value): array
// {