migrations/Version20211219194514.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 Version20211219194514 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 TABLE intervention_requests.ratings (
  19.             id SERIAL,
  20.             message TEXT,
  21.             global_rate SMALLINT DEFAULT 0,
  22.             company_id INT DEFAULT NULL,
  23.             intervention_request_id INT DEFAULT NULL,
  24.             type SMALLINT DEFAULT 0,
  25.             created_at timestamp(0) without time zone DEFAULT NOW()::timestamp without time zone,
  26.             updated_at timestamp(0) without time zone DEFAULT NULL::timestamp without time zone,
  27.             deleted_at timestamp(0) without time zone DEFAULT NULL::timestamp without time zone,
  28.             created_by integer,
  29.             updated_by integer,
  30.             deleted_by integer,
  31.             enabled smallint DEFAULT 1 NOT NULL,
  32.             deleted smallint DEFAULT 0 NOT NULL,
  33.             PRIMARY KEY(id)
  34.         )
  35.        ");
  36.         $this->addSql("
  37.         ALTER TABLE ONLY intervention_requests.ratings
  38.             ADD CONSTRAINT fk_ratings__intervention_request_id
  39.             FOREIGN KEY (intervention_request_id)
  40.             REFERENCES public.intervention_requests(id)
  41.             ON UPDATE CASCADE ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED;
  42.         ");
  43.         $this->addSql("
  44.         ALTER TABLE ONLY intervention_requests.ratings
  45.             ADD CONSTRAINT fk_ratings__company_id
  46.             FOREIGN KEY (company_id)
  47.             REFERENCES public.companies(id)
  48.             ON UPDATE CASCADE ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED;
  49.         ");
  50.         $this->addSql("
  51.         CREATE TRIGGER tgr_ratings__main_table_history
  52.             BEFORE INSERT OR UPDATE
  53.             ON intervention_requests.ratings
  54.             FOR EACH ROW EXECUTE PROCEDURE main_table_history();
  55.         
  56.         ");
  57.     }
  58.     public function down(Schema $schema): void
  59.     {
  60.         $this->addSql("DROP TABLE intervention_requests.ratings");
  61.     }
  62. }