diff --git a/db/migrate/20150319114233_change_default_content_privacy.rb b/db/migrate/20150319114233_change_default_content_privacy.rb new file mode 100644 index 0000000..4f7010a --- /dev/null +++ b/db/migrate/20150319114233_change_default_content_privacy.rb @@ -0,0 +1,20 @@ +class ChangeDefaultContentPrivacy < ActiveRecord::Migration + def up + ids = execute("SELECT id from profiles WHERE NOT public_profile") + profiles_ids = ids.map { |p| p["id"] } + unless ids.num_tuples.zero? + execute("UPDATE articles SET published = (1>2), show_to_followers = (1=1) + WHERE profile_id IN (#{profiles_ids.join(",")}) AND published") + blocks = Block.includes(:box).where(:boxes => {:owner_type => "Profile", :owner_id => profiles_ids}).where('type != ?', "MainBlock") + blocks.each do |block| + block.display_user = 'followers' + block.save + end + end + change_column :articles, :show_to_followers, :boolean, :default => true + end + + def down + say "this migration can't be reverted" + end +end diff --git a/db/schema.rb b/db/schema.rb index ef67388..42ecf17 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -150,7 +150,7 @@ ActiveRecord::Schema.define(:version => 20150408231524) do t.integer "spam_comments_count", :default => 0 t.integer "author_id" t.integer "created_by_id" - t.boolean "show_to_followers", :default => false + t.boolean "show_to_followers", :default => true end add_index "articles", ["comments_count"], :name => "index_articles_on_comments_count" -- libgit2 0.21.2