mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 21:10:17 +08:00
decf1f27cf
* Phase 0 for user-selectable theme components - Drops `key` column from the `themes` table - Drops `theme_key` column from the `user_options` table - Adds `theme_ids` (array of ints default []) column to the `user_options` table and migrates data from `theme_key` to the new column. - Removes the `default_theme_key` site setting and adds `default_theme_id` instead. - Replaces `theme_key` cookie with a new one called `theme_ids` - no longer need Theme.settings_for_client
33 lines
996 B
Ruby
33 lines
996 B
Ruby
class DropKeyColumnFromThemes < ActiveRecord::Migration[5.2]
|
|
def up
|
|
add_column :user_options, :theme_ids, :integer, array: true, null: false, default: []
|
|
|
|
execute(
|
|
"UPDATE user_options AS uo
|
|
SET theme_ids = (
|
|
SELECT array_agg(themes.id)
|
|
FROM themes
|
|
INNER JOIN user_options
|
|
ON themes.key = user_options.theme_key
|
|
WHERE user_options.user_id = uo.user_id
|
|
) WHERE uo.theme_key IN (SELECT key FROM themes)"
|
|
)
|
|
|
|
execute(
|
|
"INSERT INTO site_settings (name, data_type, value, created_at, updated_at)
|
|
SELECT 'default_theme_id', 3, id, now(), now()
|
|
FROM themes
|
|
WHERE key = (SELECT value FROM site_settings WHERE name = 'default_theme_key')"
|
|
)
|
|
|
|
execute("DELETE FROM site_settings WHERE name = 'default_theme_key'")
|
|
|
|
# delayed drop for theme_key on user_options table
|
|
# delayed drop for key on themes table
|
|
end
|
|
|
|
def down
|
|
raise ActiveRecord::IrreversibleMigration
|
|
end
|
|
end
|