<?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 Version20190905043457 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\'.');
// fix bad datetimes
$this->addSql('SET @old_sql_mode := @@sql_mode ;');
$this->addSql('SET @new_sql_mode := @old_sql_mode ;');
$this->addSql("SET @new_sql_mode := TRIM(BOTH ',' FROM REPLACE(CONCAT(',',@new_sql_mode,','),',NO_ZERO_DATE,' ,','));");
$this->addSql("SET @new_sql_mode := TRIM(BOTH ',' FROM REPLACE(CONCAT(',',@new_sql_mode,','),',NO_ZERO_IN_DATE,',','));");
$this->addSql("SET @@sql_mode := @new_sql_mode ;");
$this->addSql("UPDATE accounting_entry SET createdAt='1969-12-31' WHERE createdAt < '0000-01-01 00:00:00'");
$this->addSql('ALTER TABLE order_payment ADD receipt_id INT DEFAULT NULL, ADD payment_type VARCHAR(50) DEFAULT NULL, ADD payment_sub_type VARCHAR(50) DEFAULT NULL, ADD authorization_code VARCHAR(50) DEFAULT NULL');
$this->addSql('ALTER TABLE order_payment ADD created_by_id INT DEFAULT NULL, ADD updated_by_id INT DEFAULT NULL, ADD created_at DATETIME NOT NULL, ADD updated_at DATETIME NOT NULL');
// restore sql mode
$this->addSql("SET @@sql_mode := @old_sql_mode ;");
$this->addSql('UPDATE order_payment LEFT JOIN accounting_entry ON order_payment.idAccountingEntry=accounting_entry.id LEFT JOIN credit_card ON accounting_entry.idCreditCard=credit_card.id SET
order_payment.payment_type=credit_card.shortname,
order_payment.authorization_code=accounting_entry.authorizationCode,
order_payment.payment_method_id=accounting_entry.idPaymentMethod,
order_payment.created_by_id=accounting_entry.createdBy,
order_payment.updated_by_id=accounting_entry.updatedBy,
order_payment.created_at=accounting_entry.createdAt,
order_payment.updated_at=accounting_entry.updatedAt
');
$this->addSql('ALTER TABLE order_payment ADD CONSTRAINT FK_9B522D46B03A8386 FOREIGN KEY (created_by_id) REFERENCES users (id)');
$this->addSql('ALTER TABLE order_payment ADD CONSTRAINT FK_9B522D46896DBBDE FOREIGN KEY (updated_by_id) REFERENCES users (id)');
$this->addSql('ALTER TABLE order_payment ADD CONSTRAINT FK_9B522D462B5CA896 FOREIGN KEY (receipt_id) REFERENCES receipt (id)');
$this->addSql('CREATE INDEX IDX_9B522D46B03A8386 ON order_payment (created_by_id)');
$this->addSql('CREATE INDEX IDX_9B522D46896DBBDE ON order_payment (updated_by_id)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_9B522D462B5CA896 ON order_payment (receipt_id)');
}
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 order_payment DROP FOREIGN KEY FK_9B522D462B5CA896');
$this->addSql('ALTER TABLE order_payment DROP FOREIGN KEY FK_9B522D46B03A8386');
$this->addSql('ALTER TABLE order_payment DROP FOREIGN KEY FK_9B522D46896DBBDE');
$this->addSql('DROP INDEX IDX_9B522D46B03A8386 ON order_payment');
$this->addSql('DROP INDEX IDX_9B522D46896DBBDE ON order_payment');
$this->addSql('DROP INDEX UNIQ_9B522D462B5CA896 ON order_payment');
$this->addSql('ALTER TABLE order_payment DROP receipt_id, DROP payment_type, DROP payment_sub_type, DROP authorization_code');
$this->addSql('ALTER TABLE order_payment DROP created_by_id, DROP updated_by_id, DROP created_at, DROP updated_at');
}
}