migrations/Version20210129183341.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. /**ah i
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20210129183341 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.         $this->addSql('CREATE TABLE invoice_tax_detail (id INT AUTO_INCREMENT NOT NULL, invoice_id INT DEFAULT NULL, tax NUMERIC(10, 2) NOT NULL, taxable_amount NUMERIC(10, 2) NOT NULL, tax_amount NUMERIC(10, 2) NOT NULL, type VARCHAR(100) NOT NULL, INDEX IDX_9B0065A62989F1FD (invoice_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  20.         $this->addSql('ALTER TABLE invoice_tax_detail ADD CONSTRAINT FK_9B0065A62989F1FD FOREIGN KEY (invoice_id) REFERENCES invoice (id)');
  21.         $this->addSql('INSERT INTO invoice_tax_detail(invoice_id,type,tax,taxable_amount,tax_amount)
  22.             SELECT invoice_item.invoice_id,invoice_item.type,invoice_item.tax,SUM(invoice_item.unit_price * invoice_item.quantity),SUM(invoice_item.unit_price * invoice_item.quantity * (invoice_item.tax / 100)) FROM invoice_item
  23.             WHERE invoice_item.type <> "discount"
  24.             GROUP BY invoice_item.invoice_id, invoice_item.tax, invoice_item.type
  25.             ORDER BY invoice_item.invoice_id ASC'
  26.         );
  27.     }
  28.     public function down(Schema $schema) : void
  29.     {
  30.         // this down() migration is auto-generated, please modify it to your needs
  31.         $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql''Migration can only be executed safely on \'mysql\'.');
  32.         $this->addSql('DROP TABLE invoice_tax_detail');
  33.     }
  34. }