Ensure no null settings context hash for extensions settings

Issue: Enforce not-null constraint on settings_context... (#503812 - closed)

What does this MR do and why?

  • Adds not-null validation for extensions setting type at the application level only. This is because non-extensions setting types are expected to have null settings context hash.
  • Backfills existing extensions settings with null settings context hash to default extensions marketplace settings.

References

Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

Setup:

Before pulling this branch, let's create vs_code_settings records in the Rails console:

Extension settings

Non-extension settings

VsCode::Settings::VsCodeSetting.create!(
  user_id:  1,
  setting_type: 'extensions',
  content:'{}',
  version: 6,
  settings_context_hash: nil,
  uuid: SecureRandom.uuid
)
VsCode::Settings::VsCodeSetting.create!(
  user_id:  1,
  setting_type: 'globalState',
  content:'{}',
  version: 1,
  settings_context_hash: nil,
  uuid: SecureRandom.uuid
)

Backfill:

  • Pull this branch run migrations (bundle exec rake db:migrate)

  • Confirm backfill successful: extensions setting no longer has nil settings context hash by running

    VsCode::Settings::VsCodeSetting.find_by(settings_context_hash: nil, setting_type: 'extensions') # nil
  • Confirm non-extensions settings are not affected

    VsCode::Settings::VsCodeSetting.find_by(settings_context_hash: nil, setting_type: 'globalState') # returns record

Model Validation:

  • Using the command outlined in the setup step, create another extensions settings record with nil settings context hash.
  • Should result in validation error: ActiveRecord::RecordInvalid: Validation failed: Settings context hash cannot be blank for extensions setting type
  • Create another non-extensions settings record with nil settings context hash and setting_type: 'keybindings'
  • Should not result in validation error.
Edited by Cindy Halim

Merge request reports

Loading