mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-15 16:59:41 +00:00
Make settings-related database migrations more robust (#37079)
This commit is contained in:
@@ -4,6 +4,8 @@ class MigrateTimelinePreviewSetting < ActiveRecord::Migration[8.0]
|
|||||||
class Setting < ApplicationRecord; end
|
class Setting < ApplicationRecord; end
|
||||||
|
|
||||||
def up
|
def up
|
||||||
|
Setting.reset_column_information
|
||||||
|
|
||||||
setting = Setting.find_by(var: 'timeline_preview')
|
setting = Setting.find_by(var: 'timeline_preview')
|
||||||
return unless setting.present? && setting.attributes['value'].present?
|
return unless setting.present? && setting.attributes['value'].present?
|
||||||
|
|
||||||
@@ -12,7 +14,8 @@ class MigrateTimelinePreviewSetting < ActiveRecord::Migration[8.0]
|
|||||||
Setting.upsert_all(
|
Setting.upsert_all(
|
||||||
%w(local_live_feed_access remote_live_feed_access local_topic_feed_access remote_topic_feed_access).map do |var|
|
%w(local_live_feed_access remote_live_feed_access local_topic_feed_access remote_topic_feed_access).map do |var|
|
||||||
{ var: var, value: value ? "--- public\n" : "--- authenticated\n" }
|
{ var: var, value: value ? "--- public\n" : "--- authenticated\n" }
|
||||||
end
|
end,
|
||||||
|
unique_by: index_exists?(:settings, [:thing_type, :thing_id, :var]) ? [:thing_type, :thing_id, :var] : :var
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ class MigrateLandingPageSetting < ActiveRecord::Migration[8.0]
|
|||||||
class Setting < ApplicationRecord; end
|
class Setting < ApplicationRecord; end
|
||||||
|
|
||||||
def up
|
def up
|
||||||
|
Setting.reset_column_information
|
||||||
|
|
||||||
setting = Setting.find_by(var: 'trends_as_landing_page')
|
setting = Setting.find_by(var: 'trends_as_landing_page')
|
||||||
return unless setting.present? && setting.attributes['value'].present?
|
return unless setting.present? && setting.attributes['value'].present?
|
||||||
|
|
||||||
@@ -12,7 +14,8 @@ class MigrateLandingPageSetting < ActiveRecord::Migration[8.0]
|
|||||||
Setting.upsert({
|
Setting.upsert({
|
||||||
var: 'landing_page',
|
var: 'landing_page',
|
||||||
value: value ? "--- trends\n" : "--- about\n",
|
value: value ? "--- trends\n" : "--- about\n",
|
||||||
})
|
},
|
||||||
|
unique_by: index_exists?(:settings, [:thing_type, :thing_id, :var]) ? [:thing_type, :thing_id, :var] : :var)
|
||||||
end
|
end
|
||||||
|
|
||||||
def down; end
|
def down; end
|
||||||
|
|||||||
Reference in New Issue
Block a user