Add skin migrations for glitch-soc

This commit is contained in:
Claire
2026-02-11 13:46:03 +01:00
parent c7b08d8f19
commit 01b576efed
4 changed files with 65 additions and 3 deletions

View File

@@ -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

View 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