migrations/Common/Version20220825104121_Observation.php line 1
<?php
declare(strict_types=1);
namespace DoctrineMigrations\Common;
use App\Doctrine\Type\Common\ObservationStatus;
use App\Doctrine\Type\Common\ObservationType;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220825104121_Observation extends AbstractMigration
{
public function getDescription(): string
{
return 'Add observation table';
}
public function up(Schema $schema): void
{
$this->addSql(ObservationType::getRegistrationSQL());
$this->addSql(ObservationStatus::getRegistrationSQL());
$observationTypeType = ObservationType::getName();
$observationStatusType = ObservationStatus::getName();
$this->addSql("CREATE TABLE observation (
id SERIAL PRIMARY KEY,
work_order_id INTEGER REFERENCES public.work_order (id),
bill_id INTEGER REFERENCES public.finance_bill (id),
withdrawal_id INTEGER,
type {$observationTypeType} NOT NULL,
status {$observationStatusType} NOT NULL,
comment CHARACTER VARYING NOT NULL,
resolved_on DATE,
created_by INTEGER NOT NULL REFERENCES public.user (id),
updated_by INTEGER REFERENCES public.user (id),
created_at TIMESTAMP(0) WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP(0) WITH TIME ZONE,
deleted_at TIMESTAMP(0) WITH TIME ZONE,
CONSTRAINT observation_xor_observable CHECK (
(work_order_id IS NOT NULL AND bill_id IS NULL AND withdrawal_id IS NULL) OR
(work_order_id IS NULL AND bill_id IS NOT NULL AND withdrawal_id IS NULL) OR
(work_order_id IS NULL AND bill_id IS NULL AND withdrawal_id IS NOT NULL)
)
)");
$this->addSql("CREATE INDEX observation_work_order_id_idx ON observation (work_order_id)");
$this->addSql("CREATE INDEX observation_created_by_idx ON observation (created_by)");
$this->addSql("CREATE INDEX observation_updated_by_idx ON observation (updated_by)");
}
public function down(Schema $schema): void
{
$this->addSql("DROP TABLE IF EXISTS observation");
$this->addSql(ObservationStatus::getDeletionSQL());
$this->addSql(ObservationType::getDeletionSQL());
}
}