Skip to content

Move out user profile related data to a separate table

Problem to solve

users table has a few string columns without limit:

  • bio
  • linkedin
  • twitter
  • skype
  • website_url
  • location
  • organization

The columns are rarely used in the application, only at a few places:

  • The user's profile page.
  • Users API.

Proposal

Move these columns to the user_details table and introduce reasonable size limits.

Benefits

  • Reduced users table size. Less memory is needed to load a user record in ruby.
  • A common place to add similar columns in the future, see: !20254 (closed)

Disadvantages

  • Requires an additional query to preload the records, when listing users via the API. (not a big problem IMHO)

Risk: users table is a high traffic table, requires special migration steps.

Implementation plan far a column

  1. Create the column in the user_details table.
  2. Setup ActiveRecord callback to keep the value up to date between users and user_details
  3. Add a special index that allows iterating over the records. (create index i1 on users (id) where your_field is not null)
  4. Implement and trigger background migration.
  5. Release N+1: Update the backend to persist the column only in the user_details table.
  6. Release N+1: Ignore the column in the user_details table.
  7. Release N+2: Remove the column from users following our DB guidelines.

Example migration for bio: !27773 (merged)

Columns to migrate (with separate MRs per attribute):

  • bio - !27773 (merged)
  • linkedin
  • twitter
  • skype
  • website_url
  • location
  • organization
Edited by Christina Lohr