migrations/Finance/Version20200511103220_FinanceChargeable.php line 1
<?php
declare(strict_types=1);
namespace DoctrineMigrations\Finance;
use App\Doctrine\Type\Finance\ChargeableType;
use App\Doctrine\Type\Finance\ExpenseType;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20200511103220_FinanceChargeable extends AbstractMigration
{
public function getDescription() : string
{
return 'Add chargeable table';
}
public function up(Schema $schema) : void
{
$chargeableType = ChargeableType::getName();
$expenseType = ExpenseType::getName();
$this->addSql("CREATE TABLE finance_chargeable (
id SERIAL PRIMARY KEY,
bill_id INTEGER REFERENCES public.finance_bill (id),
invoice_id INTEGER REFERENCES public.finance_invoice (id),
chargeable_type {$chargeableType} NOT NULL,
expense_type {$expenseType} NOT NULL,
service_name CHARACTER VARYING,
quantity INTEGER NOT NULL,
unit_price DECIMAL(18, 2) NOT NULL,
sub_total DECIMAL(18, 2) NOT NULL,
taxes_sum DECIMAL(18, 2) NOT NULL,
grand_total DECIMAL(18, 2) NOT NULL,
CONSTRAINT finance_chargeable_xor_chargeable CHECK (
(bill_id IS NOT NULL AND invoice_id IS NULL) OR
(bill_id IS NULL AND invoice_id IS NOT NULL)
)
)");
$this->addSql("CREATE INDEX finance_chargeable_bill_id_idx ON finance_chargeable (bill_id)");
$this->addSql("CREATE INDEX finance_chargeable_invoice_id_idx ON finance_chargeable (invoice_id)");
}
public function down(Schema $schema) : void
{
$this->addSql("DROP TABLE IF EXISTS finance_chargeable");
}
}