From 8a1e487594d034dc3749de84b2df59bfaf5b33fb Mon Sep 17 00:00:00 2001 From: Cess Date: Tue, 5 Mar 2019 19:53:12 +0300 Subject: [PATCH] First timer tag script (#4878) * First timer tag script * migration for attaching first-time-poster * change migration bump version to 5.1 * Update schema.rb.example --- db/migrate/20190301075323_add_first_tag_poster.rb | 14 ++++++++++++++ db/schema.rb.example | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20190301075323_add_first_tag_poster.rb diff --git a/db/migrate/20190301075323_add_first_tag_poster.rb b/db/migrate/20190301075323_add_first_tag_poster.rb new file mode 100644 index 00000000000..c4c59ebea8b --- /dev/null +++ b/db/migrate/20190301075323_add_first_tag_poster.rb @@ -0,0 +1,14 @@ +class AddFirstTagPoster < ActiveRecord::Migration[5.1] + def find_and_update + User.joins(:node).where('node.status = ?', 1).each do |user| + if user.nodes.present? + node = user.nodes.first + node.add_tag('first-time-post', user) + end + end + end + + def up + find_and_update + end +end diff --git a/db/schema.rb.example b/db/schema.rb.example index 9522221882d..771379b4faf 100644 --- a/db/schema.rb.example +++ b/db/schema.rb.example @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_01_04_173959) do +ActiveRecord::Schema.define(version: 2019_03_01_075323) do create_table "answer_selections", force: true do |t| t.integer "user_id"