Skip to content

[Backend] Add First and Last name to User model

Aishwarya Subramanian requested to merge user_name_migration into master

What does this MR do?

This change is part of Improved trial experience (https://gitlab.com/gitlab-org/gitlab-ee/issues/13233).

In order to remain consistent with the platforms that store User Leads data (Marketo, SalesForce), the full name is split in to first and last name.

This MR includes the following changes:

  1. Adds a migration to create columns for first and last name in User model
  2. Adds getter methods:
    • first_name: If not present, derives from name
    • last_name: If not present, derives from name
  3. Adds a before_save method:
    • name: name is currently a mandatory field, and is used in regular sign up. Until we completely migrate from name to first/last name it is important that we continue to update this value in the database.

      For this purpose, if there are changes to first or last name, the name column is updated accordingly.

Output of the migration

Migration:

Screen_Shot_2019-08-20_at_4.21.18_AM

Rollback:

Screen_Shot_2019-08-20_at_4.21.26_AM

CE back port changes: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/31985

Database checklist

When adding migrations:

  • Updated db/schema.rb
  • Added a down method so the migration can be reverted (Uses change method instead of up and down)
  • Added the output of the migration(s) to the MR body
  • Added tests for the migration in spec/migrations if necessary (e.g. when migrating data)

When adding or modifying queries to improve performance:

  • Included data that shows the performance improvement, preferably in the form of a benchmark
  • Included the output of EXPLAIN (ANALYZE, BUFFERS) of the relevant queries

When adding foreign keys to existing tables:

  • Included a migration to remove orphaned rows in the source table before adding the foreign key
  • Removed any instances of dependent: ... that may no longer be necessary

When adding tables:

  • Ordered columns based on the Ordering Table Columns guidelines
  • Added foreign keys to any columns pointing to data in other tables
  • Added indexes for fields that are used in statements such as WHERE, ORDER BY, GROUP BY, and JOINs

When removing columns, tables, indexes or other structures:

  • Removed these in a post-deployment migration
  • Made sure the application no longer uses (or ignores) these structures

/label database databasereview pending

Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/13661

Edited by Aishwarya Subramanian

Merge request reports