From a9ba45358a3b29ef29f492c10cb4302e29510cc6 Mon Sep 17 00:00:00 2001 From: Chris Lowis Date: Mon, 11 Sep 2023 10:25:18 +0100 Subject: [PATCH] Remove unwanted whitespace from existing Organisation records There is an `Organisation` record in our production data that has leading and/or trailing whitespace in its name column. This migration removes that whitespace. Additional whitespace means records don't sort alphabetically in an expected way. At the time of writing there's only a single record with this issue in Integration and none in Production (although there's no guarentees others won't have been added by the time this migration runs). Because there's such a small number of records it seems safe to load and resave these records, triggering the hook added in the previous commit. --- ...911092404_strip_whitespace_from_organisation_names.rb | 9 +++++++++ db/schema.rb | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20230911092404_strip_whitespace_from_organisation_names.rb diff --git a/db/migrate/20230911092404_strip_whitespace_from_organisation_names.rb b/db/migrate/20230911092404_strip_whitespace_from_organisation_names.rb new file mode 100644 index 000000000..a18b1b766 --- /dev/null +++ b/db/migrate/20230911092404_strip_whitespace_from_organisation_names.rb @@ -0,0 +1,9 @@ +class StripWhitespaceFromOrganisationNames < ActiveRecord::Migration[7.0] + NAME_HAS_LEADING_OR_TRAILING_SPACE = "name REGEXP('^\s+') OR name REGEXP('\s+$')".freeze + + def up + Organisation.where(NAME_HAS_LEADING_OR_TRAILING_SPACE).each(&:save!) + end + + def down; end +end diff --git a/db/schema.rb b/db/schema.rb index 9669c00b5..f1b958e1b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_08_16_164936) do +ActiveRecord::Schema[7.0].define(version: 2023_09_11_092404) do create_table "batch_invitation_application_permissions", id: :integer, charset: "utf8mb3", force: :cascade do |t| t.integer "batch_invitation_id", null: false t.integer "supported_permission_id", null: false