migrations/Version20220116163202.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20220116163202 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         $this->addSql('
  18.       CREATE OR REPLACE FUNCTION public.fn_intervention_request__available_for__user(integer)
  19. RETURNS SETOF integer
  20. LANGUAGE \'sql\'
  21. COST 100
  22. STABLE PARALLEL UNSAFE
  23. AS $BODY$
  24. SELECT DISTINCT (intervention_request_id) FROM intervention_requests.accesses
  25. WHERE
  26.  (
  27.     (authorized_company_id IS NULL
  28.      AND authorized_group_id IS NULL
  29.      AND authorized_user_id = $1
  30.     )
  31.     OR
  32.     (authorized_company_id = (SELECT u.company_id FROM users u WHERE u.id=$1)
  33.      AND authorized_group_id IS NULL
  34.      AND authorized_user_id IS NULL
  35.     )
  36.     OR
  37.     (authorized_company_id IS NULL
  38.      AND authorized_group_id IN (SELECT g.id
  39.                                  FROM users__groups gu
  40.                                  LEFT JOIN groups g ON gu.group_id=g.id
  41.                                  WHERE gu.user_id=$1
  42.                                  AND g.enabled=1 AND g.deleted=0
  43.                                 )
  44.      AND authorized_user_id IS NULL
  45.     )
  46. )
  47. $BODY$;
  48.       ');
  49.     }
  50.     public function down(Schema $schema): void
  51.     {
  52.         // this down() migration is auto-generated, please modify it to your needs
  53.     }
  54. }