]> cat aescling's git repositories - mastodon.git/commitdiff
Fix old migrations failing because of strong_migrations update (#12692)
authorThibG <thib@sitedethib.com>
Sun, 29 Dec 2019 04:39:08 +0000 (05:39 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Sun, 29 Dec 2019 04:39:08 +0000 (05:39 +0100)
Fixes #12690

The `strong_migrations` update from ba2eac8824a85aa9541f8070ed7bcd22b9982cc8
introduced a check for `change_column_null` specific to Postgres. This rejects
old migrations.

This commit just wraps old migrations with `safety_assured` to bypass this
check. Alternatives would have been to:
- Disable that check entirely (a possibility added in that same
  `strong_migrations` version) for Mastodon, but it makes sense to write new
  migrations without such a strong lock.
- Rewrite the old migrations to do it in a way that do not require an exclusive
  lock. I thought fixing those old migrations for performance wasn't worth the
  pain. Also, if I understand correctly, the next version of
  `strong_migrations` is going to include a helper to do that. We could update
  those migrations at that point.

db/migrate/20170711225116_fix_null_booleans.rb
db/migrate/20171010025614_change_accounts_nonnullable_in_account_moderation_notes.rb
db/migrate/20171201000000_change_account_id_nonnullable_in_lists.rb
db/migrate/20180310000000_change_columns_in_notifications_nonnullable.rb

index 5b319471d700682acaf87ba78780ea2a87e112f3..aabb81f217b6b309b30a8806963f4724204e6c77 100644 (file)
@@ -1,17 +1,19 @@
 class FixNullBooleans < ActiveRecord::Migration[5.1]
   def change
-    change_column_default :domain_blocks, :reject_media, false
-    change_column_null :domain_blocks, :reject_media, false, false
+    safety_assured do
+      change_column_default :domain_blocks, :reject_media, false
+      change_column_null :domain_blocks, :reject_media, false, false
 
-    change_column_default :imports, :approved, false
-    change_column_null :imports, :approved, false, false
+      change_column_default :imports, :approved, false
+      change_column_null :imports, :approved, false, false
 
-    change_column_null :statuses, :sensitive, false, false
-    change_column_null :statuses, :reply, false, false
+      change_column_null :statuses, :sensitive, false, false
+      change_column_null :statuses, :reply, false, false
 
-    change_column_null :users, :admin, false, false
+      change_column_null :users, :admin, false, false
 
-    change_column_default :users, :otp_required_for_login, false
-    change_column_null :users, :otp_required_for_login, false, false
+      change_column_default :users, :otp_required_for_login, false
+      change_column_null :users, :otp_required_for_login, false, false
+    end
   end
 end
index 747e5a8269142c26e5ef2d7f014e29e4ad5425fa..1d7a0086c24addc5a21f40d6d730238af2e90c21 100644 (file)
@@ -1,6 +1,8 @@
 class ChangeAccountsNonnullableInAccountModerationNotes < ActiveRecord::Migration[5.1]
   def change
-    change_column_null :account_moderation_notes, :account_id, false
-    change_column_null :account_moderation_notes, :target_account_id, false
+    safety_assured do
+      change_column_null :account_moderation_notes, :account_id, false
+      change_column_null :account_moderation_notes, :target_account_id, false
+    end
   end
 end
index 3369e3b9e97ab7f28fbf69584c908807e5437756..ac86c9e777d825bd3326f4991a6ff942c009dc3e 100644 (file)
@@ -1,5 +1,7 @@
 class ChangeAccountIdNonnullableInLists < ActiveRecord::Migration[5.1]
   def change
-    change_column_null :lists, :account_id, false
+    safety_assured do
+      change_column_null :lists, :account_id, false
+    end
   end
 end
index 05ffd050104d8620fdcb864b30b1998462a65cc5..dba789207daf74e4fd48c87798b0b213d9a3f0ff 100644 (file)
@@ -1,8 +1,10 @@
 class ChangeColumnsInNotificationsNonnullable < ActiveRecord::Migration[5.1]
   def change
-    change_column_null :notifications, :activity_id, false
-    change_column_null :notifications, :activity_type, false
-    change_column_null :notifications, :account_id, false
-    change_column_null :notifications, :from_account_id, false
+    safety_assured do
+      change_column_null :notifications, :activity_id, false
+      change_column_null :notifications, :activity_type, false
+      change_column_null :notifications, :account_id, false
+      change_column_null :notifications, :from_account_id, false
+    end
   end
 end