Skip to content

A platform for community discussion. Free, open, simple.

DEV: Only lock rows that need to change in migration (#18319)

Daniel Waterworthe3d7253199ce
diff --git a/db/migrate/20220920044310_enforce_user_profile_max_limits.rb b/db/migrate/20220920044310_enforce_user_profile_max_limits.rb
index 14d5db8ade8..d484f96b512 100644
--- a/db/migrate/20220920044310_enforce_user_profile_max_limits.rb
+++ b/db/migrate/20220920044310_enforce_user_profile_max_limits.rb
@@ -2,8 +2,8 @@
class EnforceUserProfileMaxLimits < ActiveRecord::Migration[7.0]
def change
- execute "UPDATE user_profiles SET location = LEFT(location, 3000) WHERE location IS NOT NULL"
- execute "UPDATE user_profiles SET website = LEFT(website, 3000) WHERE website IS NOT NULL"
+ execute "UPDATE user_profiles SET location = LEFT(location, 3000) WHERE location IS NOT NULL AND LENGTH(location) > 3000"
+ execute "UPDATE user_profiles SET website = LEFT(website, 3000) WHERE website IS NOT NULL AND LENGTH(website) > 3000"
change_column :user_profiles, :location, :string, limit: 3000
change_column :user_profiles, :website, :string, limit: 3000