1
0

20260428120006_create_consumers.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. declare(strict_types=1);
  3. use App\Infrastructure\Db\Migrations\BaseMigration;
  4. final class CreateConsumers extends BaseMigration
  5. {
  6. public function change(): void
  7. {
  8. $table = $this->table('consumers');
  9. $table
  10. ->addColumn('name', 'string', ['limit' => 128, 'null' => false])
  11. ->addColumn('description', 'text', ['null' => true])
  12. ->addColumn('policy_id', 'integer', ['null' => false, 'signed' => false])
  13. ->addColumn('is_active', 'boolean', ['null' => false, 'default' => true])
  14. ->addColumn('created_by_user_id', 'integer', ['null' => true, 'signed' => false]);
  15. $this->addTimestampColumn($table, 'created_at');
  16. $this->addTimestampColumn($table, 'last_pulled_at', ['null' => true]);
  17. $table
  18. ->addIndex(['name'], ['unique' => true, 'name' => 'uniq_consumers_name'])
  19. ->addIndex(['policy_id'])
  20. ->addIndex(['created_by_user_id'])
  21. ->addForeignKey(
  22. 'policy_id',
  23. 'policies',
  24. 'id',
  25. ['delete' => 'RESTRICT', 'update' => 'NO_ACTION', 'constraint' => 'fk_consumers_policy']
  26. )
  27. ->addForeignKey(
  28. 'created_by_user_id',
  29. 'users',
  30. 'id',
  31. ['delete' => 'SET_NULL', 'update' => 'NO_ACTION', 'constraint' => 'fk_consumers_created_by']
  32. )
  33. ->create();
  34. }
  35. }