Changing user email address in Gitlab using rails console

For reasons that will remain unspoken, Active directory that Gitlab authenticates against changed its name. After gitlab.rb was adjusted to reflect the change, another issue popped up. It was simply impossible to change the email addresses of the users. Thankfully, there is a solution, which I shamelessly stole and replicated here for my own reference.


[root@gitlab-1 gitlab]# gitlab-rails console
--------------------------------------------------------------------------------
 GitLab:       13.0.0 (6743e883eae) FOSS
 GitLab Shell: 13.2.0
 PostgreSQL:   11.7
--------------------------------------------------------------------------------
Loading production environment (Rails 6.0.3)
irb(main):001:0> user = User.find_by_email("old_email@example.com")
=> #<User id:4 @old_email>
irb(main):002:0> user.email
=> "old_email@example.com"
irb(main):003:0> user.email = "new_email@example.com"
=> "new_email@example.com"
irb(main):004:0> user.save
=> true
irb(main):009:0>

That’s it.