<?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 Version20231201105158 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->addSql('CREATE TABLE contractors__contractors (id INT AUTO_INCREMENT NOT NULL, created_at DATETIME NOT NULL, type VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, inn VARCHAR(255) DEFAULT NULL, kpp VARCHAR(255) DEFAULT NULL, INDEX IDX_ED2B1BB8E93323CB (inn), INDEX IDX_ED2B1BB88CDE5729 (type), UNIQUE INDEX UNIQ_ED2B1BB8E93323CBC4F9F519 (inn, kpp), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE invoices__invoices (id INT AUTO_INCREMENT NOT NULL, contractor_id INT NOT NULL, created_at DATETIME NOT NULL, confirmed_date DATETIME DEFAULT NULL, canceled_date DATETIME DEFAULT NULL, INDEX IDX_7C29A666B0265DC7 (contractor_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE invoices__invoices_products (id INT AUTO_INCREMENT NOT NULL, invoice_id INT NOT NULL, warehouse_id INT NOT NULL, product_id INT NOT NULL, created_at DATETIME NOT NULL, quantity INT NOT NULL, amount INT NOT NULL, INDEX IDX_F8E4B8EA2989F1FD (invoice_id), INDEX IDX_F8E4B8EA5080ECDE (warehouse_id), INDEX IDX_F8E4B8EA4584665A (product_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE products__items_transactions (id INT AUTO_INCREMENT NOT NULL, item_id INT NOT NULL, invoice_product_id INT DEFAULT NULL, created_at DATETIME NOT NULL, init_stock INT NOT NULL, amount INT NOT NULL, new_stock INT NOT NULL, reason VARCHAR(255) NOT NULL, INDEX IDX_D9EFCC63126F525E (item_id), INDEX IDX_D9EFCC63BC5816C4 (invoice_product_id), UNIQUE INDEX UNIQ_D9EFCC63BC5816C43BB8880C (invoice_product_id, reason), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE warehouses__warehouses (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, alias VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_9B46CE6DE16C6B94 (alias), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE invoices__invoices ADD CONSTRAINT FK_7C29A666B0265DC7 FOREIGN KEY (contractor_id) REFERENCES contractors__contractors (id)');
$this->addSql('ALTER TABLE invoices__invoices_products ADD CONSTRAINT FK_F8E4B8EA2989F1FD FOREIGN KEY (invoice_id) REFERENCES invoices__invoices (id)');
$this->addSql('ALTER TABLE invoices__invoices_products ADD CONSTRAINT FK_F8E4B8EA5080ECDE FOREIGN KEY (warehouse_id) REFERENCES warehouses__warehouses (id)');
$this->addSql('ALTER TABLE invoices__invoices_products ADD CONSTRAINT FK_F8E4B8EA4584665A FOREIGN KEY (product_id) REFERENCES products__products (id)');
$this->addSql('ALTER TABLE products__items_transactions ADD CONSTRAINT FK_D9EFCC63126F525E FOREIGN KEY (item_id) REFERENCES products__items (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE products__items_transactions ADD CONSTRAINT FK_D9EFCC63BC5816C4 FOREIGN KEY (invoice_product_id) REFERENCES invoices__invoices_products (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE products__items ADD warehouse_id INT NOT NULL, CHANGE stock stock INT DEFAULT 0 NOT NULL, CHANGE price price INT DEFAULT 0 NOT NULL');
$this->addSql('ALTER TABLE products__items ADD CONSTRAINT FK_ED158EFB5080ECDE FOREIGN KEY (warehouse_id) REFERENCES warehouses__warehouses (id) ON DELETE CASCADE');
$this->addSql('CREATE INDEX IDX_ED158EFB5080ECDE ON products__items (warehouse_id)');
$this->addSql('ALTER TABLE users__users ADD cookie VARCHAR(255) NOT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE invoices__invoices DROP FOREIGN KEY FK_7C29A666B0265DC7');
$this->addSql('ALTER TABLE invoices__invoices_products DROP FOREIGN KEY FK_F8E4B8EA2989F1FD');
$this->addSql('ALTER TABLE products__items_transactions DROP FOREIGN KEY FK_D9EFCC63BC5816C4');
$this->addSql('ALTER TABLE invoices__invoices_products DROP FOREIGN KEY FK_F8E4B8EA5080ECDE');
$this->addSql('ALTER TABLE products__items DROP FOREIGN KEY FK_ED158EFB5080ECDE');
$this->addSql('DROP TABLE contractors__contractors');
$this->addSql('DROP TABLE invoices__invoices');
$this->addSql('DROP TABLE invoices__invoices_products');
$this->addSql('DROP TABLE products__items_transactions');
$this->addSql('DROP TABLE warehouses__warehouses');
$this->addSql('DROP INDEX IDX_ED158EFB5080ECDE ON products__items');
$this->addSql('ALTER TABLE products__items DROP warehouse_id, CHANGE stock stock INT NOT NULL, CHANGE price price INT NOT NULL');
$this->addSql('ALTER TABLE users__users DROP cookie');
}
}