<?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 Version20190713162526 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('ALTER TABLE facturation DROP FOREIGN KEY FK_17EB513AD3564642');
$this->addSql('ALTER TABLE facturation DROP FOREIGN KEY FK_17EB513AE8DE7170');
$this->addSql('DROP INDEX IDX_17EB513AD3564642 ON facturation');
$this->addSql('DROP INDEX IDX_17EB513AE8DE7170 ON facturation');
$this->addSql('ALTER TABLE facturation CHANGE createdAt created_at DATETIME NOT NULL');
$this->addSql('ALTER TABLE facturation CHANGE updatedAt updated_at DATETIME NOT NULL');
$this->addSql('ALTER TABLE facturation CHANGE createdBy created_by_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE facturation CHANGE updatedBy updated_by_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE facturation CHANGE receiptNumber invoice_number INT DEFAULT NULL');
$this->addSql('ALTER TABLE facturation ADD invoice_type CHAR(2)');
// now set the invoice type properly on the invoice table
$this->addSql('UPDATE facturation
LEFT JOIN orders ON orders.id=facturation.order_id
LEFT JOIN facturation_address ON facturation_address.id=orders.facturation_address_id
LEFT JOIN iva_condition ON iva_condition.id=facturation_address.idIvaCondition
SET facturation.invoice_type=iva_condition.receiptName');
// add indexes back
$this->addSql('ALTER TABLE facturation ADD CONSTRAINT FK_17EB513AB03A8386 FOREIGN KEY (created_by_id) REFERENCES users (id)');
$this->addSql('ALTER TABLE facturation ADD CONSTRAINT FK_17EB513A896DBBDE FOREIGN KEY (updated_by_id) REFERENCES users (id)');
$this->addSql('CREATE INDEX IDX_17EB513AB03A8386 ON facturation (created_by_id)');
$this->addSql('CREATE INDEX IDX_17EB513A896DBBDE ON facturation (updated_by_id)');
// add a search index for invoice type..
$this->addSql('CREATE INDEX invoiceType_idx ON facturation (invoice_type)');
}
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('ALTER TABLE facturation DROP FOREIGN KEY FK_17EB513AB03A8386');
$this->addSql('ALTER TABLE facturation DROP FOREIGN KEY FK_17EB513A896DBBDE');
$this->addSql('DROP INDEX IDX_17EB513AB03A8386 ON facturation');
$this->addSql('DROP INDEX IDX_17EB513A896DBBDE ON facturation');
$this->addSql('DROP INDEX invoiceType_idx ON facturation');
$this->addSql('ALTER TABLE facturation CHANGE created_at createdAt DATETIME NOT NULL');
$this->addSql('ALTER TABLE facturation CHANGE updated_at updatedAt DATETIME NOT NULL');
$this->addSql('ALTER TABLE facturation CHANGE created_by_id createdBy INT DEFAULT NULL');
$this->addSql('ALTER TABLE facturation CHANGE updated_by_id updatedBy INT DEFAULT NULL');
$this->addSql('ALTER TABLE facturation CHANGE invoice_number receiptNumber INT DEFAULT NULL');
$this->addSql('ALTER TABLE facturation DROP invoice_type');
$this->addSql('ALTER TABLE facturation ADD CONSTRAINT FK_17EB513AD3564642 FOREIGN KEY (createdBy) REFERENCES users (id)');
$this->addSql('ALTER TABLE facturation ADD CONSTRAINT FK_17EB513AE8DE7170 FOREIGN KEY (updatedBy) REFERENCES users (id)');
$this->addSql('CREATE INDEX IDX_17EB513AD3564642 ON facturation (createdBy)');
$this->addSql('CREATE INDEX IDX_17EB513AE8DE7170 ON facturation (updatedBy)');
}
}