2023-02-12 23:37:59 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class PopulateCategorySettings < ActiveRecord::Migration[7.0]
|
|
|
|
def up
|
|
|
|
execute(<<~SQL)
|
|
|
|
INSERT INTO
|
|
|
|
category_settings(
|
|
|
|
category_id,
|
|
|
|
require_topic_approval,
|
|
|
|
require_reply_approval,
|
|
|
|
num_auto_bump_daily,
|
|
|
|
created_at,
|
|
|
|
updated_at
|
|
|
|
)
|
|
|
|
SELECT
|
|
|
|
category_id,
|
|
|
|
MAX(
|
|
|
|
CASE WHEN (name = 'require_topic_approval')
|
2023-02-13 03:07:46 -05:00
|
|
|
THEN NULLIF(value, '') ELSE NULL END
|
2023-02-12 23:37:59 -05:00
|
|
|
)::boolean AS require_topic_approval,
|
|
|
|
MAX(
|
|
|
|
CASE WHEN (name = 'require_reply_approval')
|
2023-02-13 03:07:46 -05:00
|
|
|
THEN NULLIF(value, '') ELSE NULL END
|
2023-02-12 23:37:59 -05:00
|
|
|
)::boolean AS require_reply_approval,
|
|
|
|
MAX(
|
|
|
|
CASE WHEN (name = 'num_auto_bump_daily')
|
2023-02-13 03:07:46 -05:00
|
|
|
THEN NULLIF(value, '') ELSE NULL END
|
2023-02-12 23:37:59 -05:00
|
|
|
)::integer AS num_auto_bump_daily,
|
|
|
|
NOW() AS created_at,
|
|
|
|
NOW() AS updated_at
|
|
|
|
FROM category_custom_fields
|
|
|
|
WHERE name IN (
|
|
|
|
'require_topic_approval',
|
|
|
|
'require_reply_approval',
|
|
|
|
'num_auto_bump_daily'
|
|
|
|
)
|
|
|
|
GROUP BY category_id;
|
|
|
|
SQL
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
execute(<<~SQL)
|
|
|
|
TRUNCATE category_settings;
|
|
|
|
SQL
|
|
|
|
end
|
|
|
|
end
|