mirror of
https://github.com/glitch-soc/mastodon.git
synced 2026-03-29 03:00:33 +02:00
Add skin migrations for glitch-soc
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class GlitchMigrateDefaultSkinSetting < ActiveRecord::Migration[8.0]
|
||||
class Setting < ApplicationRecord; end
|
||||
|
||||
def up
|
||||
Setting.reset_column_information
|
||||
|
||||
return unless %w(glitch vanilla).include?(flavour)
|
||||
|
||||
setting = Setting.find_by(var: 'skin')
|
||||
return unless setting.present? && setting.attributes['value'].present?
|
||||
|
||||
theme = YAML.safe_load(setting.attributes['value'], permitted_classes: [ActiveSupport::HashWithIndifferentAccess, Symbol])
|
||||
return unless %w(mastodon-light contrast system).include?(theme)
|
||||
|
||||
setting.update_column('value', "--- default\n")
|
||||
end
|
||||
|
||||
def down; end
|
||||
|
||||
private
|
||||
|
||||
def flavour
|
||||
setting = Setting.find_by(var: 'flavour')
|
||||
return 'glitch' unless setting.present? && setting.attributes['value'].present?
|
||||
|
||||
YAML.safe_load(setting.attributes['value'], permitted_classes: [ActiveSupport::HashWithIndifferentAccess, Symbol])
|
||||
end
|
||||
end
|
||||
31
db/migrate/20260209143307_glitch_migrate_user_skin.rb
Normal file
31
db/migrate/20260209143307_glitch_migrate_user_skin.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class GlitchMigrateUserSkin < ActiveRecord::Migration[8.0]
|
||||
disable_ddl_transaction!
|
||||
|
||||
# Dummy classes, to make migration possible across version changes
|
||||
class User < ApplicationRecord; end
|
||||
|
||||
def up
|
||||
User.where.not(settings: nil).find_each do |user|
|
||||
settings = Oj.load(user.attributes_before_type_cast['settings'])
|
||||
next if settings.nil? || settings['skin'].blank? || %w(system default mastodon-light contrast).exclude?(settings['skin'])
|
||||
|
||||
case settings['skin']
|
||||
when 'default'
|
||||
settings['web.color_scheme'] = 'dark'
|
||||
settings['web.contrast'] = 'auto'
|
||||
when 'contrast'
|
||||
settings['web.color_scheme'] = 'dark'
|
||||
settings['web.contrast'] = 'high'
|
||||
when 'mastodon-light'
|
||||
settings['web.color_scheme'] = 'light'
|
||||
settings['web.contrast'] = 'auto'
|
||||
end
|
||||
|
||||
settings['skin'] = 'default'
|
||||
|
||||
user.update_column('settings', Oj.dump(settings))
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user