migrations/Version20190905043457.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 Version20190905043457 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.         // fix bad datetimes
  20.         $this->addSql('SET @old_sql_mode := @@sql_mode ;');
  21.         $this->addSql('SET @new_sql_mode := @old_sql_mode ;');
  22.         $this->addSql("SET @new_sql_mode := TRIM(BOTH ',' FROM REPLACE(CONCAT(',',@new_sql_mode,','),',NO_ZERO_DATE,'  ,','));");
  23.         $this->addSql("SET @new_sql_mode := TRIM(BOTH ',' FROM REPLACE(CONCAT(',',@new_sql_mode,','),',NO_ZERO_IN_DATE,',','));");
  24.         $this->addSql("SET @@sql_mode := @new_sql_mode ;");
  25.         $this->addSql("UPDATE accounting_entry SET createdAt='1969-12-31' WHERE createdAt < '0000-01-01 00:00:00'");
  26.         $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');
  27.         $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');
  28.         // restore sql mode
  29.         $this->addSql("SET @@sql_mode := @old_sql_mode ;");
  30.         $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
  31.                             order_payment.payment_type=credit_card.shortname,
  32.                             order_payment.authorization_code=accounting_entry.authorizationCode,
  33.                             order_payment.payment_method_id=accounting_entry.idPaymentMethod,
  34.                             order_payment.created_by_id=accounting_entry.createdBy,
  35.                             order_payment.updated_by_id=accounting_entry.updatedBy,
  36.                             order_payment.created_at=accounting_entry.createdAt,
  37.                             order_payment.updated_at=accounting_entry.updatedAt
  38.         ');
  39.         $this->addSql('ALTER TABLE order_payment ADD CONSTRAINT FK_9B522D46B03A8386 FOREIGN KEY (created_by_id) REFERENCES users (id)');
  40.         $this->addSql('ALTER TABLE order_payment ADD CONSTRAINT FK_9B522D46896DBBDE FOREIGN KEY (updated_by_id) REFERENCES users (id)');
  41.         $this->addSql('ALTER TABLE order_payment ADD CONSTRAINT FK_9B522D462B5CA896 FOREIGN KEY (receipt_id) REFERENCES receipt (id)');
  42.         $this->addSql('CREATE INDEX IDX_9B522D46B03A8386 ON order_payment (created_by_id)');
  43.         $this->addSql('CREATE INDEX IDX_9B522D46896DBBDE ON order_payment (updated_by_id)');
  44.         $this->addSql('CREATE UNIQUE INDEX UNIQ_9B522D462B5CA896 ON order_payment (receipt_id)');
  45.     }
  46.     public function down(Schema $schema) : void
  47.     {
  48.         // this down() migration is auto-generated, please modify it to your needs
  49.         $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql''Migration can only be executed safely on \'mysql\'.');
  50.         $this->addSql('ALTER TABLE order_payment DROP FOREIGN KEY FK_9B522D462B5CA896');
  51.         $this->addSql('ALTER TABLE order_payment DROP FOREIGN KEY FK_9B522D46B03A8386');
  52.         $this->addSql('ALTER TABLE order_payment DROP FOREIGN KEY FK_9B522D46896DBBDE');
  53.         $this->addSql('DROP INDEX IDX_9B522D46B03A8386 ON order_payment');
  54.         $this->addSql('DROP INDEX IDX_9B522D46896DBBDE ON order_payment');
  55.         $this->addSql('DROP INDEX UNIQ_9B522D462B5CA896 ON order_payment');
  56.         $this->addSql('ALTER TABLE order_payment DROP receipt_id, DROP payment_type, DROP payment_sub_type, DROP authorization_code');
  57.         $this->addSql('ALTER TABLE order_payment DROP created_by_id, DROP updated_by_id, DROP created_at, DROP updated_at');
  58.     }
  59. }