migrations/Inventory/Version20220901132630_InventoryMovement.php line 1

  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations\Inventory;
  4. use App\Doctrine\Type\Inventory\MovementType;
  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 Version20220901132630_InventoryMovement extends AbstractMigration
  11. {
  12.     public function getDescription(): string
  13.     {
  14.         return 'Add inventory movement table';
  15.     }
  16.     public function up(Schema $schema): void
  17.     {
  18.         $movementType MovementType::getName();
  19.         $this->addSql("CREATE TABLE inventory_package_movement (
  20.             id                              SERIAL PRIMARY KEY,
  21.             identifier                      UUID                        NOT NULL,
  22.             warehouse_id                    INTEGER                     NOT NULL REFERENCES public.place (id),
  23.             package_id                      INTEGER                     NOT NULL REFERENCES public.expediting_package (id),
  24.             shipping_segment_id             INTEGER                              REFERENCES public.expediting_shipping_segment (id),
  25.             repacking_id                    INTEGER                              REFERENCES public.expediting_repacking (id),
  26.             exit_id                         INTEGER                              REFERENCES public.inventory_package_movement (id),
  27.             type                            {$movementType}             NOT NULL,
  28.             completed_at                    TIMESTAMP(0) WITH TIME ZONE NOT NULL,
  29.             created_by                      INTEGER                     NOT NULL REFERENCES public.user (id),
  30.             updated_by                      INTEGER                              REFERENCES public.user (id),
  31.             created_at                      TIMESTAMP(0) WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
  32.             updated_at                      TIMESTAMP(0) WITH TIME ZONE,
  33.             deleted_at                      TIMESTAMP(0) WITH TIME ZONE,
  34.             CONSTRAINT inventory_package_movement_identifier_key UNIQUE (identifier),
  35.             CONSTRAINT inventory_package_movement_xor_movement CHECK (
  36.                 (shipping_segment_id IS NOT NULL AND repacking_id IS     NULL) OR
  37.                 (shipping_segment_id IS     NULL AND repacking_id IS NOT NULL)
  38.             )
  39.         )");
  40.         $this->addSql("COMMENT ON COLUMN inventory_package_movement.identifier IS '(DC2Type:ulid)'");
  41.         $this->addSql("CREATE INDEX inventory_package_movement_warehouse_id_idx ON inventory_package_movement (warehouse_id)");
  42.         $this->addSql("CREATE INDEX inventory_package_movement_package_id_idx ON inventory_package_movement (package_id)");
  43.         $this->addSql("CREATE INDEX inventory_package_movement_shipping_segment_id_idx ON inventory_package_movement (shipping_segment_id)");
  44.         $this->addSql("CREATE INDEX inventory_package_movement_repacking_id_idx ON inventory_package_movement (repacking_id)");
  45.         $this->addSql("CREATE INDEX inventory_package_movement_exit_id_idx ON inventory_package_movement (exit_id)");
  46.         $this->addSql("CREATE INDEX inventory_package_movement_created_by_idx ON inventory_package_movement (created_by)");
  47.         $this->addSql("CREATE INDEX inventory_package_movement_updated_by_idx ON inventory_package_movement (updated_by)");
  48.     }
  49.     public function down(Schema $schema): void
  50.     {
  51.         $this->addSql("DROP TABLE IF EXISTS inventory_package_movement");
  52.     }
  53. }