20260428120000_create_users.php 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. declare(strict_types=1);
  3. use App\Infrastructure\Db\Migrations\BaseMigration;
  4. final class CreateUsers extends BaseMigration
  5. {
  6. public function change(): void
  7. {
  8. $table = $this->table('users');
  9. $table
  10. ->addColumn('subject', 'string', ['limit' => 255, 'null' => true])
  11. ->addColumn('email', 'string', ['limit' => 255, 'null' => true])
  12. ->addColumn('display_name', 'string', ['limit' => 255, 'null' => true])
  13. ->addColumn('role', 'string', ['limit' => 32, 'null' => false])
  14. ->addColumn('is_local', 'boolean', ['null' => false, 'default' => false]);
  15. $this->addTimestampColumn($table, 'last_login_at', ['null' => true]);
  16. $this->addTimestampColumn($table, 'created_at');
  17. // SQLite and MySQL both treat NULLs as distinct in unique indexes, so a
  18. // full unique index on `subject` works for either driver — local users
  19. // simply have NULL subjects.
  20. $table
  21. ->addIndex(['subject'], ['unique' => true, 'name' => 'uniq_users_subject'])
  22. ->addIndex(['email'])
  23. ->addIndex(['is_local']);
  24. $table->create();
  25. }
  26. }