Skip to content

Commit

Permalink
Remove unwanted whitespace from existing Organisation records
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chrislo committed Sep 11, 2023
1 parent b27f747 commit 12cfe5e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 12cfe5e

Please sign in to comment.