mirror of
https://github.com/discourse/discourse.git
synced 2024-12-24 03:13:44 +08:00
39 lines
1.3 KiB
Ruby
39 lines
1.3 KiB
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
class SplitHideProfileAndPresence < ActiveRecord::Migration[7.1]
|
||
|
def up
|
||
|
# Split default_hide_profile_and_presence if setting exists
|
||
|
result =
|
||
|
execute(
|
||
|
"SELECT value, data_type FROM site_settings WHERE name = 'default_hide_profile_and_presence' LIMIT 1",
|
||
|
).first
|
||
|
|
||
|
if result
|
||
|
value = result["value"]
|
||
|
data_type = result["data_type"]
|
||
|
|
||
|
execute "DELETE FROM site_settings WHERE name = 'default_hide_profile_and_presence'"
|
||
|
execute <<-SQL
|
||
|
INSERT INTO site_settings (name, value, data_type, created_at, updated_at)
|
||
|
VALUES
|
||
|
('default_hide_profile', '#{value}', '#{data_type}', NOW(), NOW()),
|
||
|
('default_hide_presence', '#{value}', '#{data_type}', NOW(), NOW());
|
||
|
SQL
|
||
|
end
|
||
|
|
||
|
# Add new columns to user_options
|
||
|
execute "ALTER TABLE user_options ADD COLUMN hide_profile BOOLEAN DEFAULT FALSE NOT NULL"
|
||
|
execute "ALTER TABLE user_options ADD COLUMN hide_presence BOOLEAN DEFAULT FALSE NOT NULL"
|
||
|
execute <<-SQL
|
||
|
UPDATE user_options
|
||
|
SET hide_profile = hide_profile_and_presence,
|
||
|
hide_presence = hide_profile_and_presence
|
||
|
WHERE hide_profile_and_presence;
|
||
|
SQL
|
||
|
end
|
||
|
|
||
|
def down
|
||
|
raise ActiveRecord::IrreversibleMigration
|
||
|
end
|
||
|
end
|