migrations/Version20210408140651.php line 1

Open in your IDE?
  1. <?php
  2. namespace DoctrineMigrations;
  3. use Doctrine\DBAL\Schema\Schema;
  4. use Doctrine\Migrations\AbstractMigration;
  5. /**
  6.  * Auto-generated Migration: Please modify to your needs!
  7.  */
  8. class Version20210408140651 extends AbstractMigration
  9. {
  10.     public function up(Schema $schema): void
  11.     {
  12.         // this up() migration is auto-generated, please modify it to your needs
  13.         $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql''Migration can only be executed safely on \'mysql\'.');
  14.         $this->addSql('ALTER TABLE work_log ADD labour_rate NUMERIC(8, 2) DEFAULT NULL, ADD labour_rate_internal NUMERIC(8, 2) DEFAULT NULL');
  15.         $this->addSql('ALTER TABLE stock_item ADD cost_price NUMERIC(8, 2) DEFAULT NULL, ADD issue_price NUMERIC(8, 2) DEFAULT NULL');
  16.         $this->addSql('UPDATE work_log
  17.             LEFT JOIN job ON job.id = work_log.job_id
  18.             LEFT JOIN customer ON customer.id = job.customer_id
  19.             SET work_log.labour_rate_internal = 40,
  20.                 work_log.labour_rate = (
  21.                     CASE
  22.                         WHEN job.charge_method <> 0 THEN 40
  23.                         WHEN job.customer_id IS NULL THEN 40
  24.                         WHEN customer.labour_rate IS NOT NULL THEN customer.labour_rate
  25.                         ELSE 50
  26.                     END
  27.                 )
  28.         ');
  29.         $this->addSql('UPDATE stock_item
  30.             LEFT JOIN supplier_stock ON supplier_stock.id = stock_item.supplierStock_id
  31.             SET stock_item.cost_price = supplier_stock.cost_price,
  32.                 stock_item.issue_price = supplier_stock.issue_price
  33.             WHERE stock_item.job_id IS NOT NULL
  34.         ');
  35.     }
  36.     public function down(Schema $schema): void
  37.     {
  38.         // this down() migration is auto-generated, please modify it to your needs
  39.         $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql''Migration can only be executed safely on \'mysql\'.');
  40.         $this->addSql('ALTER TABLE stock_item DROP cost_price, DROP issue_price');
  41.         $this->addSql('ALTER TABLE work_log DROP labour_rate, DROP labour_rate_internal');
  42.     }
  43. }