Add ReleaseMetadata entity
Why ReleaseMetadata and not simply Metadata you ask? Because I want to be sure future entities may have their own type of metadata and not have name conflicts. Why not adding this data to Release? I don't know, I like small tables for the main entities I guess, probably #DoesNotScale.
This commit is contained in:
parent
3e86499e10
commit
0c17bbbc4c
37
migrations/Version20231001125432.php
Normal file
37
migrations/Version20231001125432.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20231001125432 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE SEQUENCE release_metadata_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
|
||||
$this->addSql('CREATE TABLE release_metadata (id INT NOT NULL, release_id INT NOT NULL, year INT DEFAULT NULL, PRIMARY KEY(id))');
|
||||
$this->addSql('CREATE UNIQUE INDEX UNIQ_1414EF75B12A727D ON release_metadata (release_id)');
|
||||
$this->addSql('ALTER TABLE release_metadata ADD CONSTRAINT FK_1414EF75B12A727D FOREIGN KEY (release_id) REFERENCES release (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
}
|
||||
|
||||
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('DROP SEQUENCE release_metadata_id_seq CASCADE');
|
||||
$this->addSql('ALTER TABLE release_metadata DROP CONSTRAINT FK_1414EF75B12A727D');
|
||||
$this->addSql('DROP TABLE release_metadata');
|
||||
}
|
||||
}
|
|
@ -25,6 +25,9 @@ class Release
|
|||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?User $owner = null;
|
||||
|
||||
#[ORM\OneToOne(mappedBy: 'release', cascade: ['persist', 'remove'])]
|
||||
private ?ReleaseMetadata $metadata = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->artists = new ArrayCollection();
|
||||
|
@ -82,4 +85,21 @@ class Release
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMetadata(): ?ReleaseMetadata
|
||||
{
|
||||
return $this->metadata;
|
||||
}
|
||||
|
||||
public function setMetadata(ReleaseMetadata $metadata): static
|
||||
{
|
||||
// set the owning side of the relation if necessary
|
||||
if ($metadata->getRelease() !== $this) {
|
||||
$metadata->setRelease($this);
|
||||
}
|
||||
|
||||
$this->metadata = $metadata;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
57
src/Entity/ReleaseMetadata.php
Normal file
57
src/Entity/ReleaseMetadata.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\ReleaseMetadataRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Metadata related to a release.
|
||||
*
|
||||
* Could be pulled from an external source (MusicBrainz, Discogs, …) or filled by hand. A release should be usable
|
||||
* without associated metadata, but these metadata should always have a 1-1 relation to an existing release.
|
||||
*/
|
||||
#[ORM\Entity(repositoryClass: ReleaseMetadataRepository::class)]
|
||||
class ReleaseMetadata
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\OneToOne(inversedBy: 'metadata', cascade: ['persist', 'remove'])]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?Release $release = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?int $year = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getRelease(): ?Release
|
||||
{
|
||||
return $this->release;
|
||||
}
|
||||
|
||||
public function setRelease(Release $release): static
|
||||
{
|
||||
$this->release = $release;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getYear(): ?int
|
||||
{
|
||||
return $this->year;
|
||||
}
|
||||
|
||||
public function setYear(?int $year): static
|
||||
{
|
||||
$this->year = $year;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
23
src/Repository/ReleaseMetadataRepository.php
Normal file
23
src/Repository/ReleaseMetadataRepository.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\ReleaseMetadata;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<ReleaseMetadata>
|
||||
*
|
||||
* @method ReleaseMetadata|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method ReleaseMetadata|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method ReleaseMetadata[] findAll()
|
||||
* @method ReleaseMetadata[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class ReleaseMetadataRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, ReleaseMetadata::class);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue