migrations/Common/Version20220825104121_Observation.php line 1

  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations\Common;
  4. use App\Doctrine\Type\Common\ObservationStatus;
  5. use App\Doctrine\Type\Common\ObservationType;
  6. use Doctrine\DBAL\Schema\Schema;
  7. use Doctrine\Migrations\AbstractMigration;
  8. /**
  9.  * Auto-generated Migration: Please modify to your needs!
  10.  */
  11. final class Version20220825104121_Observation extends AbstractMigration
  12. {
  13.     public function getDescription(): string
  14.     {
  15.         return 'Add observation table';
  16.     }
  17.     public function up(Schema $schema): void
  18.     {
  19.         $this->addSql(ObservationType::getRegistrationSQL());
  20.         $this->addSql(ObservationStatus::getRegistrationSQL());
  21.         $observationTypeType ObservationType::getName();
  22.         $observationStatusType ObservationStatus::getName();
  23.         $this->addSql("CREATE TABLE observation (
  24.             id                              SERIAL PRIMARY KEY,
  25.             work_order_id                   INTEGER                              REFERENCES public.work_order (id),
  26.             bill_id                         INTEGER                              REFERENCES public.finance_bill (id),
  27.             withdrawal_id                   INTEGER,
  28.             type                            {$observationTypeType}      NOT NULL,
  29.             status                          {$observationStatusType}    NOT NULL,
  30.             comment                         CHARACTER VARYING           NOT NULL,
  31.             resolved_on                     DATE,
  32.             created_by                      INTEGER                     NOT NULL REFERENCES public.user (id),
  33.             updated_by                      INTEGER                              REFERENCES public.user (id),
  34.             created_at                      TIMESTAMP(0) WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
  35.             updated_at                      TIMESTAMP(0) WITH TIME ZONE,
  36.             deleted_at                      TIMESTAMP(0) WITH TIME ZONE,
  37.             CONSTRAINT observation_xor_observable CHECK (
  38.                 (work_order_id IS NOT NULL AND bill_id IS     NULL AND withdrawal_id IS     NULL) OR
  39.                 (work_order_id IS     NULL AND bill_id IS NOT NULL AND withdrawal_id IS     NULL) OR
  40.                 (work_order_id IS     NULL AND bill_id IS     NULL AND withdrawal_id IS NOT NULL)
  41.             )
  42.         )");
  43.         $this->addSql("CREATE INDEX observation_work_order_id_idx ON observation (work_order_id)");
  44.         $this->addSql("CREATE INDEX observation_created_by_idx ON observation (created_by)");
  45.         $this->addSql("CREATE INDEX observation_updated_by_idx ON observation (updated_by)");
  46.     }
  47.     public function down(Schema $schema): void
  48.     {
  49.         $this->addSql("DROP TABLE IF EXISTS observation");
  50.         $this->addSql(ObservationStatus::getDeletionSQL());
  51.         $this->addSql(ObservationType::getDeletionSQL());
  52.     }
  53. }