<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20190828053435 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$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');
$this->addSql('ALTER TABLE stock_item ADD CONSTRAINT FK_6017DDA4584665A FOREIGN KEY (product_id) REFERENCES product (id)');
$this->addSql('ALTER TABLE stock_item ADD CONSTRAINT FK_6017DDADA7C9F35 FOREIGN KEY (unit_of_measurement_id) REFERENCES unitsOfMeasurement (id)');
$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');
$this->addSql('ALTER TABLE stock_movement ADD CONSTRAINT FK_BB1BC1B5BC942FD FOREIGN KEY (stock_item_id) REFERENCES stock_item (product_id)');
$this->addSql('ALTER TABLE stock_movement ADD CONSTRAINT FK_BB1BC1B5B03A8386 FOREIGN KEY (created_by_id) REFERENCES users (id)');
$this->addSql('ALTER TABLE stock_movement ADD CONSTRAINT FK_BB1BC1B5896DBBDE FOREIGN KEY (updated_by_id) REFERENCES users (id)');
$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');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('DROP TABLE stock_movement');
$this->addSql('DROP TABLE stock_item');
}
}