migrations/Fleet/Version20200309171219_FleetVehicle.php line 1

  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations\Fleet;
  4. use App\Doctrine\Type\Fleet\OperatingStatus;
  5. use Doctrine\DBAL\Schema\Schema;
  6. use Doctrine\Migrations\AbstractMigration;
  7. /**
  8.  * Auto-generated Migration: Please modify to your needs!
  9.  */
  10. final class Version20200309171219_FleetVehicle extends AbstractMigration
  11. {
  12.     public function getDescription(): string
  13.     {
  14.         return 'Add vehicle table';
  15.     }
  16.     public function up(Schema $schema): void
  17.     {
  18.         $operatingStatusType OperatingStatus::getName();
  19.         $defaultStatus OperatingStatus::OPERATIONAL->value;
  20.         $this->addSql("CREATE TABLE fleet_vehicle (
  21.             id                              SERIAL PRIMARY KEY,
  22.             identifier                      UUID                        NOT NULL,
  23.             owner_id                        INTEGER                              REFERENCES public.company (id),
  24.             make                            CHARACTER VARYING,
  25.             model                           CHARACTER VARYING,
  26.             front_number                    CHARACTER VARYING           NOT NULL,
  27.             rear_number                     CHARACTER VARYING           NOT NULL,
  28.             registered_on                   DATE,
  29.             country_of_operation            CHARACTER VARYING           NOT NULL,
  30.             status                          {$operatingStatusType}      NOT NULL DEFAULT '{$defaultStatus}',
  31.             created_by                      INTEGER                     NOT NULL REFERENCES public.user (id),
  32.             updated_by                      INTEGER                              REFERENCES public.user (id),
  33.             created_at                      TIMESTAMP(0) WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
  34.             updated_at                      TIMESTAMP(0) WITH TIME ZONE,
  35.             deleted_at                      TIMESTAMP(0) WITH TIME ZONE,
  36.             CONSTRAINT fleet_vehicle_identifier_key UNIQUE (identifier)
  37.         )");
  38.         $this->addSql("COMMENT ON COLUMN fleet_vehicle.identifier IS '(DC2Type:ulid)'");
  39.         $this->addSql("CREATE INDEX fleet_vehicle_owner_id_idx ON fleet_vehicle (owner_id)");
  40.         $this->addSql("CREATE INDEX fleet_vehicle_created_by_idx ON fleet_vehicle (created_by)");
  41.         $this->addSql("CREATE INDEX fleet_vehicle_updated_by_idx ON fleet_vehicle (updated_by)");
  42.     }
  43.     public function down(Schema $schema): void
  44.     {
  45.         $this->addSql("DROP TABLE IF EXISTS fleet_vehicle");
  46.     }
  47. }