# frozen_string_literal: true class MigrateAdsenseToExcludeGroups < ActiveRecord::Migration[7.0] def up adsense_display_groups_raw = DB.query_single("SELECT value FROM site_settings WHERE name = 'adsense_display_groups'").first if adsense_display_groups_raw.present? adsense_exclude_groups = case adsense_display_groups_raw when "10" "3|11|12|13|14" when "10|11" "3|12|13|14" when "10|11|12" "3|13|14" when "10|11|12|13" "3|14" when "10|11|12|14" "3" end DB.exec(<<~SQL, setting: adsense_exclude_groups) INSERT INTO site_settings(name, value, data_type, created_at, updated_at) VALUES('adsense_exclude_groups', :setting, '20', NOW(), NOW()) SQL end end def down raise ActiveRecord::IrreversibleMigration end end