20260428120012_create_allowlist.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. declare(strict_types=1);
  3. use App\Infrastructure\Db\Migrations\BaseMigration;
  4. final class CreateAllowlist extends BaseMigration
  5. {
  6. public function change(): void
  7. {
  8. $table = $this->table('allowlist');
  9. $table->addColumn('kind', 'string', ['limit' => 16, 'null' => false]);
  10. $this->addIpBinaryColumn($table, 'ip_bin', ['null' => true]);
  11. $this->addIpBinaryColumn($table, 'network_bin', ['null' => true]);
  12. $table->addColumn('prefix_length', 'smallinteger', ['null' => true, 'signed' => false]);
  13. $table->addColumn('reason', 'text', ['null' => true]);
  14. $table->addColumn('created_by_user_id', 'integer', ['null' => true, 'signed' => false]);
  15. $this->addTimestampColumn($table, 'created_at');
  16. $table
  17. ->addIndex(['ip_bin'], ['name' => 'idx_allowlist_ip_bin'])
  18. ->addIndex(['network_bin'], ['name' => 'idx_allowlist_network_bin'])
  19. ->addIndex(['kind'])
  20. ->addIndex(['created_by_user_id'])
  21. ->addForeignKey(
  22. 'created_by_user_id',
  23. 'users',
  24. 'id',
  25. ['delete' => 'SET_NULL', 'update' => 'NO_ACTION', 'constraint' => 'fk_allowlist_created_by']
  26. )
  27. ->create();
  28. }
  29. }