migrations/Finance/Version20200511103220_FinanceChargeable.php line 1

  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations\Finance;
  4. use App\Doctrine\Type\Finance\ChargeableType;
  5. use App\Doctrine\Type\Finance\ExpenseType;
  6. use Doctrine\DBAL\Schema\Schema;
  7. use Doctrine\Migrations\AbstractMigration;
  8. /**
  9.  * Auto-generated Migration: Please modify to your needs!
  10.  */
  11. final class Version20200511103220_FinanceChargeable extends AbstractMigration
  12. {
  13.     public function getDescription() : string
  14.     {
  15.         return 'Add chargeable table';
  16.     }
  17.     public function up(Schema $schema) : void
  18.     {
  19.         $chargeableType ChargeableType::getName();
  20.         $expenseType ExpenseType::getName();
  21.         $this->addSql("CREATE TABLE finance_chargeable (
  22.             id                          SERIAL PRIMARY KEY,
  23.             bill_id                     INTEGER                              REFERENCES public.finance_bill (id),
  24.             invoice_id                  INTEGER                              REFERENCES public.finance_invoice (id),
  25.             chargeable_type             {$chargeableType}           NOT NULL,
  26.             expense_type                {$expenseType}              NOT NULL,
  27.             service_name                CHARACTER VARYING,
  28.             quantity                    INTEGER                     NOT NULL,
  29.             unit_price                  DECIMAL(18, 2)              NOT NULL,
  30.             sub_total                   DECIMAL(18, 2)              NOT NULL,
  31.             taxes_sum                   DECIMAL(18, 2)              NOT NULL,
  32.             grand_total                 DECIMAL(18, 2)              NOT NULL,
  33.             CONSTRAINT finance_chargeable_xor_chargeable CHECK (
  34.                 (bill_id IS NOT NULL AND invoice_id IS     NULL) OR
  35.                 (bill_id IS     NULL AND invoice_id IS NOT NULL)
  36.             )
  37.         )");
  38.         $this->addSql("CREATE INDEX finance_chargeable_bill_id_idx ON finance_chargeable (bill_id)");
  39.         $this->addSql("CREATE INDEX finance_chargeable_invoice_id_idx ON finance_chargeable (invoice_id)");
  40.     }
  41.     public function down(Schema $schema) : void
  42.     {
  43.         $this->addSql("DROP TABLE IF EXISTS finance_chargeable");
  44.     }
  45. }