migrations/Inventory/Version20220901145204_InventoryWithdrawal.php line 1

  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations\Inventory;
  4. use App\Doctrine\Type\Inventory\WithdrawalStatus;
  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 Version20220901145204_InventoryWithdrawal extends AbstractMigration
  11. {
  12.     public function getDescription(): string
  13.     {
  14.         return 'Add inventory withdrawal table';
  15.     }
  16.     public function up(Schema $schema): void
  17.     {
  18.         $statusType WithdrawalStatus::getName();
  19.         $defaultStatus WithdrawalStatus::REQUESTED->value;
  20.         $this->addSql("CREATE TABLE inventory_withdrawal (
  21.             id                              SERIAL PRIMARY KEY,
  22.             identifier                      UUID                        NOT NULL,
  23.             slug                            CHARACTER VARYING           NOT NULL,
  24.             reference                       CHARACTER VARYING           NOT NULL,
  25.             warehouse_id                    INTEGER                     NOT NULL REFERENCES public.place (id),
  26.             beneficiary_id                  INTEGER                     NOT NULL REFERENCES public.user (id),
  27.             status                          {$statusType}               NOT NULL DEFAULT '{$defaultStatus}',
  28.             created_by                      INTEGER                     NOT NULL REFERENCES public.user (id),
  29.             updated_by                      INTEGER                              REFERENCES public.user (id),
  30.             created_at                      TIMESTAMP(0) WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
  31.             updated_at                      TIMESTAMP(0) WITH TIME ZONE,
  32.             deleted_at                      TIMESTAMP(0) WITH TIME ZONE,
  33.             CONSTRAINT inventory_withdrawal_slug_key UNIQUE (slug),
  34.             CONSTRAINT inventory_withdrawal_reference_key UNIQUE (reference),
  35.             CONSTRAINT inventory_withdrawal_identifier_key UNIQUE (identifier)
  36.         )");
  37.         $this->addSql("COMMENT ON COLUMN inventory_withdrawal.identifier IS '(DC2Type:ulid)'");
  38.         $this->addSql("CREATE INDEX inventory_withdrawal_warehouse_id_idx ON inventory_withdrawal (warehouse_id)");
  39.         $this->addSql("CREATE INDEX inventory_withdrawal_beneficiary_id_idx ON inventory_withdrawal (beneficiary_id)");
  40.         $this->addSql("CREATE INDEX inventory_withdrawal_created_by_idx ON inventory_withdrawal (created_by)");
  41.         $this->addSql("CREATE INDEX inventory_withdrawal_updated_by_idx ON inventory_withdrawal (updated_by)");
  42.     }
  43.     public function down(Schema $schema): void
  44.     {
  45.         $this->addSql("DROP TABLE IF EXISTS inventory_withdrawal");
  46.     }
  47. }