migrations/Version20220120115405.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 Version20220120115405 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $this->addSql('
  19. CREATE OR REPLACE FUNCTION public.fn_contract__matcher_for__real_estate__and__business_area(
  20.     integer,
  21.     integer)
  22.     RETURNS integer
  23.     LANGUAGE \'sql\'
  24.     COST 100
  25.     STABLE PARALLEL UNSAFE
  26. AS $BODY$
  27. WITH RECURSIVE business_area__by__contract(id, parent, contract, level) AS (
  28.     SELECT b.id, b.parent_id, c.id, 1
  29.     FROM public.business_areas b
  30.     LEFT JOIN public.contracts__business_areas cb ON b.id = cb.business_area_id
  31.     LEFT JOIN public.contracts c ON c.id = cb.contract_id
  32.     LEFT JOIN public.contracts__real_estates cr ON c.id=cr.contract_id
  33.     WHERE b.enabled=1 AND b.deleted = 0 AND c.enabled = 1 AND c.deleted = 0
  34.     AND cr.real_estate_id=$1
  35. ), business_area__enfant(id, parent, contract, level) AS (
  36.     SELECT * FROM business_area__by__contract
  37.     UNION ALL
  38.     SELECT b.id, b.parent_id, rec.contract, level+1
  39.     FROM business_area__enfant rec, public.business_areas b
  40.     WHERE b.parent_id=rec.id AND b.enabled = 1 AND b.deleted = 0
  41. )
  42. SELECT contract 
  43. FROM business_area__enfant 
  44. WHERE id=$2 
  45. ORDER BY level ASC LIMIT 1 OFFSET 0
  46. $BODY$;
  47.         ');
  48.     }
  49.     public function down(Schema $schema): void
  50.     {
  51.         // this down() migration is auto-generated, please modify it to your needs
  52.     }
  53. }