migrations/Finance/Version20200511102738_FinanceInvoice.php line 1

  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations\Finance;
  4. use App\Doctrine\Type\Finance\InvoiceType;
  5. use App\Doctrine\Type\Finance\PayableStatus;
  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 Version20200511102738_FinanceInvoice extends AbstractMigration
  12. {
  13.     public function getDescription() : string
  14.     {
  15.         return 'Add invoice table';
  16.     }
  17.     public function up(Schema $schema) : void
  18.     {
  19.         $invoiceTypeType InvoiceType::getName();
  20.         $payableStatusType PayableStatus::getName();
  21.         $this->addSql("CREATE TABLE finance_invoice (
  22.             id                          SERIAL PRIMARY KEY,
  23.             identifier                  UUID                        NOT NULL,
  24.             shipping_plan_id            INTEGER                     NOT NULL REFERENCES public.expediting_shipping_plan (id),
  25.             payable_to                  INTEGER                     NOT NULL REFERENCES public.company (id),
  26.             payable_by                  INTEGER                     NOT NULL REFERENCES public.company (id),
  27.             original_quote_id           INTEGER                              REFERENCES public.finance_invoice (id),
  28.             number                      CHARACTER VARYING           NOT NULL,
  29.             external_reference          CHARACTER VARYING,
  30.             lines_sum                   DECIMAL(18, 2),
  31.             taxes_sum                   DECIMAL(18, 2),
  32.             total                       DECIMAL(18, 2),
  33.             due_on                      DATE,
  34.             paid_on                     DATE,
  35.             type                        {$invoiceTypeType}          NOT NULL,
  36.             status                      {$payableStatusType}        NOT NULL,
  37.             created_by                  INTEGER                              REFERENCES public.user (id),
  38.             updated_by                  INTEGER                              REFERENCES public.user (id),
  39.             created_at                  TIMESTAMP(0) WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
  40.             updated_at                  TIMESTAMP(0) WITH TIME ZONE,
  41.             deleted_at                  TIMESTAMP(0) WITH TIME ZONE,
  42.             CONSTRAINT finance_invoice_original_quote_id_key UNIQUE (original_quote_id),
  43.             CONSTRAINT finance_invoice_identifier_key UNIQUE (identifier),
  44.             CONSTRAINT finance_invoice_number_key UNIQUE (number),
  45.             CONSTRAINT finance_invoice_external_reference_key UNIQUE (external_reference)
  46.         )");
  47.         $this->addSql("COMMENT ON COLUMN finance_invoice.identifier IS '(DC2Type:ulid)'");
  48.         $this->addSql("CREATE INDEX finance_invoice_shipping_plan_id_idx ON finance_invoice (shipping_plan_id)");
  49.         $this->addSql("CREATE INDEX finance_invoice_payable_to_idx ON finance_invoice (payable_to)");
  50.         $this->addSql("CREATE INDEX finance_invoice_payable_by_idx ON finance_invoice (payable_by)");
  51.         $this->addSql("CREATE INDEX finance_invoice_created_by_idx ON finance_invoice (created_by)");
  52.         $this->addSql("CREATE INDEX finance_invoice_updated_by_idx ON finance_invoice (updated_by)");
  53.     }
  54.     public function down(Schema $schema) : void
  55.     {
  56.         $this->addSql("DROP TABLE IF EXISTS finance_invoice");
  57.     }
  58. }