migrations/Version20190828053435.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 Version20190828053435 extends AbstractMigration
  10. {
  11.     public function getDescription() : string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema) : void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql''Migration can only be executed safely on \'mysql\'.');
  19.         $this->addSql('CREATE TABLE stock_item (product_id INT NOT NULL, unit_of_measurement_id INT DEFAULT NULL, current_stock INT NOT NULL, minimum_stock_level INT DEFAULT NULL, stop_selling_stock_level INT DEFAULT NULL, perishable TINYINT(1) NOT NULL, INDEX IDX_6017DDADA7C9F35 (unit_of_measurement_id), PRIMARY KEY(product_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
  20.         $this->addSql('ALTER TABLE stock_item ADD CONSTRAINT FK_6017DDA4584665A FOREIGN KEY (product_id) REFERENCES product (id)');
  21.         $this->addSql('ALTER TABLE stock_item ADD CONSTRAINT FK_6017DDADA7C9F35 FOREIGN KEY (unit_of_measurement_id) REFERENCES unitsOfMeasurement (id)');
  22.         $this->addSql('CREATE TABLE stock_movement (id INT AUTO_INCREMENT NOT NULL, stock_item_id INT DEFAULT NULL, created_by_id INT DEFAULT NULL, updated_by_id INT DEFAULT NULL, quantity INT NOT NULL, comment LONGTEXT DEFAULT NULL, balance INT NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX IDX_BB1BC1B5BC942FD (stock_item_id), INDEX IDX_BB1BC1B5B03A8386 (created_by_id), INDEX IDX_BB1BC1B5896DBBDE (updated_by_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
  23.         $this->addSql('ALTER TABLE stock_movement ADD CONSTRAINT FK_BB1BC1B5BC942FD FOREIGN KEY (stock_item_id) REFERENCES stock_item (product_id)');
  24.         $this->addSql('ALTER TABLE stock_movement ADD CONSTRAINT FK_BB1BC1B5B03A8386 FOREIGN KEY (created_by_id) REFERENCES users (id)');
  25.         $this->addSql('ALTER TABLE stock_movement ADD CONSTRAINT FK_BB1BC1B5896DBBDE FOREIGN KEY (updated_by_id) REFERENCES users (id)');
  26.         $this->addSql('INSERT INTO stock_item(product_id, unit_of_measurement_id, current_stock, minimum_stock_level, stop_selling_stock_level, perishable) SELECT id, 2, 0, 0, 10, false FROM product WHERE isDeleted=0');
  27.     }
  28.     public function down(Schema $schema) : void
  29.     {
  30.         // this down() migration is auto-generated, please modify it to your needs
  31.         $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql''Migration can only be executed safely on \'mysql\'.');
  32.         $this->addSql('DROP TABLE stock_movement');
  33.         $this->addSql('DROP TABLE stock_item');
  34.     }
  35. }