discourse/db/migrate/20250804005557_enable_markdown_monospace_font_user_option.rb
Martin Brennan 7121cfd4ab
FEATURE: User preference for editor Markdown monospace font (#34051)
This commit responds to feedback in the Discourse Meta discussion

https://meta.discourse.org/t/monospace-font-in-the-markdown-only-editor/359936

This change introduces a user preference that allows users to choose
whether the Markdown editor uses a monospace font. The default setting
is `true` for new sites, but set to `false` for existing sites to avoid
disrupting current users' experiences.

Admins can change the `default_other_enable_markdown_monospace_font`
site setting to manage this for all users.
2025-08-04 14:56:21 +10:00

29 lines
941 B
Ruby

# frozen_string_literal: true
class EnableMarkdownMonospaceFontUserOption < ActiveRecord::Migration[8.0]
def up
add_column :user_options, :enable_markdown_monospace_font, :boolean, default: true, null: false
if Migration::Helpers.existing_site?
execute <<~SQL
INSERT INTO site_settings(name, data_type, value, created_at, updated_at)
VALUES('default_other_enable_markdown_monospace_font', 5, 'f', NOW(), NOW())
ON CONFLICT (name) DO NOTHING
SQL
execute <<~SQL
UPDATE user_options
SET enable_markdown_monospace_font = false
SQL
end
end
def down
if column_exists?(:user_options, :enable_markdown_monospace_font)
remove_column :user_options, :enable_markdown_monospace_font
end
execute <<~SQL if Migration::Helpers.existing_site?
DELETE FROM site_settings WHERE name = 'default_other_enable_markdown_monospace_font'
SQL
end
end