20221220212227_add_document_table.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. declare(strict_types=1);
  3. use Phinx\Db\Adapter\MysqlAdapter;
  4. use Phinx\Migration\AbstractMigration;
  5. final class AddDocumentTable extends AbstractMigration {
  6. public function change(): void {
  7. $this->table("document", ["signed" => false])
  8. ->addColumn("user_id", "integer", ["signed" => false])
  9. ->addColumn("sale_id", "integer", ["signed" => false, "null" => true])
  10. ->addColumn("supplier_id", "integer", ["signed" => false, "null" => true])
  11. ->addColumn("location_id", "integer", ["signed" => false, "null" => true])
  12. ->addColumn("related_document_id", "integer", ["signed" => false, "null" => true])
  13. ->addColumn("type", "integer", ["signed" => false, "limit" => MysqlAdapter::INT_TINY])
  14. ->addColumn("invoice_status", "integer", ["signed" => false, "limit" => MysqlAdapter::INT_TINY, "null" => true])
  15. ->addColumn("currency", "string", ["limit" => 3, "null" => true])
  16. ->addColumn("tax_rate", "decimal", ["precision" => 5, "scale" => 2, "null" => true])
  17. ->addColumn("billing_address", "string", ["null" => true])
  18. ->addColumn("delivery_address", "string", ["null" => true])
  19. ->addColumn("number", "integer", ["signed" => false, "null" => true])
  20. ->addColumn("date", "date", ["null" => true])
  21. ->addColumn("po_number", "string", ["null" => true])
  22. ->addColumn("terms", "string", ["null" => true])
  23. ->addColumn("delivery_company", "string", ["null" => true])
  24. ->addColumn("tracking_number", "string", ["null" => true])
  25. ->addColumn("delivery_cost", "string", ["null" => true])
  26. ->addColumn("notes", "text", ["null" => true])
  27. ->addColumn("dts_finalised", "datetime", ["null" => true])
  28. ->addColumn("dts_paid", "datetime", ["null" => true])
  29. ->addColumn("dts_created", "datetime")
  30. ->addColumn("dts_updated", "datetime", ["null" => true])
  31. ->addColumn("dts_deleted", "datetime", ["null" => true])
  32. ->addForeignKey("user_id", "user", "id", ["update" => "CASCADE", "delete" => "RESTRICT"])
  33. ->addForeignKey("sale_id", "sale", "id", ["update" => "CASCADE", "delete" => "CASCADE"])
  34. ->addForeignKey("supplier_id", "supplier", "id", ["update" => "CASCADE", "delete" => "RESTRICT"])
  35. ->addForeignKey("location_id", "location", "id", ["update" => "CASCADE", "delete" => "RESTRICT"])
  36. ->addForeignKey("related_document_id", "document", "id", ["update" => "CASCADE", "delete" => "CASCADE"])
  37. ->create();
  38. }
  39. }