Skip to content

Instantly share code, notes, and snippets.

@maxwell
Created January 18, 2012 02:54
Show Gist options
  • Select an option

  • Save maxwell/1630566 to your computer and use it in GitHub Desktop.

Select an option

Save maxwell/1630566 to your computer and use it in GitHub Desktop.
# WARNING: THIS MIGRATION REQUIRES SITE DOWNTIME!
#
# This migration is about moving the 'hidden' bit of a post into the User object.
# Doing this will pave the way to allow us to not have to create unnecessary share_visibilties for public posts, greatly reducing DB index size and RAM usage.
# The migration which will run is: 20120107220942_move_recently_hidden_posts_to_user.rb
#
# Since joindiaspora.com (and mostly likely other pods like diasp.org) have a fair amount of hidden posts, this migration happens in two parts
# First, in a table locking migration (**YOU MUST BE DOWN**, app servers, websockets, and resque workers to run this migration cleanly), we serialize the first
# batch of hidden posts into users. It will take a fair amount per user to do, on jd.com (about 1000 hidden posts per 5 mintues) so the strategy is to serialize the last
# two weeks of hidden hidden posts while the tables are locked.
#
# (with everything down and not running, after you pull, and bundle) run
# AGAIN TAKE EVERYTHING DOWN WHILE THIS ONE RUNS
RAILS_ENV=production bundle exec rake db:migrate
# Depending on how many hidden share_visibilties are on your pod, grab a coffee.
# Once this migration is complete, you can bring your server back up.
# NOTE: only the last two weeks of hidden posts will be serialized
#
# With your server back up, you can run the following command, while you are still up, to deal with the rest of the hidden_share vis
# YOU CAN RUN THIS WITH YOUR SERVERS UP
RAILS_ENV=production bundle exec rake migrations:copy_hidden_share_visibilities_to_users
# This could take awhile, and you might notice some slow-down while the task it is running, but it shouldn't run for too long.
# For reference, we think this will run on JD.com for about 9-ish hours.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment