<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20230605154617 extends AbstractMigration
{
public function getDescription(): string
{
return 'Added default avatar to collaborators';
}
public function up(Schema $schema): void
{
// Insert avatar for agent with Morale person type
$this->addSql("INSERT INTO avatar (id, collaborator_id, file_path)
SELECT nextval('avatar_id_seq'), c.id, 'avatar-c.png'
FROM abstract_collaborator c
LEFT JOIN avatar a ON c.id = a.collaborator_id
WHERE a.collaborator_id IS NULL and c.person_type = 'Moral'");
// Insert avatar for female agents
$this->addSql("INSERT INTO avatar (id, collaborator_id, file_path)
SELECT nextval('avatar_id_seq'), c.id, 'avatar-f.png'
FROM abstract_collaborator c
LEFT JOIN avatar a ON c.id = a.collaborator_id
inner join gender g on g.id = c.gender_id
WHERE a.collaborator_id IS NULL and (c.person_type != 'Moral' or c.person_type is null )
and g.code = 'F'");
// Insert avatar for male agents
$this->addSql("INSERT INTO avatar (id, collaborator_id, file_path)
SELECT nextval('avatar_id_seq'), c.id, 'avatar-m.png'
FROM abstract_collaborator c
LEFT JOIN avatar a ON c.id = a.collaborator_id
inner join gender g on g.id = c.gender_id
WHERE a.collaborator_id IS NULL and (c.person_type != 'Moral' or c.person_type is null )
and g.code = 'M'");
}
}