<?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 Version20220116163202 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
$this->addSql('
CREATE OR REPLACE FUNCTION public.fn_intervention_request__available_for__user(integer)
RETURNS SETOF integer
LANGUAGE \'sql\'
COST 100
STABLE PARALLEL UNSAFE
AS $BODY$
SELECT DISTINCT (intervention_request_id) FROM intervention_requests.accesses
WHERE
(
(authorized_company_id IS NULL
AND authorized_group_id IS NULL
AND authorized_user_id = $1
)
OR
(authorized_company_id = (SELECT u.company_id FROM users u WHERE u.id=$1)
AND authorized_group_id IS NULL
AND authorized_user_id IS NULL
)
OR
(authorized_company_id IS NULL
AND authorized_group_id IN (SELECT g.id
FROM users__groups gu
LEFT JOIN groups g ON gu.group_id=g.id
WHERE gu.user_id=$1
AND g.enabled=1 AND g.deleted=0
)
AND authorized_user_id IS NULL
)
)
$BODY$;
');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
}
}