From 212c0fd87b56a849a5cd32a7592db95d9d97a880 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 28 Jul 2015 17:35:33 -0400 Subject: [PATCH] Migrate many old moderation action posts to small actions --- config/locales/client.en.yml | 3 +++ ...0150727193414_create_user_field_options.rb | 2 +- ...50728210202_migrate_old_moderator_posts.rb | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20150728210202_migrate_old_moderator_posts.rb diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 47b7dc8cfb3..843c38771bc 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -129,6 +129,9 @@ en: pinned: enabled: 'pinned this topic %{when}' disabled: 'unpinned this topic %{when}' + pinned_globally: + enabled: 'pinned this topic %{when}' + disabled: 'unpinned this topic %{when}' visible: enabled: 'unlisted this topic %{when}' disabled: 'listed this topic %{when}' diff --git a/db/migrate/20150727193414_create_user_field_options.rb b/db/migrate/20150727193414_create_user_field_options.rb index 189025a96e1..64e6e8ed378 100644 --- a/db/migrate/20150727193414_create_user_field_options.rb +++ b/db/migrate/20150727193414_create_user_field_options.rb @@ -1,6 +1,6 @@ class CreateUserFieldOptions < ActiveRecord::Migration def change - create_table :user_field_options do |t| + create_table :user_field_options, force: true do |t| t.references :user_field, null: false t.string :value, null: false t.timestamps diff --git a/db/migrate/20150728210202_migrate_old_moderator_posts.rb b/db/migrate/20150728210202_migrate_old_moderator_posts.rb new file mode 100644 index 00000000000..eeeaf7f9000 --- /dev/null +++ b/db/migrate/20150728210202_migrate_old_moderator_posts.rb @@ -0,0 +1,19 @@ +class MigrateOldModeratorPosts < ActiveRecord::Migration + + def migrate_key(action_code) + text = I18n.t("topic_statuses.#{action_code.gsub('.', '_')}") + + execute "UPDATE posts SET action_code = '#{action_code}', raw = '', cooked = '', post_type = 3 where post_type = 2 AND raw = #{ActiveRecord::Base.connection.quote(text)}" + end + + def up + migrate_key('closed.enabled') + migrate_key('closed.disabled') + migrate_key('archived.enabled') + migrate_key('archived.disabled') + migrate_key('pinned.enabled') + migrate_key('pinned.disabled') + migrate_key('pinned_globally.enabled') + migrate_key('pinned_globally.disabled') + end +end