1
0

20260428120008_create_reports.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. declare(strict_types=1);
  3. use App\Infrastructure\Db\Migrations\BaseMigration;
  4. final class CreateReports extends BaseMigration
  5. {
  6. public function change(): void
  7. {
  8. $table = $this->table('reports');
  9. $table->addColumn('category_id', 'integer', ['null' => false, 'signed' => false]);
  10. $table->addColumn('reporter_id', 'integer', ['null' => false, 'signed' => false]);
  11. $this->addIpBinaryColumn($table, 'ip_bin', ['null' => false]);
  12. $table->addColumn('ip_text', 'string', ['limit' => 45, 'null' => false]);
  13. $table->addColumn('weight_at_report', 'decimal', ['precision' => 5, 'scale' => 2, 'null' => false]);
  14. $table->addColumn('metadata_json', 'text', ['null' => true]);
  15. $this->addTimestampColumn($table, 'received_at');
  16. $table
  17. ->addIndex(['ip_bin', 'category_id', 'received_at'], ['name' => 'idx_reports_ip_cat_received'])
  18. ->addIndex(['ip_bin'], ['name' => 'idx_reports_ip_bin'])
  19. ->addIndex(['category_id'])
  20. ->addIndex(['reporter_id'])
  21. ->addIndex(['received_at'])
  22. ->addForeignKey(
  23. 'category_id',
  24. 'categories',
  25. 'id',
  26. ['delete' => 'RESTRICT', 'update' => 'NO_ACTION', 'constraint' => 'fk_reports_category']
  27. )
  28. ->addForeignKey(
  29. 'reporter_id',
  30. 'reporters',
  31. 'id',
  32. ['delete' => 'RESTRICT', 'update' => 'NO_ACTION', 'constraint' => 'fk_reports_reporter']
  33. )
  34. ->create();
  35. }
  36. }