Migrate to new theming infrastructure (#37612)

This commit is contained in:
Claire
2026-02-10 11:59:47 +01:00
committed by GitHub
parent fb89198460
commit 75ba314e6b
17 changed files with 93 additions and 101 deletions

View File

@@ -0,0 +1,22 @@
# frozen_string_literal: true
class MigrateDefaultThemeSetting < ActiveRecord::Migration[8.0]
class Setting < ApplicationRecord; end
def up
Setting.reset_column_information
setting = Setting.find_by(var: 'theme')
return unless setting.present? && setting.attributes['value'].present? && %w(mastodon-light contrast system).include?(setting.attributes['value'])
Setting.upsert(
{
var: 'theme',
value: "--- default\n",
},
unique_by: index_exists?(:settings, [:thing_type, :thing_id, :var]) ? [:thing_type, :thing_id, :var] : :var
)
end
def down; end
end

View File

@@ -0,0 +1,31 @@
# frozen_string_literal: true
class MigrateUserTheme < 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['theme'].blank? || %w(system default mastodon-light contrast).exclude?(settings['theme'])
case settings['theme']
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['theme'] = 'default'
user.update_column('settings', Oj.dump(settings))
end
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2026_01_27_141820) do
ActiveRecord::Schema[8.0].define(version: 2026_02_09_143308) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
@@ -1127,6 +1127,7 @@ ActiveRecord::Schema[8.0].define(version: 2026_01_27_141820) do
t.string "poll_options", array: true
t.boolean "sensitive"
t.bigint "quote_id"
t.string "content_type"
t.index ["account_id"], name: "index_status_edits_on_account_id"
t.index ["status_id"], name: "index_status_edits_on_status_id"
end
@@ -1189,6 +1190,8 @@ ActiveRecord::Schema[8.0].define(version: 2026_01_27_141820) do
t.bigint "ordered_media_attachment_ids", array: true
t.datetime "fetched_replies_at"
t.integer "quote_approval_policy", default: 0, null: false
t.boolean "local_only"
t.string "content_type"
t.index ["account_id", "id", "visibility", "updated_at"], name: "index_statuses_20190820", order: { id: :desc }, where: "(deleted_at IS NULL)"
t.index ["account_id"], name: "index_statuses_on_account_id"
t.index ["conversation_id"], name: "index_statuses_on_conversation_id"