Add base entities: Release, Artist

This commit is contained in:
dece 2023-10-01 12:46:02 +02:00
parent 8ef2bbaa72
commit 8364d1cd96
6 changed files with 251 additions and 3 deletions

View file

@ -0,0 +1,62 @@
<?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 Version20231001104548 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 artist_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE SEQUENCE release_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE TABLE artist (id INT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE TABLE release (id INT NOT NULL, title VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE TABLE release_artist (release_id INT NOT NULL, artist_id INT NOT NULL, PRIMARY KEY(release_id, artist_id))');
$this->addSql('CREATE INDEX IDX_CFBBEC6AB12A727D ON release_artist (release_id)');
$this->addSql('CREATE INDEX IDX_CFBBEC6AB7970CF8 ON release_artist (artist_id)');
$this->addSql('CREATE TABLE messenger_messages (id BIGSERIAL NOT NULL, body TEXT NOT NULL, headers TEXT NOT NULL, queue_name VARCHAR(190) NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, available_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, delivered_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_75EA56E0FB7336F0 ON messenger_messages (queue_name)');
$this->addSql('CREATE INDEX IDX_75EA56E0E3BD61CE ON messenger_messages (available_at)');
$this->addSql('CREATE INDEX IDX_75EA56E016BA31DB ON messenger_messages (delivered_at)');
$this->addSql('COMMENT ON COLUMN messenger_messages.created_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN messenger_messages.available_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN messenger_messages.delivered_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('CREATE OR REPLACE FUNCTION notify_messenger_messages() RETURNS TRIGGER AS $$
BEGIN
PERFORM pg_notify(\'messenger_messages\', NEW.queue_name::text);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;');
$this->addSql('DROP TRIGGER IF EXISTS notify_trigger ON messenger_messages;');
$this->addSql('CREATE TRIGGER notify_trigger AFTER INSERT OR UPDATE ON messenger_messages FOR EACH ROW EXECUTE PROCEDURE notify_messenger_messages();');
$this->addSql('ALTER TABLE release_artist ADD CONSTRAINT FK_CFBBEC6AB12A727D FOREIGN KEY (release_id) REFERENCES release (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE release_artist ADD CONSTRAINT FK_CFBBEC6AB7970CF8 FOREIGN KEY (artist_id) REFERENCES artist (id) ON DELETE CASCADE 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 artist_id_seq CASCADE');
$this->addSql('DROP SEQUENCE release_id_seq CASCADE');
$this->addSql('ALTER TABLE release_artist DROP CONSTRAINT FK_CFBBEC6AB12A727D');
$this->addSql('ALTER TABLE release_artist DROP CONSTRAINT FK_CFBBEC6AB7970CF8');
$this->addSql('DROP TABLE artist');
$this->addSql('DROP TABLE release');
$this->addSql('DROP TABLE release_artist');
$this->addSql('DROP TABLE messenger_messages');
}
}

72
src/Entity/Artist.php Normal file
View file

@ -0,0 +1,72 @@
<?php
namespace App\Entity;
use App\Repository\ArtistRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ArtistRepository::class)]
class Artist
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\ManyToMany(targetEntity: Release::class, mappedBy: 'artists')]
private Collection $releases;
public function __construct()
{
$this->releases = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, Release>
*/
public function getReleases(): Collection
{
return $this->releases;
}
public function addRelease(Release $release): static
{
if (!$this->releases->contains($release)) {
$this->releases->add($release);
$release->addArtist($this);
}
return $this;
}
public function removeRelease(Release $release): static
{
if ($this->releases->removeElement($release)) {
$release->removeArtist($this);
}
return $this;
}
}

69
src/Entity/Release.php Normal file
View file

@ -0,0 +1,69 @@
<?php
namespace App\Entity;
use App\Repository\ReleaseRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ReleaseRepository::class)]
class Release
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $title = null;
#[ORM\ManyToMany(targetEntity: Artist::class, inversedBy: 'releases')]
private Collection $artists;
public function __construct()
{
$this->artists = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
/**
* @return Collection<int, Artist>
*/
public function getArtists(): Collection
{
return $this->artists;
}
public function addArtist(Artist $artist): static
{
if (!$this->artists->contains($artist)) {
$this->artists->add($artist);
}
return $this;
}
public function removeArtist(Artist $artist): static
{
$this->artists->removeElement($artist);
return $this;
}
}

View file

@ -0,0 +1,23 @@
<?php
namespace App\Repository;
use App\Entity\Artist;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Artist>
*
* @method Artist|null find($id, $lockMode = null, $lockVersion = null)
* @method Artist|null findOneBy(array $criteria, array $orderBy = null)
* @method Artist[] findAll()
* @method Artist[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class ArtistRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Artist::class);
}
}

View file

@ -0,0 +1,23 @@
<?php
namespace App\Repository;
use App\Entity\Release;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Release>
*
* @method Release|null find($id, $lockMode = null, $lockVersion = null)
* @method Release|null findOneBy(array $criteria, array $orderBy = null)
* @method Release[] findAll()
* @method Release[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class ReleaseRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Release::class);
}
}

View file

@ -2,11 +2,10 @@
<html>
<head>
<meta charset="UTF-8">
<title>{% block title %}Welcome!{% endblock %}</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 128 128%22><text y=%221.2em%22 font-size=%2296%22>⚫️</text></svg>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}Flumzi{% endblock %}</title>
{% block stylesheets %}
{% endblock %}
{% block javascripts %}
{% endblock %}
</head>