discourse/db/migrate/20150729150523_migrate_auto_close_posts.rb

24 lines
653 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class MigrateAutoClosePosts < ActiveRecord::Migration[4.2]
2015-07-30 00:20:35 +08:00
def up
I18n.overrides_disabled do
strings = []
%w(days hours lastpost_days lastpost_hours lastpost_minutes).map do |k|
strings += I18n.t("topic_statuses.autoclosed_enabled_#{k}").values.map { |s| s.sub("%{count}", "\\d+") }
end
2015-07-30 00:20:35 +08:00
sql = <<~SQL
UPDATE posts
SET action_code = 'autoclosed.enabled',
post_type = 3
WHERE post_type = 2 AND (
#{strings.map { |s| "raw ~* #{ActiveRecord::Base.connection.quote(s)}" }.join(' OR ')}
)
SQL
2015-07-30 00:20:35 +08:00
execute sql
end
2015-07-30 00:20:35 +08:00
end
end