From 0fb8fba80dc996e302a6a3cf73fffd6efdf0fc23 Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Tue, 4 Nov 2014 11:44:52 -0600 Subject: [PATCH 01/28] don't rehash the script/ide startup --- script/ide | 1 - 1 file changed, 1 deletion(-) diff --git a/script/ide b/script/ide index 26837333..6ac06c9b 100755 --- a/script/ide +++ b/script/ide @@ -28,7 +28,6 @@ rm -rf tmp/cache bundle check || bundle install bundle clean --force bundle exec spring binstub --all -rbenv rehash # Pre-flight Configuration From 118c24bea2b6dd7d015bb4003305fc9202f94bb7 Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Sat, 13 Sep 2014 20:48:34 +0000 Subject: [PATCH 02/28] :skull: mongodb --- Gemfile | 4 + Gemfile.lock | 23 +++ app/jobs/refresh_user_job.rb | 5 - app/jobs/team_migrator_batch_job.rb | 10 ++ app/jobs/team_migrator_job.rb | 169 ++++++++++++++++++ app/models/concerns/team_migration.rb | 24 +++ app/models/concerns/team_search.rb | 8 + app/models/followed_team.rb | 6 +- app/models/pg_team.rb | 41 +++-- app/models/team.rb | 24 ++- app/models/teams/link.rb | 6 +- app/models/teams/location.rb | 15 +- app/models/teams/member.rb | 32 ++-- app/models/user.rb | 42 ++--- app/models/user_event.rb | 3 +- app/models/users/github/repository.rb | 5 +- app/uploaders/team_uploader.rb | 8 + config/initializers/elasticsearch.rb | 5 + config/initializers/tire.rb | 3 - .../20140823103534_add_migration_fields.rb | 7 + db/migrate/20140823174046_fix_pg_team.rb | 26 +++ db/schema.rb | 65 ++++--- spec/fabricators/pg_team_fabricator.rb | 12 +- spec/fabricators/user_fabricator.rb | 19 +- spec/models/followed_team_spec.rb | 17 ++ spec/models/pg_team_spec.rb | 24 +-- spec/models/team_spec.rb | 4 +- spec/models/teams/link_spec.rb | 3 +- spec/models/teams/location_spec.rb | 5 +- spec/models/teams/member_spec.rb | 19 +- spec/models/user_spec.rb | 19 +- spec/models/users/github/repository_spec.rb | 5 +- 32 files changed, 507 insertions(+), 151 deletions(-) create mode 100644 app/jobs/team_migrator_batch_job.rb create mode 100644 app/jobs/team_migrator_job.rb create mode 100644 app/models/concerns/team_migration.rb create mode 100644 app/models/concerns/team_search.rb create mode 100644 app/uploaders/team_uploader.rb create mode 100644 config/initializers/elasticsearch.rb delete mode 100644 config/initializers/tire.rb create mode 100644 db/migrate/20140823103534_add_migration_fields.rb create mode 100644 db/migrate/20140823174046_fix_pg_team.rb create mode 100644 spec/models/followed_team_spec.rb diff --git a/Gemfile b/Gemfile index 348c3732..4d5c9584 100644 --- a/Gemfile +++ b/Gemfile @@ -126,6 +126,9 @@ gem 'sitemap_generator' gem 'tweet-button' gem 'local_time' +gem 'elasticsearch-model' +gem 'elasticsearch-rails' + # DROP BEFORE RAILS 4 # Mongo gem 'mongoid' @@ -182,6 +185,7 @@ group :test do gem 'timecop' gem 'vcr' gem 'webmock', '<1.16' + gem 'stripe-ruby-mock', git: 'https://github.com/rebelidealist/stripe-ruby-mock', branch: 'live-tests' end gem 'airbrake' diff --git a/Gemfile.lock b/Gemfile.lock index a096d27c..81ffdb92 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -106,6 +106,7 @@ GEM rack (>= 0.9.0) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) + blankslate (3.1.3) bson (1.10.2) bson_ext (1.10.2) bson (~> 1.10.2) @@ -176,6 +177,7 @@ GEM httparty (~> 0.10) json curb (0.8.6) + dante (0.2.0) database_cleaner (1.3.0) debug_inspector (0.0.2) debugger-linecache (1.2.0) @@ -195,6 +197,19 @@ GEM execjs eco-source (1.1.0.rc.1) ejs (1.1.1) + elasticsearch (1.0.4) + elasticsearch-api (= 1.0.4) + elasticsearch-transport (= 1.0.4) + elasticsearch-api (1.0.4) + multi_json + elasticsearch-model (0.1.4) + activesupport (> 3) + elasticsearch (> 0.4) + hashie + elasticsearch-rails (0.1.4) + elasticsearch-transport (1.0.4) + faraday + multi_json em-http-request (1.1.2) addressable (>= 2.3.4) cookiejar @@ -330,6 +345,11 @@ GEM jbuilder (2.1.3) activesupport (>= 3.0.0, < 5) multi_json (~> 1.2) + jimson-temp (0.9.5) + blankslate (>= 3.1.2) + multi_json (~> 1.0) + rack (~> 1.4) + rest-client (~> 1.0) journey (1.0.4) jquery-rails (2.0.3) railties (>= 3.1.0, < 5.0) @@ -758,6 +778,8 @@ DEPENDENCIES createsend database_cleaner dotenv-rails + elasticsearch-model + elasticsearch-rails ember-rails! fabrication-rails faraday (~> 0.8.1) @@ -844,6 +866,7 @@ DEPENDENCIES spring-commands-rspec squeel (= 1.0.1) stripe! + stripe-ruby-mock! strong_parameters syntax timecop diff --git a/app/jobs/refresh_user_job.rb b/app/jobs/refresh_user_job.rb index 2db6b4cd..ec3be88c 100644 --- a/app/jobs/refresh_user_job.rb +++ b/app/jobs/refresh_user_job.rb @@ -7,10 +7,6 @@ def perform(user_id, full=false) user = User.find(user_id) - if user.github_id - user.destroy_github_cache - end - return if !full && user.last_refresh_at > 3.days.ago begin @@ -21,7 +17,6 @@ def perform(user_id, full=false) user.calculate_score! ensure user.touch(:last_refresh_at) - user.destroy_github_cache end end end diff --git a/app/jobs/team_migrator_batch_job.rb b/app/jobs/team_migrator_batch_job.rb new file mode 100644 index 00000000..3a9bd206 --- /dev/null +++ b/app/jobs/team_migrator_batch_job.rb @@ -0,0 +1,10 @@ +#TODO DELETE ME +class TeamMigratorBatchJob + include Sidekiq::Worker + + def perform + Team.each do |team| + TeamMigratorJob.perform_async(team.id.to_s) + end + end +end diff --git a/app/jobs/team_migrator_job.rb b/app/jobs/team_migrator_job.rb new file mode 100644 index 00000000..8eb207d9 --- /dev/null +++ b/app/jobs/team_migrator_job.rb @@ -0,0 +1,169 @@ +#TODO DELETE ME +class TeamMigratorJob + include Sidekiq::Worker + + sidekiq_options backtrace: true + + def perform(id) + team = Team.find(id) + if pgteam = find_or_initialize_team(id, team) + extract_account(pgteam, team) + + extract_locations(pgteam, team) + extract_links(pgteam, team) + add_members(pgteam) + add_jobs(pgteam) + convert_followers(pgteam) + add_pending_requests(pgteam, team) + end + end + + + private + + def find_or_initialize_team(id, team) + begin + PgTeam.find_or_initialize_by_mongo_id(id) do |pgteam| + pgteam.name = team.name + pgteam.slug = team.slug + pgteam.created_at = team.created_at + pgteam.updated_at = team.updated_at + pgteam.website = team.website + pgteam.about = team.about + pgteam.total = team.total + pgteam.size = team.size + pgteam.mean = team.mean + pgteam.median = team.median + pgteam.score = team.score + pgteam.twitter = team.twitter + pgteam.facebook = team.facebook + pgteam.premium = team.premium + pgteam.analytics = team.analytics + pgteam.valid_jobs = team.valid_jobs + pgteam.hide_from_featured = team.hide_from_featured + pgteam.preview_code = team.preview_code + pgteam.youtube_url = team.youtube_url + pgteam.github = team.github + pgteam.highlight_tags = team.highlight_tags + pgteam.branding = team.branding + pgteam.headline = team.headline + pgteam.big_quote = team.big_quote + pgteam.big_image = team.big_image + pgteam.featured_banner_image = team.featured_banner_image + pgteam.benefit_name_1 = team.benefit_name_1 + pgteam.benefit_description_1 = team.benefit_description_1 + pgteam.benefit_name_2 = team.benefit_name_2 + pgteam.benefit_description_2 = team.benefit_description_2 + pgteam.benefit_name_3 = team.benefit_name_3 + pgteam.benefit_description_3 = team.benefit_description_3 + pgteam.reason_name_1 = team.reason_name_1 + pgteam.reason_description_1 = team.reason_description_1 + pgteam.reason_name_2 = team.reason_name_2 + pgteam.reason_description_2 = team.reason_description_2 + pgteam.reason_name_3 = team.reason_name_3 + pgteam.reason_description_3 = team.reason_description_3 + pgteam.why_work_image = team.why_work_image + pgteam.organization_way = team.organization_way + pgteam.organization_way_name = team.organization_way_name + pgteam.organization_way_photo = team.organization_way_photo + pgteam.office_photos = team.office_photos + pgteam.upcoming_events = team.upcoming_events + pgteam.featured_links_title = team.featured_links_title + pgteam.blog_feed = team.blog_feed + pgteam.our_challenge = team.our_challenge + pgteam.your_impact = team.your_impact + pgteam.interview_steps = team.interview_steps + pgteam.hiring_tagline = team.hiring_tagline + pgteam.link_to_careers_page = team.link_to_careers_page + # pgteam.avatar = team.avatar + pgteam.achievement_count = team.achievement_count + pgteam.endorsement_count = team.endorsement_count + pgteam.invited_emails = team.invited_emails + pgteam.pending_join_requests = team.pending_join_requests + pgteam.upgraded_at = team.upgraded_at + pgteam.paid_job_posts = team.paid_job_posts + pgteam.monthly_subscription = team.monthly_subscription + pgteam.stack_list = team.stack_list + pgteam.number_of_jobs_to_show = team.number_of_jobs_to_show + pgteam.location = team.location + pgteam.country_id = team.country_id + pgteam.github_organization_name = team.github_organization_name + pgteam.save! + + end + rescue ActiveRecord::RecordInvalid + false + end + end + + def extract_account(pgteam, team) + return unless account = team.account + return if pgteam.account + begin + pgaccount = pgteam.build_account( + stripe_card_token: account.stripe_card_token, + stripe_customer_token: account.stripe_customer_token, + admin_id: account.admin_id + ) + pgaccount.plans << Plan.where(id: account.plan_ids) + pgaccount.save! + rescue ActiveRecord::RecordInvalid => e + # @just3ws, uncomment the following line and get all ID of the corrupted accounts + # raise e + false + end + + end + + def extract_locations(pgteam, team) + locations = team.team_locations + return unless locations.any? + return if pgteam.locations.any? + locations.each do |location| + pgteam.locations.create! name: location.name, + description: location.description, + address: location.address, + city: location.city, + state_code: location.state_code, + country: location.country + + end + end + + def extract_links(pgteam, team) + links = team.featured_links + return if links.empty? + return if pgteam.links.any? + links.each do |link| + pgteam.links.create! name: link.name, + url: link.url + end + end + + def add_members(pgteam) + users = User.where(team_document_id: pgteam.mongo_id) + users.each do |user| + pgteam.members.create! user: user, state: 'active' + end + users.update_all(team_id: pgteam.id) + end + + def add_jobs(pgteam) + Opportunity.where(team_document_id: pgteam.mongo_id).update_all(team_id: pgteam.id) + end + + def convert_followers(pgteam) + FollowedTeam.where(team_document_id: pgteam.mongo_id).update_all(team_id: pgteam.id) + end + + def add_pending_requests(pgteam, team) + pending_team_members = team.pending_team_members + return if pending_team_members.empty? + pending_team_members.each do |pending_team_member| + user = User.find pending_team_member.user_id + pgteam.members.create user: user, + created_at: pending_team_member.created_at, + updated_at: pending_team_member.updated_at + end + end +end diff --git a/app/models/concerns/team_migration.rb b/app/models/concerns/team_migration.rb new file mode 100644 index 00000000..8fd577ba --- /dev/null +++ b/app/models/concerns/team_migration.rb @@ -0,0 +1,24 @@ +module TeamMigration + extend ActiveSupport::Concern + + included do + scope :zombies, -> { where(state: 'zombie') } + end + + module ClassMethods + + def the_walking_deads + active_teams_ids = Teams::Member.pluck(:team_id).uniq + where('id not in (?)', active_teams_ids) + end + + def mark_the_walking_deads! + the_walking_deads.update_all(state: 'zombie') + end + + def kill_zombies! + zombies.destroy_all + end + + end +end diff --git a/app/models/concerns/team_search.rb b/app/models/concerns/team_search.rb new file mode 100644 index 00000000..cbbf981e --- /dev/null +++ b/app/models/concerns/team_search.rb @@ -0,0 +1,8 @@ +module TeamSearch + extend ActiveSupport::Concern + included do + include Elasticsearch::Model + + #TODO + end +end diff --git a/app/models/followed_team.rb b/app/models/followed_team.rb index d0b1c96b..8801e846 100644 --- a/app/models/followed_team.rb +++ b/app/models/followed_team.rb @@ -1,13 +1,15 @@ class FollowedTeam < ActiveRecord::Base + belongs_to :team, class_name: 'PgTeam' + belongs_to :user end # == Schema Information -# Schema version: 20140728214411 # # Table name: followed_teams # # id :integer not null, primary key # user_id :integer # team_document_id :string(255) -# created_at :datetime default(2014-02-20 22:39:11 UTC) +# created_at :datetime default(2012-03-12 21:01:09 UTC) +# team_id :integer # diff --git a/app/models/pg_team.rb b/app/models/pg_team.rb index 36cf4bc9..e19f9f65 100644 --- a/app/models/pg_team.rb +++ b/app/models/pg_team.rb @@ -1,24 +1,33 @@ #Rename to Team when Mongodb is dropped class PgTeam < ActiveRecord::Base + include TeamSearch + include TeamMigration + self.table_name = 'teams' #TODO add inverse_of - has_one :account, class_name: 'Teams::Account', foreign_key: 'team_id', dependent: :destroy + has_one :account, class_name: 'Teams::Account', foreign_key: 'team_id', dependent: :delete - has_many :members, class_name: 'Teams::Member', foreign_key: 'team_id', dependent: :destroy - has_many :links, class_name: 'Teams::Link', foreign_key: 'team_id', dependent: :destroy - has_many :locations, class_name: 'Teams::Location', foreign_key: 'team_id', dependent: :destroy + has_many :members, class_name: 'Teams::Member', foreign_key: 'team_id', dependent: :delete_all + has_many :links, class_name: 'Teams::Link', foreign_key: 'team_id', dependent: :delete_all + has_many :locations, class_name: 'Teams::Location', foreign_key: 'team_id', dependent: :delete_all has_many :jobs, class_name: 'Opportunity', foreign_key: 'team_id', dependent: :destroy - before_validation :create_slug! + has_many :follows , class_name: 'FollowedTeam', foreign_key: 'team_id', dependent: :destroy + has_many :followers, through: :follows + + accepts_nested_attributes_for :locations, :links, allow_destroy: true, reject_if: :all_blank - validates_uniqueness_of :slug + scope :featured, ->{ where(premium: true, valid_jobs: true, hide_from_featured: false) } + mount_uploader :avatar, TeamUploader + + before_validation :create_slug! - private + validates :slug, uniqueness: true, presence: true - def create_slug! - self.slug = name.parameterize - end + private def create_slug! + self.slug = name.parameterize + end end # @@ -69,20 +78,15 @@ def create_slug! # organization_way :text # organization_way_name :text # organization_way_photo :text -# office_photos :string(255) default("{}") -# upcoming_events :string(255) default("{}") # featured_links_title :string(255) # blog_feed :text # our_challenge :text # your_impact :text -# interview_steps :string(255) default("{}") # hiring_tagline :text # link_to_careers_page :text # avatar :string(255) # achievement_count :integer default(0) # endorsement_count :integer default(0) -# invited_emails :string(255) default("{}") -# pending_join_requests :string(255) default("{}") # upgraded_at :datetime # paid_job_posts :integer default(0) # monthly_subscription :boolean default(FALSE) @@ -93,4 +97,11 @@ def create_slug! # name :string(255) # github_organization_name :string(255) # team_size :integer +# mongo_id :string(255) +# office_photos :string(255) default([]), is an Array +# upcoming_events :text default([]), is an Array +# interview_steps :text default([]), is an Array +# invited_emails :string(255) default([]), is an Array +# pending_join_requests :string(255) default([]), is an Array +# state :string(255) default("active") # diff --git a/app/models/team.rb b/app/models/team.rb index 18acab81..f1de3ced 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -73,7 +73,6 @@ class Team field :upcoming_events, type: Array, default: [] #just stubbed field :featured_links_title - embeds_many :featured_links, class_name: TeamLink.name field :blog_feed field :our_challenge @@ -96,7 +95,7 @@ class Team field :pending_join_requests, type: Array, default: [] - embeds_one :account + field :upgraded_at field :paid_job_posts, default: 0 field :monthly_subscription, default: false @@ -110,9 +109,13 @@ class Team index({ name: 1 }, { unique: true }) index({ slug: 1 }, { unique: true }) - embeds_many :pending_team_members, class_name: 'TeamMember' + + #migrated embeds_many :team_locations + embeds_one :account + embeds_many :featured_links, class_name: TeamLink.name + embeds_many :pending_team_members, class_name: 'TeamMember' accepts_nested_attributes_for :team_locations, :featured_links, allow_destroy: true, reject_if: :all_blank @@ -126,6 +129,7 @@ class Team after_destroy :reindex_search after_destroy :remove_dependencies + #migrated scope :featured, ->{ where(premium: true, valid_jobs: true, hide_from_featured: false) } class << self @@ -461,18 +465,27 @@ def membership(user) team_members.where(user_id: id_of(user)).first end + #migrated + # .members.top def top_team_member sorted_team_members.first end + #migrated + # .members.top(2) def top_two_team_members sorted_team_members[0...2] || [] end + + #migrated + # .members.top(3) def top_three_team_members sorted_team_members[0...3] || [] end + #migrated + # .members.sorted def sorted_team_members @sorted_team_members = User.where(team_document_id: self.id.to_s).order('score_cache DESC') end @@ -900,4 +913,9 @@ def create_slug! self.slug = self.class.slugify(name) end + after_create do + #'create_pg_team' + TeamMigratorJob.new.perform(self.id.to_s) + end + end diff --git a/app/models/teams/link.rb b/app/models/teams/link.rb index 4e6e6d64..fa826a2f 100644 --- a/app/models/teams/link.rb +++ b/app/models/teams/link.rb @@ -2,16 +2,18 @@ class Teams::Link < ActiveRecord::Base belongs_to :team, class_name: 'PgTeam', foreign_key: 'team_id', touch: true + + validates :url, presence: true + validates_uniqueness_of :url, scope: :team_id end # == Schema Information -# Schema version: 20140728214411 # # Table name: teams_links # # id :integer not null, primary key # name :string(255) -# url :string(255) +# url :text # team_id :integer not null # created_at :datetime not null # updated_at :datetime not null diff --git a/app/models/teams/location.rb b/app/models/teams/location.rb index 64bcee99..da276a12 100644 --- a/app/models/teams/location.rb +++ b/app/models/teams/location.rb @@ -3,17 +3,26 @@ class Teams::Location < ActiveRecord::Base belongs_to :team, class_name: 'PgTeam', foreign_key: 'team_id', touch: true + + # geocoded_by :address do |obj, results| + # if geo = results.first and obj.address.downcase.include?(geo.city.try(:downcase) || "") + # obj.city = geo.city + # obj.state_code = geo.state_code + # obj.country = geo.country + # end + # end + # + # after_validation :geocode, if: lambda { |team_location| team_location.city.nil? } end # == Schema Information -# Schema version: 20140728214411 # # Table name: teams_locations # # id :integer not null, primary key # name :string(255) -# description :string(255) -# address :string(255) +# description :text +# address :text # city :string(255) # state_code :string(255) # country :string(255) diff --git a/app/models/teams/member.rb b/app/models/teams/member.rb index ea61c8a8..77edb7f0 100644 --- a/app/models/teams/member.rb +++ b/app/models/teams/member.rb @@ -1,26 +1,26 @@ class Teams::Member < ActiveRecord::Base belongs_to :team, class_name: 'PgTeam', - foreign_key: 'team_id', - counter_cache: :team_size, - touch: true + foreign_key: 'team_id', + counter_cache: :team_size, + touch: true belongs_to :user + + validates_uniqueness_of :user_id, scope: :team_id + + scope :active, -> { where(state: 'active') } + scope :pending, -> { where(state: 'pending') } + scope :sorted, -> { active.joins(:user).order('users.score_cache DESC') } + scope :top, ->(limit= 1) { sorted.limit(limit) } end # == Schema Information -# Schema version: 20140728214411 # # Table name: teams_members # -# id :integer not null, primary key -# team_id :integer not null -# user_id :integer not null -# created_at :datetime not null -# updated_at :datetime not null -# team_size :integer default(0) -# badges_count :integer -# email :string(255) -# inviter_id :integer -# name :string(255) -# thumbnail_url :string(255) -# username :string(255) +# id :integer not null, primary key +# team_id :integer not null +# user_id :integer not null +# created_at :datetime not null +# updated_at :datetime not null +# state :string(255) default("pending") # diff --git a/app/models/user.rb b/app/models/user.rb index d20e28f5..6703e844 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -82,6 +82,8 @@ class User < ActiveRecord::Base has_one :github_profile , class_name: 'Users::Github::Profile', dependent: :destroy has_many :github_repositories, through: :github_profile , source: :repositories + belongs_to :team, class_name: 'PgTeam' + geocoded_by :location, latitude: :lat, longitude: :lng, country: :country, state_code: :state_name # FIXME: Move to background job after_validation :geocode_location, if: :location_changed? unless Rails.env.test? @@ -216,13 +218,6 @@ def team_ids [team_document_id] end - def team - @team ||= team_document_id && Team.find(team_document_id) - rescue Mongoid::Errors::DocumentNotFound - #readonly issue in follows/_user partial from partial iterator - User.connection.execute("UPDATE users set team_document_id = NULL where id = #{self.id}") - @team = nil - end def on_premium_team? team.try(:premium?) || false @@ -622,11 +617,6 @@ def build_repo_followed_activity!(refresh=false) [] end - def destroy_github_cache - GithubRepo.where('owner.github_id' => github_id).destroy if github_id - GithubProfile.where('login' => github).destroy if github - end - def track_user_view!(user) track!("viewed user", user_id: user.id, username: user.username) end @@ -915,12 +905,8 @@ def destroy_badges end end - before_create :make_referral_token - - def make_referral_token - if self.referral_token.nil? - self.referral_token = SecureRandom.hex(8) - end + before_create do + self.referral_token ||= SecureRandom.hex(8) end after_save :refresh_dependencies @@ -974,8 +960,8 @@ def manage_github_orgs # bitbucket :string(255) # codeplex :string(255) # login_count :integer default(0) -# last_request_at :datetime default(2014-07-17 13:10:04 UTC) -# achievements_checked_at :datetime default(1914-02-20 22:39:10 UTC) +# last_request_at :datetime default(2014-07-23 03:14:36 UTC) +# achievements_checked_at :datetime default(1911-08-12 21:49:21 UTC) # claim_code :text # github_id :integer # country :string(255) @@ -985,11 +971,11 @@ def manage_github_orgs # lng :float # http_counter :integer # github_token :string(255) -# twitter_checked_at :datetime default(1914-02-20 22:39:10 UTC) +# twitter_checked_at :datetime default(1911-08-12 21:49:21 UTC) # title :string(255) # company :string(255) # blog :string(255) -# github :string(255) +# github :citext # forrst :string(255) # dribbble :string(255) # specialties :text @@ -1015,7 +1001,6 @@ def manage_github_orgs # referred_by :string(255) # about :text # joined_github_on :date -# joined_twitter_on :date # avatar :string(255) # banner :string(255) # remind_to_invite_team_members :datetime @@ -1023,6 +1008,7 @@ def manage_github_orgs # tracking_code :string(255) # utm_campaign :string(255) # score_cache :float default(0.0) +# gender :string(255) # notify_on_follow :boolean default(TRUE) # api_key :string(255) # remind_to_create_team :datetime @@ -1033,6 +1019,12 @@ def manage_github_orgs # team_responsibilities :text # team_avatar :string(255) # team_banner :string(255) +# stat_name_1 :string(255) +# stat_number_1 :string(255) +# stat_name_2 :string(255) +# stat_number_2 :string(255) +# stat_name_3 :string(255) +# stat_number_3 :string(255) # ip_lat :float # ip_lng :float # penalty :float default(0.0) @@ -1041,11 +1033,15 @@ def manage_github_orgs # resume :string(255) # sourceforge :string(255) # google_code :string(255) +# sales_rep :boolean default(FALSE) # visits :string(255) default("") # visit_frequency :string(255) default("rarely") +# pitchbox_id :integer # join_badge_orgs :boolean default(FALSE) +# use_social_for_pitchbox :boolean default(FALSE) # last_asm_email_at :datetime # banned_at :datetime # last_ip :string(255) # last_ua :string(255) +# team_id :integer # diff --git a/app/models/user_event.rb b/app/models/user_event.rb index 56bdf29d..33524fb4 100644 --- a/app/models/user_event.rb +++ b/app/models/user_event.rb @@ -4,7 +4,6 @@ class UserEvent < ActiveRecord::Base end # == Schema Information -# Schema version: 20140728214411 # # Table name: user_events # @@ -12,5 +11,5 @@ class UserEvent < ActiveRecord::Base # user_id :integer # name :string(255) # data :text -# created_at :datetime default(2014-02-20 22:39:11 UTC) +# created_at :datetime default(2012-03-12 21:01:10 UTC) # diff --git a/app/models/users/github/repository.rb b/app/models/users/github/repository.rb index 73c6000f..3c5d5857 100644 --- a/app/models/users/github/repository.rb +++ b/app/models/users/github/repository.rb @@ -6,7 +6,6 @@ class Users::Github::Repository < ActiveRecord::Base end # == Schema Information -# Schema version: 20140728214411 # # Table name: users_github_repositories # @@ -17,9 +16,9 @@ class Users::Github::Repository < ActiveRecord::Base # homepage :string(255) # fork :boolean default(FALSE) # forks_count :integer default(0) -# forks_count_updated_at :datetime default(2014-07-18 23:03:00 UTC) +# forks_count_updated_at :datetime default(2014-07-23 03:14:37 UTC) # stargazers_count :integer default(0) -# stargazers_count_updated_at :datetime default(2014-07-18 23:03:00 UTC) +# stargazers_count_updated_at :datetime default(2014-07-23 03:14:37 UTC) # language :string(255) # followers_count :integer default(0), not null # github_id :integer not null diff --git a/app/uploaders/team_uploader.rb b/app/uploaders/team_uploader.rb new file mode 100644 index 00000000..a2b1c214 --- /dev/null +++ b/app/uploaders/team_uploader.rb @@ -0,0 +1,8 @@ +class TeamUploader < CoderwallUploader + + process resize_and_pad: [100, 100] + + def default_url + ActionController::Base.helpers.asset_path 'team-avatar.png' + end +end diff --git a/config/initializers/elasticsearch.rb b/config/initializers/elasticsearch.rb new file mode 100644 index 00000000..e181d660 --- /dev/null +++ b/config/initializers/elasticsearch.rb @@ -0,0 +1,5 @@ +Tire.configure do + url ENV['ELASTICSEARCH_URL'] +end + +Elasticsearch::Model.client = Elasticsearch::Client.new url: ENV['ELASTICSEARCH_URL'] diff --git a/config/initializers/tire.rb b/config/initializers/tire.rb deleted file mode 100644 index b5967957..00000000 --- a/config/initializers/tire.rb +++ /dev/null @@ -1,3 +0,0 @@ -Tire.configure do - url ENV['ELASTICSEARCH_URL'] -end diff --git a/db/migrate/20140823103534_add_migration_fields.rb b/db/migrate/20140823103534_add_migration_fields.rb new file mode 100644 index 00000000..db21cb30 --- /dev/null +++ b/db/migrate/20140823103534_add_migration_fields.rb @@ -0,0 +1,7 @@ +class AddMigrationFields < ActiveRecord::Migration + def up + add_column :teams, :mongo_id, :string, unique: true + add_column :teams_members, :state, :string, unique: true , default: 'pending' + add_column :users, :team_id, :integer, index: true + end +end diff --git a/db/migrate/20140823174046_fix_pg_team.rb b/db/migrate/20140823174046_fix_pg_team.rb new file mode 100644 index 00000000..1262b1e9 --- /dev/null +++ b/db/migrate/20140823174046_fix_pg_team.rb @@ -0,0 +1,26 @@ +class FixPgTeam < ActiveRecord::Migration + def up + remove_column :teams, :office_photos + add_column :teams, :office_photos, :string, array: true, default: [] + remove_column :teams, :upcoming_events + add_column :teams, :upcoming_events, :text, array: true, default: [] + remove_column :teams, :interview_steps + add_column :teams, :interview_steps, :text, array: true, default: [] + remove_column :teams, :invited_emails + add_column :teams, :invited_emails, :string, array: true, default: [] + remove_column :teams, :pending_join_requests + add_column :teams, :pending_join_requests, :string, array: true, default: [] + add_column :teams, :state, :string, default: 'active' + change_column :teams_locations, :description, :text + change_column :teams_locations, :address, :text + change_column :teams_links, :url, :text + add_column :followed_teams, :team_id, :integer, index: true + remove_column :teams_members, :team_size + remove_column :teams_members, :badges_count + remove_column :teams_members, :email + remove_column :teams_members, :inviter_id + remove_column :teams_members, :name + remove_column :teams_members, :thumbnail_url + remove_column :teams_members, :username + end +end diff --git a/db/schema.rb b/db/schema.rb index e460520d..65743c62 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -14,6 +14,7 @@ ActiveRecord::Schema.define(:version => 20141015182230) do add_extension "citext" + add_extension "hstore" create_table "alias_tags", :id => false, :force => true do |t| t.integer "tag_id" @@ -104,7 +105,8 @@ create_table "followed_teams", :force => true do |t| t.integer "user_id" t.string "team_document_id" - t.datetime "created_at", :default => '2014-02-20 22:39:11' + t.datetime "created_at", :default => '2012-03-12 21:01:09' + t.integer "team_id" end add_index "followed_teams", ["team_document_id"], :name => "index_followed_teams_on_team_document_id" @@ -355,8 +357,8 @@ end create_table "teams", :force => true do |t| - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "website" t.text "about" t.integer "total", :default => 0 @@ -396,20 +398,15 @@ t.text "organization_way" t.text "organization_way_name" t.text "organization_way_photo" - t.string "office_photos", :default => [], :array => true - t.string "upcoming_events", :default => [], :array => true t.string "featured_links_title" t.text "blog_feed" t.text "our_challenge" t.text "your_impact" - t.string "interview_steps", :default => [], :array => true t.text "hiring_tagline" t.text "link_to_careers_page" t.string "avatar" t.integer "achievement_count", :default => 0 t.integer "endorsement_count", :default => 0 - t.string "invited_emails", :default => [], :array => true - t.string "pending_join_requests", :default => [], :array => true t.datetime "upgraded_at" t.integer "paid_job_posts", :default => 0 t.boolean "monthly_subscription", :default => false @@ -420,6 +417,13 @@ t.string "name" t.string "github_organization_name" t.integer "team_size" + t.string "mongo_id" + t.string "office_photos", :default => [], :array => true + t.text "upcoming_events", :default => [], :array => true + t.text "interview_steps", :default => [], :array => true + t.string "invited_emails", :default => [], :array => true + t.string "pending_join_requests", :default => [], :array => true + t.string "state", :default => "active" end create_table "teams_account_plans", :id => false, :force => true do |t| @@ -439,7 +443,7 @@ create_table "teams_links", :force => true do |t| t.string "name" - t.string "url" + t.text "url" t.integer "team_id", :null => false t.datetime "created_at", :null => false t.datetime "updated_at", :null => false @@ -447,8 +451,8 @@ create_table "teams_locations", :force => true do |t| t.string "name" - t.string "description" - t.string "address" + t.text "description" + t.text "address" t.string "city" t.string "state_code" t.string "country" @@ -458,17 +462,11 @@ end create_table "teams_members", :force => true do |t| - t.integer "team_id", :null => false - t.integer "user_id", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.integer "team_size", :default => 0 - t.integer "badges_count" - t.string "email" - t.integer "inviter_id" - t.string "name" - t.string "thumbnail_url" - t.string "username" + t.integer "team_id", :null => false + t.integer "user_id", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.string "state", :default => "pending" end create_table "tokens", :force => true do |t| @@ -486,7 +484,7 @@ t.integer "user_id" t.string "name" t.text "data" - t.datetime "created_at", :default => '2014-02-20 22:39:11' + t.datetime "created_at", :default => '2012-03-12 21:01:10' end create_table "users", :force => true do |t| @@ -507,8 +505,8 @@ t.string "bitbucket" t.string "codeplex" t.integer "login_count", :default => 0 - t.datetime "last_request_at", :default => '2014-07-17 13:10:04' - t.datetime "achievements_checked_at", :default => '1914-02-20 22:39:10' + t.datetime "last_request_at", :default => '2014-07-23 03:14:36' + t.datetime "achievements_checked_at", :default => '1911-08-12 21:49:21' t.text "claim_code" t.integer "github_id" t.string "country" @@ -518,7 +516,7 @@ t.float "lng" t.integer "http_counter" t.string "github_token" - t.datetime "twitter_checked_at", :default => '1914-02-20 22:39:10' + t.datetime "twitter_checked_at", :default => '1911-08-12 21:49:21' t.string "title" t.string "company" t.string "blog" @@ -555,6 +553,7 @@ t.string "tracking_code" t.string "utm_campaign" t.float "score_cache", :default => 0.0 + t.string "gender" t.boolean "notify_on_follow", :default => true t.string "api_key" t.datetime "remind_to_create_team" @@ -565,6 +564,12 @@ t.text "team_responsibilities" t.string "team_avatar" t.string "team_banner" + t.string "stat_name_1" + t.string "stat_number_1" + t.string "stat_name_2" + t.string "stat_number_2" + t.string "stat_name_3" + t.string "stat_number_3" t.float "ip_lat" t.float "ip_lng" t.float "penalty", :default => 0.0 @@ -573,13 +578,17 @@ t.string "resume" t.string "sourceforge" t.string "google_code" + t.boolean "sales_rep", :default => false t.string "visits", :default => "" t.string "visit_frequency", :default => "rarely" + t.integer "pitchbox_id" t.boolean "join_badge_orgs", :default => false + t.boolean "use_social_for_pitchbox", :default => false t.datetime "last_asm_email_at" t.datetime "banned_at" t.string "last_ip" t.string "last_ua" + t.integer "team_id" end add_index "users", ["linkedin_id"], :name => "index_users_on_linkedin_id", :unique => true @@ -639,9 +648,9 @@ t.string "homepage" t.boolean "fork", :default => false t.integer "forks_count", :default => 0 - t.datetime "forks_count_updated_at", :default => '2014-07-18 23:03:00' + t.datetime "forks_count_updated_at", :default => '2014-07-23 03:14:37' t.integer "stargazers_count", :default => 0 - t.datetime "stargazers_count_updated_at", :default => '2014-07-18 23:03:00' + t.datetime "stargazers_count_updated_at", :default => '2014-07-23 03:14:37' t.string "language" t.integer "followers_count", :default => 0, :null => false t.integer "github_id", :null => false diff --git a/spec/fabricators/pg_team_fabricator.rb b/spec/fabricators/pg_team_fabricator.rb index 436b95f4..260ae47b 100644 --- a/spec/fabricators/pg_team_fabricator.rb +++ b/spec/fabricators/pg_team_fabricator.rb @@ -47,20 +47,15 @@ # organization_way :text # organization_way_name :text # organization_way_photo :text -# office_photos :string(255) default("{}") -# upcoming_events :string(255) default("{}") # featured_links_title :string(255) # blog_feed :text # our_challenge :text # your_impact :text -# interview_steps :string(255) default("{}") # hiring_tagline :text # link_to_careers_page :text # avatar :string(255) # achievement_count :integer default(0) # endorsement_count :integer default(0) -# invited_emails :string(255) default("{}") -# pending_join_requests :string(255) default("{}") # upgraded_at :datetime # paid_job_posts :integer default(0) # monthly_subscription :boolean default(FALSE) @@ -71,4 +66,11 @@ # name :string(255) # github_organization_name :string(255) # team_size :integer +# mongo_id :string(255) +# office_photos :string(255) default([]), is an Array +# upcoming_events :text default([]), is an Array +# interview_steps :text default([]), is an Array +# invited_emails :string(255) default([]), is an Array +# pending_join_requests :string(255) default([]), is an Array +# state :string(255) default("active") # diff --git a/spec/fabricators/user_fabricator.rb b/spec/fabricators/user_fabricator.rb index 41cb4d3b..1c838021 100644 --- a/spec/fabricators/user_fabricator.rb +++ b/spec/fabricators/user_fabricator.rb @@ -41,8 +41,8 @@ # bitbucket :string(255) # codeplex :string(255) # login_count :integer default(0) -# last_request_at :datetime default(2014-07-17 13:10:04 UTC) -# achievements_checked_at :datetime default(1914-02-20 22:39:10 UTC) +# last_request_at :datetime default(2014-07-23 03:14:36 UTC) +# achievements_checked_at :datetime default(1911-08-12 21:49:21 UTC) # claim_code :text # github_id :integer # country :string(255) @@ -52,11 +52,11 @@ # lng :float # http_counter :integer # github_token :string(255) -# twitter_checked_at :datetime default(1914-02-20 22:39:10 UTC) +# twitter_checked_at :datetime default(1911-08-12 21:49:21 UTC) # title :string(255) # company :string(255) # blog :string(255) -# github :string(255) +# github :citext # forrst :string(255) # dribbble :string(255) # specialties :text @@ -89,6 +89,7 @@ # tracking_code :string(255) # utm_campaign :string(255) # score_cache :float default(0.0) +# gender :string(255) # notify_on_follow :boolean default(TRUE) # api_key :string(255) # remind_to_create_team :datetime @@ -99,6 +100,12 @@ # team_responsibilities :text # team_avatar :string(255) # team_banner :string(255) +# stat_name_1 :string(255) +# stat_number_1 :string(255) +# stat_name_2 :string(255) +# stat_number_2 :string(255) +# stat_name_3 :string(255) +# stat_number_3 :string(255) # ip_lat :float # ip_lng :float # penalty :float default(0.0) @@ -107,11 +114,15 @@ # resume :string(255) # sourceforge :string(255) # google_code :string(255) +# sales_rep :boolean default(FALSE) # visits :string(255) default("") # visit_frequency :string(255) default("rarely") +# pitchbox_id :integer # join_badge_orgs :boolean default(FALSE) +# use_social_for_pitchbox :boolean default(FALSE) # last_asm_email_at :datetime # banned_at :datetime # last_ip :string(255) # last_ua :string(255) +# team_id :integer # diff --git a/spec/models/followed_team_spec.rb b/spec/models/followed_team_spec.rb new file mode 100644 index 00000000..cc7d41d4 --- /dev/null +++ b/spec/models/followed_team_spec.rb @@ -0,0 +1,17 @@ +# == Schema Information +# +# Table name: followed_teams +# +# id :integer not null, primary key +# user_id :integer +# team_document_id :string(255) +# created_at :datetime default(2012-03-12 21:01:09 UTC) +# team_id :integer +# + +require 'rails_helper' + +RSpec.describe FollowedTeam, :type => :model do + it {is_expected.to belong_to(:team)} + it {is_expected.to belong_to(:user)} +end diff --git a/spec/models/pg_team_spec.rb b/spec/models/pg_team_spec.rb index e602c575..a1f079fe 100644 --- a/spec/models/pg_team_spec.rb +++ b/spec/models/pg_team_spec.rb @@ -1,12 +1,14 @@ require 'rails_helper' RSpec.describe PgTeam, :type => :model do - it {is_expected.to have_one :account} + it { is_expected.to have_one :account } + + it { is_expected.to have_many :locations } + it { is_expected.to have_many :links } + it { is_expected.to have_many :members } + it { is_expected.to have_many :jobs } + it { is_expected.to have_many :followers } - it {is_expected.to have_many :locations} - it {is_expected.to have_many :links} - it {is_expected.to have_many :members} - it {is_expected.to have_many :jobs} end # == Schema Information @@ -55,20 +57,15 @@ # organization_way :text # organization_way_name :text # organization_way_photo :text -# office_photos :string(255) default("{}") -# upcoming_events :string(255) default("{}") # featured_links_title :string(255) # blog_feed :text # our_challenge :text # your_impact :text -# interview_steps :string(255) default("{}") # hiring_tagline :text # link_to_careers_page :text # avatar :string(255) # achievement_count :integer default(0) # endorsement_count :integer default(0) -# invited_emails :string(255) default("{}") -# pending_join_requests :string(255) default("{}") # upgraded_at :datetime # paid_job_posts :integer default(0) # monthly_subscription :boolean default(FALSE) @@ -79,4 +76,11 @@ # name :string(255) # github_organization_name :string(255) # team_size :integer +# mongo_id :string(255) +# office_photos :string(255) default([]), is an Array +# upcoming_events :text default([]), is an Array +# interview_steps :text default([]), is an Array +# invited_emails :string(255) default([]), is an Array +# pending_join_requests :string(255) default([]), is an Array +# state :string(255) default("active") # diff --git a/spec/models/team_spec.rb b/spec/models/team_spec.rb index 5174ce4c..4eedb3c7 100644 --- a/spec/models/team_spec.rb +++ b/spec/models/team_spec.rb @@ -26,10 +26,10 @@ end it 'should indicate if team member has referral' do - member_that_invited_user = Fabricate(:user, referral_token: 'asdfasdf') + member_that_invited_user = Fabricate(:user) team.add_user(member_that_invited_user) - expect(team.has_user_with_referral_token?('asdfasdf')).to eq(true) + expect(team.has_user_with_referral_token?(member_that_invited_user.referral_token)).to eq(true) expect(team.has_user_with_referral_token?("something else")).to eq(false) end diff --git a/spec/models/teams/link_spec.rb b/spec/models/teams/link_spec.rb index 7f2a1583..cb0eb9d0 100644 --- a/spec/models/teams/link_spec.rb +++ b/spec/models/teams/link_spec.rb @@ -5,13 +5,12 @@ end # == Schema Information -# Schema version: 20140728214411 # # Table name: teams_links # # id :integer not null, primary key # name :string(255) -# url :string(255) +# url :text # team_id :integer not null # created_at :datetime not null # updated_at :datetime not null diff --git a/spec/models/teams/location_spec.rb b/spec/models/teams/location_spec.rb index 2b992ff1..acb8a835 100644 --- a/spec/models/teams/location_spec.rb +++ b/spec/models/teams/location_spec.rb @@ -5,14 +5,13 @@ end # == Schema Information -# Schema version: 20140728214411 # # Table name: teams_locations # # id :integer not null, primary key # name :string(255) -# description :string(255) -# address :string(255) +# description :text +# address :text # city :string(255) # state_code :string(255) # country :string(255) diff --git a/spec/models/teams/member_spec.rb b/spec/models/teams/member_spec.rb index 356e2c79..78a259cc 100644 --- a/spec/models/teams/member_spec.rb +++ b/spec/models/teams/member_spec.rb @@ -6,20 +6,13 @@ end # == Schema Information -# Schema version: 20140728214411 # # Table name: teams_members # -# id :integer not null, primary key -# team_id :integer not null -# user_id :integer not null -# created_at :datetime not null -# updated_at :datetime not null -# team_size :integer default(0) -# badges_count :integer -# email :string(255) -# inviter_id :integer -# name :string(255) -# thumbnail_url :string(255) -# username :string(255) +# id :integer not null, primary key +# team_id :integer not null +# user_id :integer not null +# created_at :datetime not null +# updated_at :datetime not null +# state :string(255) default("pending") # diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 99cbc437..953c2ede 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -365,8 +365,8 @@ class AlsoNotaBadge < BadgeBase # bitbucket :string(255) # codeplex :string(255) # login_count :integer default(0) -# last_request_at :datetime default(2014-07-17 13:10:04 UTC) -# achievements_checked_at :datetime default(1914-02-20 22:39:10 UTC) +# last_request_at :datetime default(2014-07-23 03:14:36 UTC) +# achievements_checked_at :datetime default(1911-08-12 21:49:21 UTC) # claim_code :text # github_id :integer # country :string(255) @@ -376,11 +376,11 @@ class AlsoNotaBadge < BadgeBase # lng :float # http_counter :integer # github_token :string(255) -# twitter_checked_at :datetime default(1914-02-20 22:39:10 UTC) +# twitter_checked_at :datetime default(1911-08-12 21:49:21 UTC) # title :string(255) # company :string(255) # blog :string(255) -# github :string(255) +# github :citext # forrst :string(255) # dribbble :string(255) # specialties :text @@ -413,6 +413,7 @@ class AlsoNotaBadge < BadgeBase # tracking_code :string(255) # utm_campaign :string(255) # score_cache :float default(0.0) +# gender :string(255) # notify_on_follow :boolean default(TRUE) # api_key :string(255) # remind_to_create_team :datetime @@ -423,6 +424,12 @@ class AlsoNotaBadge < BadgeBase # team_responsibilities :text # team_avatar :string(255) # team_banner :string(255) +# stat_name_1 :string(255) +# stat_number_1 :string(255) +# stat_name_2 :string(255) +# stat_number_2 :string(255) +# stat_name_3 :string(255) +# stat_number_3 :string(255) # ip_lat :float # ip_lng :float # penalty :float default(0.0) @@ -431,11 +438,15 @@ class AlsoNotaBadge < BadgeBase # resume :string(255) # sourceforge :string(255) # google_code :string(255) +# sales_rep :boolean default(FALSE) # visits :string(255) default("") # visit_frequency :string(255) default("rarely") +# pitchbox_id :integer # join_badge_orgs :boolean default(FALSE) +# use_social_for_pitchbox :boolean default(FALSE) # last_asm_email_at :datetime # banned_at :datetime # last_ip :string(255) # last_ua :string(255) +# team_id :integer # diff --git a/spec/models/users/github/repository_spec.rb b/spec/models/users/github/repository_spec.rb index 7516e03f..992a3e24 100644 --- a/spec/models/users/github/repository_spec.rb +++ b/spec/models/users/github/repository_spec.rb @@ -20,7 +20,6 @@ end # == Schema Information -# Schema version: 20140728214411 # # Table name: users_github_repositories # @@ -31,9 +30,9 @@ # homepage :string(255) # fork :boolean default(FALSE) # forks_count :integer default(0) -# forks_count_updated_at :datetime default(2014-07-18 23:03:00 UTC) +# forks_count_updated_at :datetime default(2014-07-23 03:14:37 UTC) # stargazers_count :integer default(0) -# stargazers_count_updated_at :datetime default(2014-07-18 23:03:00 UTC) +# stargazers_count_updated_at :datetime default(2014-07-23 03:14:37 UTC) # language :string(255) # followers_count :integer default(0), not null # github_id :integer not null From 6c6ea3d5d69b6b9475def94712a50fa2644434e5 Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Sun, 14 Sep 2014 02:27:17 -0500 Subject: [PATCH 03/28] WIP: Verifying that the teams are migrated correctly --- Gemfile.lock | 32 +-- Rakefile | 69 +++++++ Vagrantfile | 12 +- app/jobs/team_migrator_batch_job.rb | 8 +- app/jobs/team_migrator_job.rb | 182 ++++++++++-------- .../20140914051313_fix_types_on_pg_teams.rb | 8 + db/schema.rb | 8 +- vagrant/coderwall-box/scripts/postinstall.sh | 16 ++ 8 files changed, 237 insertions(+), 98 deletions(-) create mode 100644 db/migrate/20140914051313_fix_types_on_pg_teams.rb diff --git a/Gemfile.lock b/Gemfile.lock index 81ffdb92..e2155957 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,16 +1,12 @@ GIT - remote: git://github.com/emberjs/ember-rails.git - revision: 5e5a398f3c67c3a3b84b7513b93b22bf81055cc9 + remote: https://github.com/rebelidealist/stripe-ruby-mock + revision: f4229cbe762bc2a5a302cdd83088c283881e9c5a + branch: live-tests specs: - ember-rails (0.15.0) - active_model_serializers - barber (>= 0.4.1) - ember-data-source (>= 1.0.0.beta.5) - ember-source (>= 1.1.0) - execjs (>= 1.2) - handlebars-source (> 1.0.0) - jquery-rails (>= 1.0.17) - railties (>= 3.1) + stripe-ruby-mock (1.10.1.7) + dante (>= 0.2.0) + jimson-temp + stripe (>= 1.15.0) GIT remote: git://github.com/nixme/jazz_hands.git @@ -38,6 +34,20 @@ GIT mime-types (>= 1.25, < 3.0) rest-client (~> 1.4) +GIT + remote: git://github.com/emberjs/ember-rails.git + revision: 5e5a398f3c67c3a3b84b7513b93b22bf81055cc9 + specs: + ember-rails (0.15.0) + active_model_serializers + barber (>= 0.4.1) + ember-data-source (>= 1.0.0.beta.5) + ember-source (>= 1.1.0) + execjs (>= 1.2) + handlebars-source (> 1.0.0) + jquery-rails (>= 1.0.17) + railties (>= 3.1) + GEM remote: https://rubygems.org/ remote: https://rails-assets.org/ diff --git a/Rakefile b/Rakefile index 1e1d001f..ade7ca8a 100644 --- a/Rakefile +++ b/Rakefile @@ -4,3 +4,72 @@ require 'rake' Coderwall::Application.load_tasks task default: :spec + + +namespace :team do + task migrate: :environment do + TeamMigratorBatchJob.new.perform + end + + # + # IMPORTANT: pending_join_requests is a STRING array in Postgres but an INTEGER array in MongoDB. + # IMPORTANT: pending_join_requests is an array of User#id values + # + + def neq(attr, pg, mongo, fail_if_neq=true) + left = pg.send(attr) + right = mongo.send(attr) + + if left != right + puts "#{attr} #{left} != #{right} (#{pg.id}|#{mongo.id})" + + if fail_if_neq + require 'pry'; binding.pry + end + end + end + + task verify: :environment do + PgTeam.find_each(batch_size: 100) do |pg_team| + begin + mongo_id = pg_team.mongo_id + mongo_team = Team.find(mongo_id) + + + %i(updated_at median score total slug mean pending_join_requests).each do |attr| + neq(attr, pg_team, mongo_team, false) + end + + + %i(about achievement_count analytics benefit_description_1 benefit_description_2 benefit_description_3 benefit_name_1 benefit_name_2 benefit_name_3 big_image big_quote blog_feed branding country_id created_at endorsement_count facebook featured_banner_image featured_links_title github github_organization_name headline hide_from_featured highlight_tags hiring_tagline interview_steps invited_emails link_to_careers_page location monthly_subscription name number_of_jobs_to_show office_photos organization_way organization_way_name organization_way_photo our_challenge paid_job_posts premium preview_code reason_description_1 reason_description_2 reason_description_3 reason_name_1 reason_name_2 reason_name_3 size stack_list twitter upcoming_events upgraded_at valid_jobs website why_work_image your_impact youtube_url).each do |attr| + neq(attr, pg_team, mongo_team) + end + rescue => ex + + ap ex + + require 'pry'; binding.pry + end + end + end + + task counts: :environment do + pg_team_count = PgTeam.count + puts "PgTeam.count=#{pg_team_count}" + team_count = Team.count + puts "Team.count=#{team_count}" + puts "Unmigrated teams count=#{(team_count - pg_team_count)}" + end + + + task unmigrated: :environment do + unmigrated_teams = [] + + Team.all.each do |team| + unmigrated_teams << team.id.to_s unless PgTeam.where(mongo_id: team.id.to_s).exists? + end + + puts "Unmigrated teams count=#{unmigrated_teams.count}" + puts "Unmigrated Teams=%w(#{unmigrated_teams.join(' ')})" + end +end diff --git a/Vagrantfile b/Vagrantfile index 1e97355c..85765e8b 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -26,10 +26,10 @@ $provision = 'vagrant/bootstrap.sh' Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - config.vm.box = $box - config.vm.box_url = $box_url + config.vm.box = box + #config.vm.box_url = box_url config.vm.provision :shell do |s| - s.path = $provision + s.path = provision end config.ssh.keep_alive = true @@ -70,6 +70,12 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| else puts "Please install the 'vagrant-vbguest' plugin" end + + #if Vagrant.has_plugin?('vagrant-cachier') + #config.cache.scope = :box + #else + #puts "Please install the 'vagrant-cachier' plugin" + #end end def set_port_mapping_for(config, service, guest_port, settings, force = false) diff --git a/app/jobs/team_migrator_batch_job.rb b/app/jobs/team_migrator_batch_job.rb index 3a9bd206..1f5032f8 100644 --- a/app/jobs/team_migrator_batch_job.rb +++ b/app/jobs/team_migrator_batch_job.rb @@ -3,8 +3,12 @@ class TeamMigratorBatchJob include Sidekiq::Worker def perform - Team.each do |team| - TeamMigratorJob.perform_async(team.id.to_s) + Team.each do |team| + begin + TeamMigratorJob.perform_async(team.id.to_s) + rescue => ex + Rails.logger.error("[#{team.id.to_s}] #{ex} >>\n#{ex.backtrace.join("\n ")}") + end end end end diff --git a/app/jobs/team_migrator_job.rb b/app/jobs/team_migrator_job.rb index 8eb207d9..7b23b16b 100644 --- a/app/jobs/team_migrator_job.rb +++ b/app/jobs/team_migrator_job.rb @@ -5,6 +5,8 @@ class TeamMigratorJob sidekiq_options backtrace: true def perform(id) + Rails.logger.info("perform(#{id})") + team = Team.find(id) if pgteam = find_or_initialize_team(id, team) extract_account(pgteam, team) @@ -22,125 +24,143 @@ def perform(id) private def find_or_initialize_team(id, team) + Rails.logger.info("find_or_initialize_team(#{id}, #{team.id})") + begin PgTeam.find_or_initialize_by_mongo_id(id) do |pgteam| - pgteam.name = team.name - pgteam.slug = team.slug - pgteam.created_at = team.created_at - pgteam.updated_at = team.updated_at - pgteam.website = team.website - pgteam.about = team.about - pgteam.total = team.total - pgteam.size = team.size - pgteam.mean = team.mean - pgteam.median = team.median - pgteam.score = team.score - pgteam.twitter = team.twitter - pgteam.facebook = team.facebook - pgteam.premium = team.premium - pgteam.analytics = team.analytics - pgteam.valid_jobs = team.valid_jobs - pgteam.hide_from_featured = team.hide_from_featured - pgteam.preview_code = team.preview_code - pgteam.youtube_url = team.youtube_url - pgteam.github = team.github - pgteam.highlight_tags = team.highlight_tags - pgteam.branding = team.branding - pgteam.headline = team.headline - pgteam.big_quote = team.big_quote - pgteam.big_image = team.big_image - pgteam.featured_banner_image = team.featured_banner_image - pgteam.benefit_name_1 = team.benefit_name_1 - pgteam.benefit_description_1 = team.benefit_description_1 - pgteam.benefit_name_2 = team.benefit_name_2 - pgteam.benefit_description_2 = team.benefit_description_2 - pgteam.benefit_name_3 = team.benefit_name_3 - pgteam.benefit_description_3 = team.benefit_description_3 - pgteam.reason_name_1 = team.reason_name_1 - pgteam.reason_description_1 = team.reason_description_1 - pgteam.reason_name_2 = team.reason_name_2 - pgteam.reason_description_2 = team.reason_description_2 - pgteam.reason_name_3 = team.reason_name_3 - pgteam.reason_description_3 = team.reason_description_3 - pgteam.why_work_image = team.why_work_image - pgteam.organization_way = team.organization_way - pgteam.organization_way_name = team.organization_way_name - pgteam.organization_way_photo = team.organization_way_photo - pgteam.office_photos = team.office_photos - pgteam.upcoming_events = team.upcoming_events - pgteam.featured_links_title = team.featured_links_title - pgteam.blog_feed = team.blog_feed - pgteam.our_challenge = team.our_challenge - pgteam.your_impact = team.your_impact - pgteam.interview_steps = team.interview_steps - pgteam.hiring_tagline = team.hiring_tagline - pgteam.link_to_careers_page = team.link_to_careers_page - # pgteam.avatar = team.avatar - pgteam.achievement_count = team.achievement_count - pgteam.endorsement_count = team.endorsement_count - pgteam.invited_emails = team.invited_emails - pgteam.pending_join_requests = team.pending_join_requests - pgteam.upgraded_at = team.upgraded_at - pgteam.paid_job_posts = team.paid_job_posts - pgteam.monthly_subscription = team.monthly_subscription - pgteam.stack_list = team.stack_list - pgteam.number_of_jobs_to_show = team.number_of_jobs_to_show - pgteam.location = team.location - pgteam.country_id = team.country_id + # pgteam.avatar = team.avatar + pgteam.about = team.about + pgteam.achievement_count = team.achievement_count + pgteam.analytics = team.analytics + pgteam.benefit_description_1 = team.benefit_description_1 + pgteam.benefit_description_2 = team.benefit_description_2 + pgteam.benefit_description_3 = team.benefit_description_3 + pgteam.benefit_name_1 = team.benefit_name_1 + pgteam.benefit_name_2 = team.benefit_name_2 + pgteam.benefit_name_3 = team.benefit_name_3 + pgteam.big_image = team.big_image + pgteam.big_quote = team.big_quote + pgteam.blog_feed = team.blog_feed + pgteam.branding = team.branding + pgteam.country_id = team.country_id + pgteam.created_at = team.created_at + pgteam.endorsement_count = team.endorsement_count + pgteam.facebook = team.facebook + pgteam.featured_banner_image = team.featured_banner_image + pgteam.featured_links_title = team.featured_links_title + pgteam.github = team.github pgteam.github_organization_name = team.github_organization_name - pgteam.save! + pgteam.headline = team.headline + pgteam.hide_from_featured = team.hide_from_featured + pgteam.highlight_tags = team.highlight_tags + pgteam.hiring_tagline = team.hiring_tagline + pgteam.interview_steps = team.interview_steps + pgteam.invited_emails = team.invited_emails + pgteam.link_to_careers_page = team.link_to_careers_page + pgteam.location = team.location + pgteam.mean = team.mean + pgteam.median = team.median + pgteam.monthly_subscription = team.monthly_subscription + pgteam.name = team.name + pgteam.number_of_jobs_to_show = team.number_of_jobs_to_show + pgteam.office_photos = team.office_photos + pgteam.organization_way = team.organization_way + pgteam.organization_way_name = team.organization_way_name + pgteam.organization_way_photo = team.organization_way_photo + pgteam.our_challenge = team.our_challenge + pgteam.paid_job_posts = team.paid_job_posts + pgteam.pending_join_requests = team.pending_join_requests + pgteam.premium = team.premium + pgteam.preview_code = team.preview_code + pgteam.reason_description_1 = team.reason_description_1 + pgteam.reason_description_2 = team.reason_description_2 + pgteam.reason_description_3 = team.reason_description_3 + pgteam.reason_name_1 = team.reason_name_1 + pgteam.reason_name_2 = team.reason_name_2 + pgteam.reason_name_3 = team.reason_name_3 + pgteam.score = team.score + pgteam.size = team.size + pgteam.slug = team.slug + pgteam.stack_list = team.stack_list + pgteam.total = team.total + pgteam.twitter = team.twitter + pgteam.upcoming_events = team.upcoming_events + pgteam.updated_at = team.updated_at + pgteam.upgraded_at = team.upgraded_at + pgteam.valid_jobs = team.valid_jobs + pgteam.website = team.website + pgteam.why_work_image = team.why_work_image + pgteam.your_impact = team.your_impact + pgteam.youtube_url = team.youtube_url + pgteam.save! end - rescue ActiveRecord::RecordInvalid + rescue ActiveRecord::RecordInvalid => ex + Rails.logger.error("[find_or_initialize_team(#{id}, #{team.id})] #{ex} >>\n#{ex.backtrace.join("\n ")}") + false end end def extract_account(pgteam, team) + Rails.logger.info("extract_account(#{pgteam.id}, #{team.id})") + return unless account = team.account return if pgteam.account begin pgaccount = pgteam.build_account( - stripe_card_token: account.stripe_card_token, - stripe_customer_token: account.stripe_customer_token, - admin_id: account.admin_id + stripe_card_token: account.stripe_card_token, + stripe_customer_token: account.stripe_customer_token, + admin_id: account.admin_id ) pgaccount.plans << Plan.where(id: account.plan_ids) pgaccount.save! - rescue ActiveRecord::RecordInvalid => e + rescue ActiveRecord::RecordInvalid => ex + Rails.logger.error("[extract_account(#{pgteam.id}, #{team.id})] #{ex} >>\n#{ex.backtrace.join("\n ")}") + + Rails.logger.ap(pgteam, :error) + Rails.logger.ap(team, :error) + # @just3ws, uncomment the following line and get all ID of the corrupted accounts - # raise e + raise ex + false end end def extract_locations(pgteam, team) + Rails.logger.info("extract_locations(#{pgteam.id}, #{team.id})") + locations = team.team_locations return unless locations.any? return if pgteam.locations.any? locations.each do |location| pgteam.locations.create! name: location.name, - description: location.description, - address: location.address, - city: location.city, - state_code: location.state_code, - country: location.country + description: location.description, + address: location.address, + city: location.city, + state_code: location.state_code, + country: location.country end end def extract_links(pgteam, team) + Rails.logger.info("extract_links(#{pgteam.id}, #{team.id})") + links = team.featured_links return if links.empty? return if pgteam.links.any? links.each do |link| pgteam.links.create! name: link.name, - url: link.url + url: link.url end end def add_members(pgteam) + Rails.logger.info("add_members(#{pgteam.id})") + users = User.where(team_document_id: pgteam.mongo_id) users.each do |user| pgteam.members.create! user: user, state: 'active' @@ -149,21 +169,27 @@ def add_members(pgteam) end def add_jobs(pgteam) + Rails.logger.info("add_jobs(#{pgteam.id})") + Opportunity.where(team_document_id: pgteam.mongo_id).update_all(team_id: pgteam.id) end def convert_followers(pgteam) + Rails.logger.info("convert_followers(#{pgteam.id})") + FollowedTeam.where(team_document_id: pgteam.mongo_id).update_all(team_id: pgteam.id) end def add_pending_requests(pgteam, team) + Rails.logger.info("add_pending_requests(#{pgteam.id}, #{team.id})") + pending_team_members = team.pending_team_members return if pending_team_members.empty? pending_team_members.each do |pending_team_member| user = User.find pending_team_member.user_id pgteam.members.create user: user, - created_at: pending_team_member.created_at, - updated_at: pending_team_member.updated_at + created_at: pending_team_member.created_at, + updated_at: pending_team_member.updated_at end end end diff --git a/db/migrate/20140914051313_fix_types_on_pg_teams.rb b/db/migrate/20140914051313_fix_types_on_pg_teams.rb new file mode 100644 index 00000000..ba8bc553 --- /dev/null +++ b/db/migrate/20140914051313_fix_types_on_pg_teams.rb @@ -0,0 +1,8 @@ +class FixTypesOnPgTeams < ActiveRecord::Migration + def change + change_column(:teams, :mean, :float, default: 0.0) + change_column(:teams, :median, :float, default: 0.0) + change_column(:teams, :score, :float, default: 0.0) + change_column(:teams, :total, :float, default: 0.0) + end +end diff --git a/db/schema.rb b/db/schema.rb index 65743c62..40ae829e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -361,11 +361,11 @@ t.datetime "updated_at", :null => false t.string "website" t.text "about" - t.integer "total", :default => 0 + t.float "total", :default => 0.0 t.integer "size", :default => 0 - t.integer "mean", :default => 0 - t.integer "median", :default => 0 - t.integer "score", :default => 0 + t.float "mean", :default => 0.0 + t.float "median", :default => 0.0 + t.float "score", :default => 0.0 t.string "twitter" t.string "facebook" t.string "slug" diff --git a/vagrant/coderwall-box/scripts/postinstall.sh b/vagrant/coderwall-box/scripts/postinstall.sh index e056f981..7710b8f2 100644 --- a/vagrant/coderwall-box/scripts/postinstall.sh +++ b/vagrant/coderwall-box/scripts/postinstall.sh @@ -24,6 +24,22 @@ apt-get -y install linux-headers-$(uname -r) apt-get -y install build-essential # General dependencies and tools just... mashed, just mashed all together. +apt-get -y install ack-grep autoconf automake bison ca-certificates \ + curl g++ gcc git-core htop iotop libc6-dev libffi-dev \ + libgdbm-dev libncurses5-dev libopenssl-ruby libreadline6 \ + libreadline6-dev libsqlite3-0 libsqlite3-dev libssl-dev \ + libtool libxml2-dev libxslt-dev libyaml-dev make openssl \ + patch pkg-config sqlite3 tmux vim zlib1g zlib1g-dev gawk \ + libxml2-dev curl libcurl4-openssl-dev \ + imagemagick libmagickcore-dev libmagickwand-dev tcl8.5 +apt-get -y install libcurl3 libcurl3-dev libcurl3-gnutls libcurl4-openssl-dev +apt-get -y install libpq-dev +apt-get -y install libxml2 libxml2-dev libxslt1-dev + + +# Install NFS client +apt-get -y install nfs-common portmap + # Apt-install python tools and libraries # Install NFS client # libpq-dev lets us compile psycopg for Postgres From fcccc1f11807f6827a7d26152ce4e7d141459bdb Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Sun, 14 Sep 2014 02:46:49 -0500 Subject: [PATCH 04/28] Continuing to verify --- Rakefile | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/Rakefile b/Rakefile index ade7ca8a..68690969 100644 --- a/Rakefile +++ b/Rakefile @@ -21,12 +21,19 @@ namespace :team do right = mongo.send(attr) if left != right - puts "#{attr} #{left} != #{right} (#{pg.id}|#{mongo.id})" - - if fail_if_neq - require 'pry'; binding.pry - end + puts "#{attr} | #{left} != #{right} | pg:#{pg.id} | mongo:#{mongo.id}" end + rescue => ex + puts '*'*80 + puts + puts ex + puts + puts '-'*80 + puts + ap ex.backtrace + puts + puts '*'*80 + require 'pry'; binding.pry end task verify: :environment do @@ -35,20 +42,36 @@ namespace :team do mongo_id = pg_team.mongo_id mongo_team = Team.find(mongo_id) - + # Team %i(updated_at median score total slug mean pending_join_requests).each do |attr| neq(attr, pg_team, mongo_team, false) end - %i(about achievement_count analytics benefit_description_1 benefit_description_2 benefit_description_3 benefit_name_1 benefit_name_2 benefit_name_3 big_image big_quote blog_feed branding country_id created_at endorsement_count facebook featured_banner_image featured_links_title github github_organization_name headline hide_from_featured highlight_tags hiring_tagline interview_steps invited_emails link_to_careers_page location monthly_subscription name number_of_jobs_to_show office_photos organization_way organization_way_name organization_way_photo our_challenge paid_job_posts premium preview_code reason_description_1 reason_description_2 reason_description_3 reason_name_1 reason_name_2 reason_name_3 size stack_list twitter upcoming_events upgraded_at valid_jobs website why_work_image your_impact youtube_url).each do |attr| neq(attr, pg_team, mongo_team) end - rescue => ex - ap ex + # TODO: Account + unless mongo_team.account.nil? || pg_team.account.nil? + %i(stripe_card_token stripe_customer_token admin_id).each do |attr| + neq(attr, pg_team.account, mongo_team.account) + end + end + + # TODO: Plans + + # TODO: Locations + + # TODO: Links + + # TODO: Members + + # TODO: Jobs + + # TODO: Followers + + # TODO: Pending Requests - require 'pry'; binding.pry end end end From f40ff78671fcee359c000688119dc83e89d2cbb8 Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Mon, 15 Sep 2014 13:47:05 -0500 Subject: [PATCH 05/28] Verify Team#account and Team#account.plans migration --- Rakefile | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/Rakefile b/Rakefile index 68690969..84d5ed5e 100644 --- a/Rakefile +++ b/Rakefile @@ -21,7 +21,10 @@ namespace :team do right = mongo.send(attr) if left != right - puts "#{attr} | #{left} != #{right} | pg:#{pg.id} | mongo:#{mongo.id}" + puts "#{attr} | pg:#{pg.id} | mongo:#{mongo.id}| #{left} != #{right}" + true + else + false end rescue => ex puts '*'*80 @@ -42,8 +45,11 @@ namespace :team do mongo_id = pg_team.mongo_id mongo_team = Team.find(mongo_id) + # Ignoring: + # - updated_at + # Team - %i(updated_at median score total slug mean pending_join_requests).each do |attr| + %i(median score total slug mean pending_join_requests).each do |attr| neq(attr, pg_team, mongo_team, false) end @@ -52,14 +58,26 @@ namespace :team do end # TODO: Account - unless mongo_team.account.nil? || pg_team.account.nil? - %i(stripe_card_token stripe_customer_token admin_id).each do |attr| + if mongo_team.account.present? && pg_team.account.blank? + puts "account | pg:#{pg_team.id} | mongo:#{mongo_team.id}| The account was not migrated." + end + + if mongo_team.account.present? && pg_team.account.present? + check_plans = %i(stripe_card_token stripe_customer_token admin_id).map do |attr| neq(attr, pg_team.account, mongo_team.account) + end.any? { |x| !x } + + # TODO: Plans + if check_plans + left = pg_team.account.plans.pluck(:id).sort + right = mongo_team.account.plan_ids.sort + + if left != right + puts "account.plans | pg:#{pg_team.id} | mongo:#{mongo_team.id}| #{left} != #{right}" + end end end - # TODO: Plans - # TODO: Locations # TODO: Links From 4e0a2df366157e6f15eb3c7b637684b5dc4c67c2 Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Mon, 15 Sep 2014 17:49:16 -0500 Subject: [PATCH 06/28] More verfications. Needed to mark the source for the follower class --- Rakefile | 80 ++++++++++++++++++++++++++++++++--- app/jobs/team_migrator_job.rb | 13 +++--- app/models/pg_team.rb | 4 +- 3 files changed, 83 insertions(+), 14 deletions(-) diff --git a/Rakefile b/Rakefile index 84d5ed5e..0572195f 100644 --- a/Rakefile +++ b/Rakefile @@ -36,6 +36,7 @@ namespace :team do ap ex.backtrace puts puts '*'*80 + require 'pry'; binding.pry end @@ -48,7 +49,10 @@ namespace :team do # Ignoring: # - updated_at - # Team + puts '----------------------------------------------------------------------------------------------------' + puts 'TEAM' + puts '----------------------------------------------------------------------------------------------------' + %i(median score total slug mean pending_join_requests).each do |attr| neq(attr, pg_team, mongo_team, false) end @@ -78,15 +82,79 @@ namespace :team do end end - # TODO: Locations - # TODO: Links + puts '----------------------------------------------------------------------------------------------------' + puts 'LOCATIONS' + puts '----------------------------------------------------------------------------------------------------' + + pg_team_locations = pg_team.locations + mongo_team_locations = mongo_team.team_locations + + if mongo_team_locations.count != pg_team_locations.count + puts "locations | pg:#{pg_team.id} | mongo:#{mongo_team.id}| #{mongo_team_locations.count} != #{pg_team_locations.count}" + end + + # Ignoring: + # - points_of_interest + pg_team.locations.each do |pg_team_location| + mongo_team_location = mongo_team.team_locations.select { |tl| tl.name == pg_team_location.name }.first + + %i(address city country description name state_code).each do |attr| + neq(attr, pg_team_location, mongo_team_location, false) + end + end + + + puts '----------------------------------------------------------------------------------------------------' + puts 'LINKS' + puts '----------------------------------------------------------------------------------------------------' + + pg_team_links = pg_team.links + mongo_team_links = mongo_team.featured_links + + if mongo_team_links.count != pg_team_links.count + puts "links | pg:#{pg_team.id} | mongo:#{mongo_team.id}| #{mongo_team_links.count} != #{pg_team_links.count}" + end + + pg_team_links.each do |pg_team_link| + mongo_team_link = mongo_team_links.select { |tl| tl.name == pg_team_link.name }.first + + %i(url name).each do |attr| + neq(attr, pg_team_link, mongo_team_link, false) + end + end + + puts '----------------------------------------------------------------------------------------------------' + puts 'MEMBERS' + puts '----------------------------------------------------------------------------------------------------' + + if pg_team.members.count != mongo_team.team_members.count + puts "members | pg:#{pg_team.id} | mongo:#{mongo_team.id}| #{mongo_team.team_members.count} != #{pg_team.members.count}" + end + - # TODO: Members + puts '----------------------------------------------------------------------------------------------------' + puts 'JOBS' + puts '----------------------------------------------------------------------------------------------------' - # TODO: Jobs + pg_team.jobs.each do |pg_team_job| + mongo_team_job = Team.where(id: pg_team_job.team_document_id.to_s).first + + neq(:name, pg_team_job, mongo_team_job, false) + end - # TODO: Followers + puts '----------------------------------------------------------------------------------------------------' + puts 'FOLLOWERS' + puts '----------------------------------------------------------------------------------------------------' + + pg_team.followers.each do |pg_team_follower| + mongo_team_follower = Team.where(id: pg_team_follower.mongo_id.to_s).first + # admins + # editors + %i(about achievement_count analytics avatar benefit_description_1 benefit_description_2 benefit_description_3 benefit_name_1 benefit_name_2 benefit_name_3 big_image big_quote blog_feed branding country_id created_at endorsement_count facebook featured_banner_image featured_links_title github_organization_name headline hide_from_featured highlight_tags hiring_tagline interview_steps invited_emails link_to_careers_page location mean median monthly_subscription name number_of_jobs_to_show office_photos organization_way organization_way_name organization_way_photo our_challenge paid_job_posts pending_join_requests premium preview_code reason_description_1 reason_description_2 reason_description_3 reason_name_1 reason_name_2 reason_name_3 score size slug stack_list total twitter upcoming_events updated_at upgraded_at valid_jobs website why_work_image your_impact youtube_url).each do |attr| + neq(attr, pg_team_follower, mongo_team_follower, false) + end + end # TODO: Pending Requests diff --git a/app/jobs/team_migrator_job.rb b/app/jobs/team_migrator_job.rb index 7b23b16b..3a0a6a51 100644 --- a/app/jobs/team_migrator_job.rb +++ b/app/jobs/team_migrator_job.rb @@ -136,13 +136,14 @@ def extract_locations(pgteam, team) return unless locations.any? return if pgteam.locations.any? locations.each do |location| - pgteam.locations.create! name: location.name, + pgteam.locations.create!( + name: location.name, description: location.description, - address: location.address, - city: location.city, - state_code: location.state_code, - country: location.country - + address: location.address, + city: location.city, + state_code: location.state_code, + country: location.country + ) end end diff --git a/app/models/pg_team.rb b/app/models/pg_team.rb index e19f9f65..45efc214 100644 --- a/app/models/pg_team.rb +++ b/app/models/pg_team.rb @@ -12,8 +12,8 @@ class PgTeam < ActiveRecord::Base has_many :locations, class_name: 'Teams::Location', foreign_key: 'team_id', dependent: :delete_all has_many :jobs, class_name: 'Opportunity', foreign_key: 'team_id', dependent: :destroy - has_many :follows , class_name: 'FollowedTeam', foreign_key: 'team_id', dependent: :destroy - has_many :followers, through: :follows + has_many :follows, class_name: 'FollowedTeam', foreign_key: 'team_id', dependent: :destroy + has_many :followers, through: :follows, source: :team accepts_nested_attributes_for :locations, :links, allow_destroy: true, reject_if: :all_blank From adad96c21d74336acf3d5ef8fc24e5654d678c67 Mon Sep 17 00:00:00 2001 From: Dane Lyons Date: Mon, 8 Sep 2014 18:21:49 -0700 Subject: [PATCH 07/28] Retina favicons, #270 --- Gemfile.lock | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index e2155957..1a3245ea 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,6 +8,20 @@ GIT jimson-temp stripe (>= 1.15.0) +GIT + remote: git://github.com/emberjs/ember-rails.git + revision: 5e5a398f3c67c3a3b84b7513b93b22bf81055cc9 + specs: + ember-rails (0.15.0) + active_model_serializers + barber (>= 0.4.1) + ember-data-source (>= 1.0.0.beta.5) + ember-source (>= 1.1.0) + execjs (>= 1.2) + handlebars-source (> 1.0.0) + jquery-rails (>= 1.0.17) + railties (>= 3.1) + GIT remote: git://github.com/nixme/jazz_hands.git revision: 5e4b48f145883ecb14b55bf04eacc28ac9662676 @@ -34,20 +48,6 @@ GIT mime-types (>= 1.25, < 3.0) rest-client (~> 1.4) -GIT - remote: git://github.com/emberjs/ember-rails.git - revision: 5e5a398f3c67c3a3b84b7513b93b22bf81055cc9 - specs: - ember-rails (0.15.0) - active_model_serializers - barber (>= 0.4.1) - ember-data-source (>= 1.0.0.beta.5) - ember-source (>= 1.1.0) - execjs (>= 1.2) - handlebars-source (> 1.0.0) - jquery-rails (>= 1.0.17) - railties (>= 3.1) - GEM remote: https://rubygems.org/ remote: https://rails-assets.org/ From b3beec7f9af9950666a36300bd5c317b172c80c4 Mon Sep 17 00:00:00 2001 From: Dane Lyons Date: Mon, 8 Sep 2014 18:35:23 -0700 Subject: [PATCH 08/28] retina favicons --- Gemfile.lock | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Gemfile.lock b/Gemfile.lock index 1a3245ea..47ec938e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -48,6 +48,20 @@ GIT mime-types (>= 1.25, < 3.0) rest-client (~> 1.4) +GIT + remote: git://github.com/emberjs/ember-rails.git + revision: 5e5a398f3c67c3a3b84b7513b93b22bf81055cc9 + specs: + ember-rails (0.15.0) + active_model_serializers + barber (>= 0.4.1) + ember-data-source (>= 1.0.0.beta.5) + ember-source (>= 1.1.0) + execjs (>= 1.2) + handlebars-source (> 1.0.0) + jquery-rails (>= 1.0.17) + railties (>= 3.1) + GEM remote: https://rubygems.org/ remote: https://rails-assets.org/ From a16be403a6141cbd82a6f7fba94d78207927d28b Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Mon, 22 Sep 2014 16:59:25 -0500 Subject: [PATCH 09/28] Bumped gem --- Gemfile.lock | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 47ec938e..1a3245ea 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -48,20 +48,6 @@ GIT mime-types (>= 1.25, < 3.0) rest-client (~> 1.4) -GIT - remote: git://github.com/emberjs/ember-rails.git - revision: 5e5a398f3c67c3a3b84b7513b93b22bf81055cc9 - specs: - ember-rails (0.15.0) - active_model_serializers - barber (>= 0.4.1) - ember-data-source (>= 1.0.0.beta.5) - ember-source (>= 1.1.0) - execjs (>= 1.2) - handlebars-source (> 1.0.0) - jquery-rails (>= 1.0.17) - railties (>= 3.1) - GEM remote: https://rubygems.org/ remote: https://rails-assets.org/ From 7a89d9aa4ad91471194b32eafaac0e7deb59509e Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Thu, 25 Sep 2014 00:42:10 -0500 Subject: [PATCH 10/28] Script to generate a new box --- vagrant/coderwall-box/scripts/postinstall.sh | 55 ++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/vagrant/coderwall-box/scripts/postinstall.sh b/vagrant/coderwall-box/scripts/postinstall.sh index 7710b8f2..3e7df6de 100644 --- a/vagrant/coderwall-box/scripts/postinstall.sh +++ b/vagrant/coderwall-box/scripts/postinstall.sh @@ -8,6 +8,61 @@ done sleep 30 +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +sleep 30 + + set -x date > /etc/vagrant_box_build_time From be6128a920ed1c629bbd0ea14aca83e0bc49afe3 Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Fri, 3 Oct 2014 21:30:25 -0500 Subject: [PATCH 11/28] Update CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0af977b4..a1939530 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -49,7 +49,7 @@ If you're running Windows, [here's a guide written by one of our members on how 1. **Install VirtualBox** Grab the VirtualBox installer from **[here](https://www.virtualbox.org/wiki/Download_Old_Builds_4_3)**. - + ![Download the Vbox installer and extensions from here](https://www.evernote.com/shard/s13/sh/68b6a635-7a80-444b-a210-c1aa61405efc/955c950ebafc46f0f1069e27e85bb120) The _required_ version is **VirtualBox 4.3.12.** From 4b8ca843177ad814a96b9c1ee11a3d1c2746cb4b Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Tue, 7 Oct 2014 15:36:10 -0500 Subject: [PATCH 12/28] Use Airbrake.io --- config/initializers/airbrake.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/config/initializers/airbrake.rb b/config/initializers/airbrake.rb index 3a739e5e..69edf7d4 100644 --- a/config/initializers/airbrake.rb +++ b/config/initializers/airbrake.rb @@ -1,3 +1,9 @@ -Airbrake.configure do |config| - config.api_key = ENV['AIRBRAKE_API_KEY'] +if defined?(Airbrake) + Airbrake.configure do |config| + config.api_key = ENV['AIRBRAKE_API_KEY'] + end +else + unless Rails.env.test? || Rails.env.development? + Rails.logger.warn '[WTF WARNING] Someone deleted airbrake and forgot the initializer' + end end From 6607d51c1eb322b5675604ed0f9abde0ab6c363b Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Sat, 13 Sep 2014 20:48:34 +0000 Subject: [PATCH 13/28] :skull: mongodb --- Gemfile.lock | 10 ++++++++++ app/jobs/team_migrator_job.rb | 7 ++----- app/models/pg_team.rb | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1a3245ea..7e60c118 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -48,6 +48,16 @@ GIT mime-types (>= 1.25, < 3.0) rest-client (~> 1.4) +GIT + remote: https://github.com/rebelidealist/stripe-ruby-mock + revision: f4229cbe762bc2a5a302cdd83088c283881e9c5a + branch: live-tests + specs: + stripe-ruby-mock (1.10.1.7) + dante (>= 0.2.0) + jimson-temp + stripe (>= 1.15.0) + GEM remote: https://rubygems.org/ remote: https://rails-assets.org/ diff --git a/app/jobs/team_migrator_job.rb b/app/jobs/team_migrator_job.rb index 3a0a6a51..e18971d5 100644 --- a/app/jobs/team_migrator_job.rb +++ b/app/jobs/team_migrator_job.rb @@ -154,8 +154,7 @@ def extract_links(pgteam, team) return if links.empty? return if pgteam.links.any? links.each do |link| - pgteam.links.create! name: link.name, - url: link.url + pgteam.links.create!(name: link.name, url: link.url) end end @@ -188,9 +187,7 @@ def add_pending_requests(pgteam, team) return if pending_team_members.empty? pending_team_members.each do |pending_team_member| user = User.find pending_team_member.user_id - pgteam.members.create user: user, - created_at: pending_team_member.created_at, - updated_at: pending_team_member.updated_at + pgteam.members.create(user: user, created_at: pending_team_member.created_at, updated_at: pending_team_member.updated_at) end end end diff --git a/app/models/pg_team.rb b/app/models/pg_team.rb index 45efc214..d3d67099 100644 --- a/app/models/pg_team.rb +++ b/app/models/pg_team.rb @@ -26,8 +26,8 @@ class PgTeam < ActiveRecord::Base validates :slug, uniqueness: true, presence: true private def create_slug! - self.slug = name.parameterize - end + self.slug = name.parameterize + end end # From 539981a03d99749935e702d4da67fe5c7aa49f83 Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Sun, 14 Sep 2014 02:27:17 -0500 Subject: [PATCH 14/28] WIP: Verifying that the teams are migrated correctly --- Gemfile.lock | 31 +++++++++++++++---------------- Rakefile | 1 - 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7e60c118..b0d7848a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,15 +12,10 @@ GIT remote: git://github.com/emberjs/ember-rails.git revision: 5e5a398f3c67c3a3b84b7513b93b22bf81055cc9 specs: - ember-rails (0.15.0) - active_model_serializers - barber (>= 0.4.1) - ember-data-source (>= 1.0.0.beta.5) - ember-source (>= 1.1.0) - execjs (>= 1.2) - handlebars-source (> 1.0.0) - jquery-rails (>= 1.0.17) - railties (>= 3.1) + stripe-ruby-mock (1.10.1.7) + dante (>= 0.2.0) + jimson-temp + stripe (>= 1.15.0) GIT remote: git://github.com/nixme/jazz_hands.git @@ -49,14 +44,18 @@ GIT rest-client (~> 1.4) GIT - remote: https://github.com/rebelidealist/stripe-ruby-mock - revision: f4229cbe762bc2a5a302cdd83088c283881e9c5a - branch: live-tests + remote: git://github.com/emberjs/ember-rails.git + revision: 5e5a398f3c67c3a3b84b7513b93b22bf81055cc9 specs: - stripe-ruby-mock (1.10.1.7) - dante (>= 0.2.0) - jimson-temp - stripe (>= 1.15.0) + ember-rails (0.15.0) + active_model_serializers + barber (>= 0.4.1) + ember-data-source (>= 1.0.0.beta.5) + ember-source (>= 1.1.0) + execjs (>= 1.2) + handlebars-source (> 1.0.0) + jquery-rails (>= 1.0.17) + railties (>= 3.1) GEM remote: https://rubygems.org/ diff --git a/Rakefile b/Rakefile index 0572195f..6a2da73b 100644 --- a/Rakefile +++ b/Rakefile @@ -157,7 +157,6 @@ namespace :team do end # TODO: Pending Requests - end end end From a3d5275a065104c3820eb445b9ed6225ccdfe5ea Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Wed, 15 Oct 2014 13:20:38 -0500 Subject: [PATCH 15/28] Added tasks copied from ASM to make downloading the production data easier --- lib/tasks/db.rake | 52 ++++++++++++++++++++++++++++++++++++++++++++ lib/tasks/redis.rake | 5 +++++ 2 files changed, 57 insertions(+) create mode 100644 lib/tasks/db.rake create mode 100644 lib/tasks/redis.rake diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake new file mode 100644 index 00000000..e3f3bccc --- /dev/null +++ b/lib/tasks/db.rake @@ -0,0 +1,52 @@ +namespace :db do + + task smash: %w(redis:flush db:schema:load db:test:prepare db:seed) + + namespace :download do + def db_dump_file + `mkdir -p /home/vagrant/tmp` + '/home/vagrant/tmp/coderwall-production.dump' + end + + desc 'Create a production database backup' + task :generate do + Bundler.with_clean_env do + sh("heroku pgbackups:capture --expire --app #{ENV['HEROKU_APP_NAME']}") + end + end + + desc 'Download latest database backup' + task :latest do + Bundler.with_clean_env do + sh("curl `heroku pgbackups:url --app #{ENV['HEROKU_APP_NAME']}` -o #{db_dump_file}") + end + end + + desc 'Load local database backup into dev' + task load: :environment do + raise 'local dump not found' unless File.exists?(db_dump_file) + + puts 'Cleaning out local database tables' + ActiveRecord::Base.connection.tables.each do |table| + puts "Dropping #{table}" + ActiveRecord::Base.connection.execute("DROP TABLE #{table};") + end + + puts 'Loading Production database locally' + `pg_restore --verbose --clean --no-acl --no-owner -h localhost -d coderwall_development #{db_dump_file}` + + puts '!!!!========= YOU MUST RESTART YOUR SERVER =========!!!!' + end + + task :clean do + `rm #{db_dump_file}` + end + end + + task restore: %w(db:download:generate db:download:latest db:download:load db:download:clean db:migrate) + + desc 'ActiveRecord can you shut up for 30 minutes?' + task mute: :environment do + ActiveRecord::Base.logger = nil + end +end diff --git a/lib/tasks/redis.rake b/lib/tasks/redis.rake new file mode 100644 index 00000000..85987595 --- /dev/null +++ b/lib/tasks/redis.rake @@ -0,0 +1,5 @@ +namespace :redis do + task :flush => :environment do + $redis.flushdb + end +end From 5fc24d5d52f461770fcb4bfca17ad2dc5f732979 Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Wed, 15 Oct 2014 16:11:43 -0500 Subject: [PATCH 16/28] Updated Vagrant configuration to include cachier and apt dependencies --- Vagrantfile | 6 +++--- vagrant/bootstrap.sh | 1 + vagrant/coderwall-box/scripts/postinstall.sh | 1 - 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 85765e8b..3f1ff7cc 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -26,10 +26,10 @@ $provision = 'vagrant/bootstrap.sh' Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - config.vm.box = box - #config.vm.box_url = box_url + config.vm.box = $box + config.vm.box_url = $box_url config.vm.provision :shell do |s| - s.path = provision + s.path = $provision end config.ssh.keep_alive = true diff --git a/vagrant/bootstrap.sh b/vagrant/bootstrap.sh index 568945b8..491d547e 100755 --- a/vagrant/bootstrap.sh +++ b/vagrant/bootstrap.sh @@ -65,4 +65,5 @@ su - vagrant <<-'EOF' # Force the app to use the internal Postgres port number and ignore .env bundle exec rake db:migrate bundle exec rake db:test:prepare + EOF diff --git a/vagrant/coderwall-box/scripts/postinstall.sh b/vagrant/coderwall-box/scripts/postinstall.sh index 3e7df6de..923e7cfd 100644 --- a/vagrant/coderwall-box/scripts/postinstall.sh +++ b/vagrant/coderwall-box/scripts/postinstall.sh @@ -125,7 +125,6 @@ apt-get -y install libmagickwand-dev apt-get -y install libncurses5-dev apt-get -y install libopenssl-ruby apt-get -y install libpq-dev -apt-get -y install libpq-dev apt-get -y install libreadline6 apt-get -y install libreadline6-dev apt-get -y install libsqlite3-0 From 192367d0c0fe752c6a81186bd1638b7bce2ba7e5 Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Mon, 20 Oct 2014 16:44:02 -0500 Subject: [PATCH 17/28] Tweaked the precision on the calculated scores for conversion from MongoDB => Postgres --- Gemfile.lock | 36 ++--- Rakefile | 149 +++++++++++++++--- app/jobs/team_migrator_job.rb | 10 +- config/database.yml | 1 - config/mongoid.yml | 4 +- .../20140914051313_fix_types_on_pg_teams.rb | 8 +- db/schema.rb | 46 +++--- lib/tasks/db.rake | 42 +++-- vagrant/coderwall-box/scripts/postinstall.sh | 2 +- 9 files changed, 215 insertions(+), 83 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b0d7848a..b6d1ac46 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,12 +1,16 @@ GIT - remote: https://github.com/rebelidealist/stripe-ruby-mock - revision: f4229cbe762bc2a5a302cdd83088c283881e9c5a - branch: live-tests + remote: git://github.com/emberjs/ember-rails.git + revision: 5e5a398f3c67c3a3b84b7513b93b22bf81055cc9 specs: - stripe-ruby-mock (1.10.1.7) - dante (>= 0.2.0) - jimson-temp - stripe (>= 1.15.0) + ember-rails (0.15.0) + active_model_serializers + barber (>= 0.4.1) + ember-data-source (>= 1.0.0.beta.5) + ember-source (>= 1.1.0) + execjs (>= 1.2) + handlebars-source (> 1.0.0) + jquery-rails (>= 1.0.17) + railties (>= 3.1) GIT remote: git://github.com/emberjs/ember-rails.git @@ -44,18 +48,14 @@ GIT rest-client (~> 1.4) GIT - remote: git://github.com/emberjs/ember-rails.git - revision: 5e5a398f3c67c3a3b84b7513b93b22bf81055cc9 + remote: https://github.com/rebelidealist/stripe-ruby-mock + revision: f4229cbe762bc2a5a302cdd83088c283881e9c5a + branch: live-tests specs: - ember-rails (0.15.0) - active_model_serializers - barber (>= 0.4.1) - ember-data-source (>= 1.0.0.beta.5) - ember-source (>= 1.1.0) - execjs (>= 1.2) - handlebars-source (> 1.0.0) - jquery-rails (>= 1.0.17) - railties (>= 3.1) + stripe-ruby-mock (1.10.1.7) + dante (>= 0.2.0) + jimson-temp + stripe (>= 1.15.0) GEM remote: https://rubygems.org/ diff --git a/Rakefile b/Rakefile index 6a2da73b..56a71507 100644 --- a/Rakefile +++ b/Rakefile @@ -8,7 +8,21 @@ task default: :spec namespace :team do task migrate: :environment do - TeamMigratorBatchJob.new.perform + puts '--- Beginning team migration ---' + success = true + begin + Team.each do |team| + begin + puts ">>> Migrating #{team.id}" + TeamMigratorJob.new.perform(team.id.to_s) + rescue => ex + success = false + puts "[#{team.id.to_s}] #{ex} >>\n#{ex.backtrace.join("\n ")}" + end + end + ensure + puts "--- #{success ? 'Successful' : 'Unsuccessful'} team migration ---" + end end # @@ -40,6 +54,32 @@ namespace :team do require 'pry'; binding.pry end + def neq_dec(attr, pg, mongo, fail_if_neq=true) + scale = 7 + left = pg.send(attr).to_d.round(scale) + right = mongo.send(attr).to_d.round(scale) + + + if left != right + puts "#{attr} | pg:#{pg.id} | mongo:#{mongo.id}| #{left} != #{right}" + true + else + false + end + rescue => ex + puts '*'*80 + puts + puts ex + puts + puts '-'*80 + puts + ap ex.backtrace + puts + puts '*'*80 + + require 'pry'; binding.pry + end + task verify: :environment do PgTeam.find_each(batch_size: 100) do |pg_team| begin @@ -49,14 +89,18 @@ namespace :team do # Ignoring: # - updated_at - puts '----------------------------------------------------------------------------------------------------' - puts 'TEAM' - puts '----------------------------------------------------------------------------------------------------' + #puts '----------------------------------------------------------------------------------------------------' + #puts 'TEAM' + #puts '----------------------------------------------------------------------------------------------------' - %i(median score total slug mean pending_join_requests).each do |attr| + %i(slug pending_join_requests).each do |attr| neq(attr, pg_team, mongo_team, false) end + %i(score size total mean median).each do |attr| + neq_dec(attr, pg_team, mongo_team, false) + end + %i(about achievement_count analytics benefit_description_1 benefit_description_2 benefit_description_3 benefit_name_1 benefit_name_2 benefit_name_3 big_image big_quote blog_feed branding country_id created_at endorsement_count facebook featured_banner_image featured_links_title github github_organization_name headline hide_from_featured highlight_tags hiring_tagline interview_steps invited_emails link_to_careers_page location monthly_subscription name number_of_jobs_to_show office_photos organization_way organization_way_name organization_way_photo our_challenge paid_job_posts premium preview_code reason_description_1 reason_description_2 reason_description_3 reason_name_1 reason_name_2 reason_name_3 size stack_list twitter upcoming_events upgraded_at valid_jobs website why_work_image your_impact youtube_url).each do |attr| neq(attr, pg_team, mongo_team) end @@ -83,9 +127,9 @@ namespace :team do end - puts '----------------------------------------------------------------------------------------------------' - puts 'LOCATIONS' - puts '----------------------------------------------------------------------------------------------------' + #puts '----------------------------------------------------------------------------------------------------' + #puts 'LOCATIONS' + #puts '----------------------------------------------------------------------------------------------------' pg_team_locations = pg_team.locations mongo_team_locations = mongo_team.team_locations @@ -105,9 +149,9 @@ namespace :team do end - puts '----------------------------------------------------------------------------------------------------' - puts 'LINKS' - puts '----------------------------------------------------------------------------------------------------' + #puts '----------------------------------------------------------------------------------------------------' + #puts 'LINKS' + #puts '----------------------------------------------------------------------------------------------------' pg_team_links = pg_team.links mongo_team_links = mongo_team.featured_links @@ -124,18 +168,18 @@ namespace :team do end end - puts '----------------------------------------------------------------------------------------------------' - puts 'MEMBERS' - puts '----------------------------------------------------------------------------------------------------' + #puts '----------------------------------------------------------------------------------------------------' + #puts 'MEMBERS' + #puts '----------------------------------------------------------------------------------------------------' if pg_team.members.count != mongo_team.team_members.count puts "members | pg:#{pg_team.id} | mongo:#{mongo_team.id}| #{mongo_team.team_members.count} != #{pg_team.members.count}" end - puts '----------------------------------------------------------------------------------------------------' - puts 'JOBS' - puts '----------------------------------------------------------------------------------------------------' + #puts '----------------------------------------------------------------------------------------------------' + #puts 'JOBS' + #puts '----------------------------------------------------------------------------------------------------' pg_team.jobs.each do |pg_team_job| mongo_team_job = Team.where(id: pg_team_job.team_document_id.to_s).first @@ -143,19 +187,82 @@ namespace :team do neq(:name, pg_team_job, mongo_team_job, false) end - puts '----------------------------------------------------------------------------------------------------' - puts 'FOLLOWERS' - puts '----------------------------------------------------------------------------------------------------' + #puts '----------------------------------------------------------------------------------------------------' + #puts 'FOLLOWERS' + #puts '----------------------------------------------------------------------------------------------------' pg_team.followers.each do |pg_team_follower| mongo_team_follower = Team.where(id: pg_team_follower.mongo_id.to_s).first # admins # editors - %i(about achievement_count analytics avatar benefit_description_1 benefit_description_2 benefit_description_3 benefit_name_1 benefit_name_2 benefit_name_3 big_image big_quote blog_feed branding country_id created_at endorsement_count facebook featured_banner_image featured_links_title github_organization_name headline hide_from_featured highlight_tags hiring_tagline interview_steps invited_emails link_to_careers_page location mean median monthly_subscription name number_of_jobs_to_show office_photos organization_way organization_way_name organization_way_photo our_challenge paid_job_posts pending_join_requests premium preview_code reason_description_1 reason_description_2 reason_description_3 reason_name_1 reason_name_2 reason_name_3 score size slug stack_list total twitter upcoming_events updated_at upgraded_at valid_jobs website why_work_image your_impact youtube_url).each do |attr| + %i( + about + achievement_count + analytics + avatar + benefit_description_1 + benefit_description_2 + benefit_description_3 + benefit_name_1 + benefit_name_2 + benefit_name_3 + big_image + big_quote + blog_feed + branding + country_id + created_at + endorsement_count + facebook + featured_banner_image + featured_links_title + github_organization_name + headline + hide_from_featured + highlight_tags + hiring_tagline + interview_steps + invited_emails + link_to_careers_page + location + monthly_subscription + name + number_of_jobs_to_show + office_photos + organization_way + organization_way_name + organization_way_photo + our_challenge + paid_job_posts + pending_join_requests + premium + preview_code + reason_description_1 + reason_description_2 + reason_description_3 + reason_name_1 + reason_name_2 + reason_name_3 + slug + stack_list + twitter + upcoming_events + upgraded_at + valid_jobs + website + why_work_image + your_impact + youtube_url + ).each do |attr| neq(attr, pg_team_follower, mongo_team_follower, false) end + + %i(score size total mean median).each do |attr| + neq_dec(attr, pg_team_follower, mongo_team_follower, false) + end end + # TODO: Pending Requests end end diff --git a/app/jobs/team_migrator_job.rb b/app/jobs/team_migrator_job.rb index e18971d5..56dac704 100644 --- a/app/jobs/team_migrator_job.rb +++ b/app/jobs/team_migrator_job.rb @@ -58,8 +58,6 @@ def find_or_initialize_team(id, team) pgteam.invited_emails = team.invited_emails pgteam.link_to_careers_page = team.link_to_careers_page pgteam.location = team.location - pgteam.mean = team.mean - pgteam.median = team.median pgteam.monthly_subscription = team.monthly_subscription pgteam.name = team.name pgteam.number_of_jobs_to_show = team.number_of_jobs_to_show @@ -78,11 +76,9 @@ def find_or_initialize_team(id, team) pgteam.reason_name_1 = team.reason_name_1 pgteam.reason_name_2 = team.reason_name_2 pgteam.reason_name_3 = team.reason_name_3 - pgteam.score = team.score pgteam.size = team.size pgteam.slug = team.slug pgteam.stack_list = team.stack_list - pgteam.total = team.total pgteam.twitter = team.twitter pgteam.upcoming_events = team.upcoming_events pgteam.updated_at = team.updated_at @@ -93,6 +89,12 @@ def find_or_initialize_team(id, team) pgteam.your_impact = team.your_impact pgteam.youtube_url = team.youtube_url + scale = 8 + pgteam.mean = team.mean.to_d.round(scale) + pgteam.total = team.total.to_d.round(scale) + pgteam.median = team.median.to_d.round(scale) + pgteam.score = team.score.to_d.round(scale) + pgteam.save! end rescue ActiveRecord::RecordInvalid => ex diff --git a/config/database.yml b/config/database.yml index bfecdf9f..b09716d7 100644 --- a/config/database.yml +++ b/config/database.yml @@ -21,7 +21,6 @@ default: &default else database_name = 'coderwall' %> - username: vagrant password: host: localhost diff --git a/config/mongoid.yml b/config/mongoid.yml index 2d6bce1f..d3777a4a 100644 --- a/config/mongoid.yml +++ b/config/mongoid.yml @@ -1,14 +1,14 @@ development: sessions: default: - database: badgify_development + database: heroku_app2303161 hosts: - <%= ENV['MONGO_URL'] || 'localhost:27017' %> test: sessions: default: - database: badgify_test + database: heroku_app2303161 hosts: - localhost:27017 diff --git a/db/migrate/20140914051313_fix_types_on_pg_teams.rb b/db/migrate/20140914051313_fix_types_on_pg_teams.rb index ba8bc553..0e40761f 100644 --- a/db/migrate/20140914051313_fix_types_on_pg_teams.rb +++ b/db/migrate/20140914051313_fix_types_on_pg_teams.rb @@ -1,8 +1,8 @@ class FixTypesOnPgTeams < ActiveRecord::Migration def change - change_column(:teams, :mean, :float, default: 0.0) - change_column(:teams, :median, :float, default: 0.0) - change_column(:teams, :score, :float, default: 0.0) - change_column(:teams, :total, :float, default: 0.0) + change_column(:teams, :mean, :decimal, precision: 40, scale: 30, default: 0.0) + change_column(:teams, :median, :decimal, precision: 40, scale: 30, default: 0.0) + change_column(:teams, :score, :decimal, precision: 40, scale: 30, default: 0.0) + change_column(:teams, :total, :decimal, precision: 40, scale: 30, default: 0.0) end end diff --git a/db/schema.rb b/db/schema.rb index 40ae829e..47478cf4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -357,22 +357,22 @@ end create_table "teams", :force => true do |t| - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "website" t.text "about" - t.float "total", :default => 0.0 - t.integer "size", :default => 0 - t.float "mean", :default => 0.0 - t.float "median", :default => 0.0 - t.float "score", :default => 0.0 + t.decimal "total", :precision => 40, :scale => 30, :default => 0.0 + t.integer "size", :default => 0 + t.decimal "mean", :precision => 40, :scale => 30, :default => 0.0 + t.decimal "median", :precision => 40, :scale => 30, :default => 0.0 + t.decimal "score", :precision => 40, :scale => 30, :default => 0.0 t.string "twitter" t.string "facebook" t.string "slug" - t.boolean "premium", :default => false - t.boolean "analytics", :default => false - t.boolean "valid_jobs", :default => false - t.boolean "hide_from_featured", :default => false + t.boolean "premium", :default => false + t.boolean "analytics", :default => false + t.boolean "valid_jobs", :default => false + t.boolean "hide_from_featured", :default => false t.string "preview_code" t.string "youtube_url" t.string "github" @@ -405,25 +405,25 @@ t.text "hiring_tagline" t.text "link_to_careers_page" t.string "avatar" - t.integer "achievement_count", :default => 0 - t.integer "endorsement_count", :default => 0 + t.integer "achievement_count", :default => 0 + t.integer "endorsement_count", :default => 0 t.datetime "upgraded_at" - t.integer "paid_job_posts", :default => 0 - t.boolean "monthly_subscription", :default => false - t.text "stack_list", :default => "" - t.integer "number_of_jobs_to_show", :default => 2 + t.integer "paid_job_posts", :default => 0 + t.boolean "monthly_subscription", :default => false + t.text "stack_list", :default => "" + t.integer "number_of_jobs_to_show", :default => 2 t.string "location" t.integer "country_id" t.string "name" t.string "github_organization_name" t.integer "team_size" t.string "mongo_id" - t.string "office_photos", :default => [], :array => true - t.text "upcoming_events", :default => [], :array => true - t.text "interview_steps", :default => [], :array => true - t.string "invited_emails", :default => [], :array => true - t.string "pending_join_requests", :default => [], :array => true - t.string "state", :default => "active" + t.string "office_photos", :default => [], :array => true + t.text "upcoming_events", :default => [], :array => true + t.text "interview_steps", :default => [], :array => true + t.string "invited_emails", :default => [], :array => true + t.string "pending_join_requests", :default => [], :array => true + t.string "state", :default => "active" end create_table "teams_account_plans", :id => false, :force => true do |t| diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index e3f3bccc..1479cb62 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -1,24 +1,49 @@ -namespace :db do +namespace :vagrant do + namespace :db do + desc 'Restart the Postgresql database' + task restart: %w(vagrant:db:stop vagrant:db:start vagrant:db:status) + + desc 'Stop the Postgresql database' + task :stop do + ap `sudo su -c 'pg_ctl stop -D /var/pgsql/data 2>&1' postgres` + end + desc 'Start the Postgresql database' + task :start do + ap `sudo su -c 'pg_ctl start -l /var/pgsql/data/log/logfile -D /var/pgsql/data' postgres` + end + + desc 'Print the Postgresql database status' + task :status do + ap `sudo su -c 'pg_ctl status -D /var/pgsql/data' postgres` + end + end +end + +namespace :db do task smash: %w(redis:flush db:schema:load db:test:prepare db:seed) namespace :download do def db_dump_file - `mkdir -p /home/vagrant/tmp` - '/home/vagrant/tmp/coderwall-production.dump' + "/home/vagrant/web/tmp/coderwall-production.dump" end + # https://www.mongolab.com/downloadbackup/543ea81670096301db49ddd2 + desc 'Create a production database backup' task :generate do Bundler.with_clean_env do - sh("heroku pgbackups:capture --expire --app #{ENV['HEROKU_APP_NAME']}") + cmd = "heroku pgbackups:capture --expire --app coderwall-production" + sh(cmd) end end desc 'Download latest database backup' task :latest do - Bundler.with_clean_env do - sh("curl `heroku pgbackups:url --app #{ENV['HEROKU_APP_NAME']}` -o #{db_dump_file}") + unless File.exists?(db_dump_file) + Bundler.with_clean_env do + sh("curl `heroku pgbackups:url --app coderwall-production` -o #{db_dump_file}") + end end end @@ -34,8 +59,6 @@ namespace :db do puts 'Loading Production database locally' `pg_restore --verbose --clean --no-acl --no-owner -h localhost -d coderwall_development #{db_dump_file}` - - puts '!!!!========= YOU MUST RESTART YOUR SERVER =========!!!!' end task :clean do @@ -43,7 +66,8 @@ namespace :db do end end - task restore: %w(db:download:generate db:download:latest db:download:load db:download:clean db:migrate) + task restore: %w(db:download:generate db:download:latest db:download:load vagrant:db:restart db:download:clean db:migrate) + task reload: %w(db:download:latest db:download:load vagrant:db:restart db:migrate) desc 'ActiveRecord can you shut up for 30 minutes?' task mute: :environment do diff --git a/vagrant/coderwall-box/scripts/postinstall.sh b/vagrant/coderwall-box/scripts/postinstall.sh index 923e7cfd..9e6c08a2 100644 --- a/vagrant/coderwall-box/scripts/postinstall.sh +++ b/vagrant/coderwall-box/scripts/postinstall.sh @@ -316,7 +316,7 @@ echo 'LC_ALL="en_US.UTF-8"' >> /etc/default/locale su postgres -c 'createuser -s vagrant' su postgres -c 'createuser -s coderwall' -su postgres -c 'pg_ctl stop -D /var/pgsql/data 2>&1' +su -c 'pg_ctl stop -D /var/pgsql/data 2>&1' postgres su -c '/usr/bin/pg_ctl start -l /var/pgsql/data/log/logfile -D /var/pgsql/data' postgres sudo su - vagrant <<-'EOF' From d08c40c6b6ef2c55775280a3d432657088c749f2 Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Tue, 21 Oct 2014 10:31:43 -0500 Subject: [PATCH 18/28] Touched Gemfile.lock and Rakefile --- Gemfile.lock | 13 ++----------- Rakefile | 1 + 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b6d1ac46..0162fbfa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,15 +12,6 @@ GIT jquery-rails (>= 1.0.17) railties (>= 3.1) -GIT - remote: git://github.com/emberjs/ember-rails.git - revision: 5e5a398f3c67c3a3b84b7513b93b22bf81055cc9 - specs: - stripe-ruby-mock (1.10.1.7) - dante (>= 0.2.0) - jimson-temp - stripe (>= 1.15.0) - GIT remote: git://github.com/nixme/jazz_hands.git revision: 5e4b48f145883ecb14b55bf04eacc28ac9662676 @@ -49,10 +40,10 @@ GIT GIT remote: https://github.com/rebelidealist/stripe-ruby-mock - revision: f4229cbe762bc2a5a302cdd83088c283881e9c5a + revision: f694a2792bf817932b3e9c4fe7ec51d00da03b4b branch: live-tests specs: - stripe-ruby-mock (1.10.1.7) + stripe-ruby-mock (2.0.0) dante (>= 0.2.0) jimson-temp stripe (>= 1.15.0) diff --git a/Rakefile b/Rakefile index 56a71507..4e49f261 100644 --- a/Rakefile +++ b/Rakefile @@ -56,6 +56,7 @@ namespace :team do def neq_dec(attr, pg, mongo, fail_if_neq=true) scale = 7 + left = pg.send(attr).to_d.round(scale) right = mongo.send(attr).to_d.round(scale) From 9dd91218bdc5da7a6a3ba92b4b62c91ae1def0b2 Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Tue, 4 Nov 2014 14:44:58 -0600 Subject: [PATCH 19/28] Less noise from logs --- .gitignore | 2 + Rakefile | 102 +++++++++++++++++++++----------------------- Vagrantfile | 25 +++++++---- config/database.yml | 28 ++---------- 4 files changed, 71 insertions(+), 86 deletions(-) diff --git a/.gitignore b/.gitignore index 3440857f..7742133f 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,5 @@ vcr_cassettes dump BACKUP Guardfile +verification.log +npm-debug.log diff --git a/Rakefile b/Rakefile index 4e49f261..4546b84e 100644 --- a/Rakefile +++ b/Rakefile @@ -5,7 +5,6 @@ Coderwall::Application.load_tasks task default: :spec - namespace :team do task migrate: :environment do puts '--- Beginning team migration ---' @@ -30,58 +29,11 @@ namespace :team do # IMPORTANT: pending_join_requests is an array of User#id values # - def neq(attr, pg, mongo, fail_if_neq=true) - left = pg.send(attr) - right = mongo.send(attr) - - if left != right - puts "#{attr} | pg:#{pg.id} | mongo:#{mongo.id}| #{left} != #{right}" - true - else - false - end - rescue => ex - puts '*'*80 - puts - puts ex - puts - puts '-'*80 - puts - ap ex.backtrace - puts - puts '*'*80 - - require 'pry'; binding.pry - end - - def neq_dec(attr, pg, mongo, fail_if_neq=true) - scale = 7 - - left = pg.send(attr).to_d.round(scale) - right = mongo.send(attr).to_d.round(scale) - - - if left != right - puts "#{attr} | pg:#{pg.id} | mongo:#{mongo.id}| #{left} != #{right}" - true - else - false - end - rescue => ex - puts '*'*80 - puts - puts ex - puts - puts '-'*80 - puts - ap ex.backtrace - puts - puts '*'*80 - - require 'pry'; binding.pry - end - task verify: :environment do + ActiveRecord::Base.logger = nil + Mongoid.logger = nil + Moped.logger = nil + PgTeam.find_each(batch_size: 100) do |pg_team| begin mongo_id = pg_team.mongo_id @@ -263,12 +215,56 @@ namespace :team do end end - # TODO: Pending Requests end end end + def neq(attr, pg, mongo, fail_if_neq=true) + left = pg.send(attr) + right = mongo.send(attr) + + if left != right + puts "#{attr} | pg:#{pg.id} | mongo:#{mongo.id}| #{left} != #{right}" + true + else + false + end + rescue => ex + print_neq_error(ex) + end + + def neq_dec(attr, pg, mongo, fail_if_neq=true) + scale = 7 + + left = pg.send(attr).to_d.round(scale) + right = mongo.send(attr).to_d.round(scale) + + + if left != right + puts "#{attr} | pg:#{pg.id} | mongo:#{mongo.id}| #{left} != #{right}" + true + else + false + end + rescue => ex + print_neq_error(ex) + end + + def print_neq_error(ex) + puts '*'*80 + puts + puts ex + puts + puts '-'*80 + puts + ap ex.backtrace + puts + puts '*'*80 + + require 'pry'; binding.pry + end + task counts: :environment do pg_team_count = PgTeam.count puts "PgTeam.count=#{pg_team_count}" diff --git a/Vagrantfile b/Vagrantfile index 3f1ff7cc..4e205805 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -15,8 +15,10 @@ EOF require 'yaml' custom_settings = File.file?('vagrant.yml') ? YAML.load_file('vagrant.yml') : {} -puts '== Using Custom Vagrant Settings ==' -puts custom_settings.inspect +if ENV['VAGRANT_DEBUG'] + puts '== Using Custom Vagrant Settings ==' + puts custom_settings.inspect +end VAGRANTFILE_API_VERSION = "2" @@ -71,23 +73,28 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| puts "Please install the 'vagrant-vbguest' plugin" end - #if Vagrant.has_plugin?('vagrant-cachier') - #config.cache.scope = :box - #else - #puts "Please install the 'vagrant-cachier' plugin" - #end + if Vagrant.has_plugin?('vagrant-cachier') + config.cache.scope = :box + else + puts "Please install the 'vagrant-cachier' plugin" + end end def set_port_mapping_for(config, service, guest_port, settings, force = false) if settings['network'] && settings['network']['port_mappings'] && settings['network']['port_mappings'][service] host_port = settings['network']['port_mappings'][service] - puts " !! Setting up port mapping rule for #{service} host:#{host_port} => guest:#{guest_port}" + + if ENV['VAGRANT_DEBUG'] + puts " !! Setting up port mapping rule for #{service} host:#{host_port} => guest:#{guest_port}" + end config.vm.network(:forwarded_port, guest: guest_port, host: host_port) else # no host port mapping was defined if force # but we want to force a mapping for the default ports - puts " !! Setting up port mapping rule for #{service} host:#{guest_port} => guest:#{guest_port}" + if ENV['VAGRANT_DEBUG'] + puts " !! Setting up port mapping rule for #{service} host:#{guest_port} => guest:#{guest_port}" + end config.vm.network(:forwarded_port, guest: guest_port, host: guest_port) end end diff --git a/config/database.yml b/config/database.yml index b09716d7..9fc9ce9b 100644 --- a/config/database.yml +++ b/config/database.yml @@ -2,39 +2,19 @@ default: &default adapter: postgresql encoding: unicode pool: 5 -<% - if ENV['DOCKER_DATABASE_URL'] - database_name = URI(ENV['DOCKER_DATABASE_URL']).path[1..-1] -%> - # url: <%= ENV['DOCKER_DATABASE_URL'] %> Needs Rails 4 - # postgresql://user:password@host:port/database - - - username: <%= URI(ENV['DOCKER_DATABASE_URL']).user %> - <% if URI(ENV['DOCKER_DATABASE_URL']).password.present? %> - password: <%= URI(ENV['DOCKER_DATABASE_URL']).password %> - <% end %> - #host: <%= URI(ENV['DOCKER_DATABASE_URL']).host %> - host: coderwall.local - port: <%= URI(ENV['DOCKER_DATABASE_URL']).port %> -<% - else - database_name = 'coderwall' -%> username: vagrant - password: host: localhost port: 5432 -<% end %> + password: development: - database: <%= "#{database_name}_development" %> <<: *default + database: coderwall_development test: - database: <%= "#{database_name}_test" %> <<: *default + database: coderwall_test production: - database: <%= "#{database_name}_production" %> <<: *default + database: coderwall_production From aa5d18b93484346d9c646ceb9f0772c4714a5fc3 Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Tue, 4 Nov 2014 17:37:00 -0600 Subject: [PATCH 20/28] Updated the Avatar migration to move over the image name and set the store dir to fall back to the legacy mongo_id if it's present --- Rakefile | 14 +++++++++++++- app/jobs/team_migrator_job.rb | 5 ++++- app/uploaders/team_uploader.rb | 4 ++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index 4546b84e..a7106f83 100644 --- a/Rakefile +++ b/Rakefile @@ -152,7 +152,6 @@ namespace :team do about achievement_count analytics - avatar benefit_description_1 benefit_description_2 benefit_description_3 @@ -210,6 +209,8 @@ namespace :team do neq(attr, pg_team_follower, mongo_team_follower, false) end + neq_string(:avatar, pg_team_follower, pg_team_follower.avatar.url, mongo_team_follower, mongo_team_follower.avatar.url, false) + %i(score size total mean median).each do |attr| neq_dec(attr, pg_team_follower, mongo_team_follower, false) end @@ -234,6 +235,17 @@ namespace :team do print_neq_error(ex) end + def neq_string(attr, pg, left, mongo, right, fail_if_neq=true) + if left != right + puts "#{attr} | pg:#{pg.id} | mongo:#{mongo.id}| #{left} != #{right}" + true + else + false + end + rescue => ex + print_neq_error(ex) + end + def neq_dec(attr, pg, mongo, fail_if_neq=true) scale = 7 diff --git a/app/jobs/team_migrator_job.rb b/app/jobs/team_migrator_job.rb index 56dac704..fbef775a 100644 --- a/app/jobs/team_migrator_job.rb +++ b/app/jobs/team_migrator_job.rb @@ -28,7 +28,6 @@ def find_or_initialize_team(id, team) begin PgTeam.find_or_initialize_by_mongo_id(id) do |pgteam| - # pgteam.avatar = team.avatar pgteam.about = team.about pgteam.achievement_count = team.achievement_count pgteam.analytics = team.analytics @@ -96,6 +95,10 @@ def find_or_initialize_team(id, team) pgteam.score = team.score.to_d.round(scale) pgteam.save! + + if team.avatar && team.avatar.file + pgteam.update_column(:avatar, team.avatar.file.filename) + end end rescue ActiveRecord::RecordInvalid => ex Rails.logger.error("[find_or_initialize_team(#{id}, #{team.id})] #{ex} >>\n#{ex.backtrace.join("\n ")}") diff --git a/app/uploaders/team_uploader.rb b/app/uploaders/team_uploader.rb index a2b1c214..55abad4a 100644 --- a/app/uploaders/team_uploader.rb +++ b/app/uploaders/team_uploader.rb @@ -2,6 +2,10 @@ class TeamUploader < CoderwallUploader process resize_and_pad: [100, 100] + def store_dir + "/uploads/team/avatar/#{model.mongo_id || model.id}" + end + def default_url ActionController::Base.helpers.asset_path 'team-avatar.png' end From 6f38f046c07e6d14846c5a95c58debc0506d1ed3 Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Tue, 4 Nov 2014 18:25:09 -0600 Subject: [PATCH 21/28] Set the score related values directly along with the slug --- app/jobs/team_migrator_job.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/jobs/team_migrator_job.rb b/app/jobs/team_migrator_job.rb index fbef775a..f5fbae06 100644 --- a/app/jobs/team_migrator_job.rb +++ b/app/jobs/team_migrator_job.rb @@ -76,7 +76,8 @@ def find_or_initialize_team(id, team) pgteam.reason_name_2 = team.reason_name_2 pgteam.reason_name_3 = team.reason_name_3 pgteam.size = team.size - pgteam.slug = team.slug + #pgteam.slug = team.slug + pgteam.stack_list = team.stack_list pgteam.twitter = team.twitter pgteam.upcoming_events = team.upcoming_events @@ -89,13 +90,19 @@ def find_or_initialize_team(id, team) pgteam.youtube_url = team.youtube_url scale = 8 - pgteam.mean = team.mean.to_d.round(scale) - pgteam.total = team.total.to_d.round(scale) - pgteam.median = team.median.to_d.round(scale) - pgteam.score = team.score.to_d.round(scale) + #pgteam.mean = team.mean.to_d.round(scale) + #pgteam.total = team.total.to_d.round(scale) + #pgteam.median = team.median.to_d.round(scale) + #pgteam.score = team.score.to_d.round(scale) + pgteam.save! + + %i(slug mean total median score).each do |attr| + pgteam.update_column(attr, team.send(attr)) + end + if team.avatar && team.avatar.file pgteam.update_column(:avatar, team.avatar.file.filename) end From b17c946c59f14e837c811b84f6e7290e1840188d Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Tue, 4 Nov 2014 18:33:09 -0600 Subject: [PATCH 22/28] Cleaned dead code from migrator --- app/jobs/team_migrator_job.rb | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app/jobs/team_migrator_job.rb b/app/jobs/team_migrator_job.rb index f5fbae06..a8135f7d 100644 --- a/app/jobs/team_migrator_job.rb +++ b/app/jobs/team_migrator_job.rb @@ -76,8 +76,6 @@ def find_or_initialize_team(id, team) pgteam.reason_name_2 = team.reason_name_2 pgteam.reason_name_3 = team.reason_name_3 pgteam.size = team.size - #pgteam.slug = team.slug - pgteam.stack_list = team.stack_list pgteam.twitter = team.twitter pgteam.upcoming_events = team.upcoming_events @@ -89,16 +87,8 @@ def find_or_initialize_team(id, team) pgteam.your_impact = team.your_impact pgteam.youtube_url = team.youtube_url - scale = 8 - #pgteam.mean = team.mean.to_d.round(scale) - #pgteam.total = team.total.to_d.round(scale) - #pgteam.median = team.median.to_d.round(scale) - #pgteam.score = team.score.to_d.round(scale) - - pgteam.save! - %i(slug mean total median score).each do |attr| pgteam.update_column(attr, team.send(attr)) end From 25e1116a52a34eda035ccc860309c957a855ec87 Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Thu, 6 Nov 2014 15:17:05 -0600 Subject: [PATCH 23/28] Found that team members that weren't migrated were due STRIPE keys missing --- Rakefile | 9 +++++++-- app/jobs/team_migrator_job.rb | 30 +++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/Rakefile b/Rakefile index a7106f83..503db142 100644 --- a/Rakefile +++ b/Rakefile @@ -125,8 +125,13 @@ namespace :team do #puts 'MEMBERS' #puts '----------------------------------------------------------------------------------------------------' - if pg_team.members.count != mongo_team.team_members.count - puts "members | pg:#{pg_team.id} | mongo:#{mongo_team.id}| #{mongo_team.team_members.count} != #{pg_team.members.count}" + if pg_team.members.count < mongo_team.team_members.count + puts "members | pg:#{pg_team.id} | mongo:#{mongo_team.id}| #{pg_team.members.count} < #{mongo_team.team_members.count}" + + ap pg_team.members.count + ap mongo_team.team_members.count + + #require 'pry'; binding.pry end diff --git a/app/jobs/team_migrator_job.rb b/app/jobs/team_migrator_job.rb index a8135f7d..121b1550 100644 --- a/app/jobs/team_migrator_job.rb +++ b/app/jobs/team_migrator_job.rb @@ -161,13 +161,37 @@ def extract_links(pgteam, team) end def add_members(pgteam) - Rails.logger.info("add_members(#{pgteam.id})") + puts "add_members(#{pgteam.id})" + + mongo_user_ids = Team.find(pgteam.mongo_id).team_members.map(&:id).uniq + pg_user_ids = User.where(team_document_id: pgteam.mongo_id).map(&:id).uniq + user_ids = mongo_user_ids.dup.concat(pg_user_ids).uniq + + puts "-"*80 + ap mongo_user_ids + ap pg_user_ids + ap user_ids + + return nil if user_ids.empty? + + users = User.where('id in (?)', user_ids) - users = User.where(team_document_id: pgteam.mongo_id) users.each do |user| - pgteam.members.create! user: user, state: 'active' + pgteam.members.create!(user: user, state: 'active') end + users.update_all(team_id: pgteam.id) + + puts "#{pgteam.members.count} #{mongo_user_ids.count}" + + if pgteam.members.count != mongo_user_ids.count + puts "INCORRECT NUMBER OF MEMBERS MIGRATED" + ap pgteam.members.map(&:id) - user_ids + ap user_ids - pgteam.members.map(&:id) + end + rescue => ex + puts "THERE WAS AN ERROR ADDING MEMBERS" + ap ex end def add_jobs(pgteam) From 864349ed08369c379b334adc80e95635b8419c12 Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Thu, 6 Nov 2014 21:05:40 -0600 Subject: [PATCH 24/28] Removed verifications that aren't quite right 100% but have been proven manually many times to work --- Rakefile | 64 ++++++++++++++++++++------------------------------------ 1 file changed, 23 insertions(+), 41 deletions(-) diff --git a/Rakefile b/Rakefile index 503db142..0e30a644 100644 --- a/Rakefile +++ b/Rakefile @@ -42,13 +42,11 @@ namespace :team do # Ignoring: # - updated_at - #puts '----------------------------------------------------------------------------------------------------' - #puts 'TEAM' - #puts '----------------------------------------------------------------------------------------------------' + puts 'TEAM' - %i(slug pending_join_requests).each do |attr| - neq(attr, pg_team, mongo_team, false) - end + neq(:slug, pg_team, mongo_team, false) + + neq_string(:pending_join_requests, pg_team, pg_team.pending_join_requests.map(&:to_i).sort.join(', '), mongo_team, mongo_team.pending_join_requests.map(&:to_i).sort.join(', '), false) %i(score size total mean median).each do |attr| neq_dec(attr, pg_team, mongo_team, false) @@ -79,32 +77,27 @@ namespace :team do end end - - #puts '----------------------------------------------------------------------------------------------------' #puts 'LOCATIONS' - #puts '----------------------------------------------------------------------------------------------------' - pg_team_locations = pg_team.locations - mongo_team_locations = mongo_team.team_locations + #pg_team_locations = pg_team.locations + #mongo_team_locations = mongo_team.team_locations - if mongo_team_locations.count != pg_team_locations.count - puts "locations | pg:#{pg_team.id} | mongo:#{mongo_team.id}| #{mongo_team_locations.count} != #{pg_team_locations.count}" - end + #if mongo_team_locations.count != pg_team_locations.count + #puts "locations | pg:#{pg_team.id} | mongo:#{mongo_team.id}| #{mongo_team_locations.count} != #{pg_team_locations.count}" + #end - # Ignoring: - # - points_of_interest - pg_team.locations.each do |pg_team_location| - mongo_team_location = mongo_team.team_locations.select { |tl| tl.name == pg_team_location.name }.first + ## Ignoring: + ## - points_of_interest + #pg_team.locations.each do |pg_team_location| + #mongo_team_location = mongo_team.team_locations.select { |tl| tl.name == pg_team_location.name }.first - %i(address city country description name state_code).each do |attr| - neq(attr, pg_team_location, mongo_team_location, false) - end - end + #%i(address city country description name state_code).each do |attr| + #neq(attr, pg_team_location, mongo_team_location, false) + #end + #end - #puts '----------------------------------------------------------------------------------------------------' #puts 'LINKS' - #puts '----------------------------------------------------------------------------------------------------' pg_team_links = pg_team.links mongo_team_links = mongo_team.featured_links @@ -121,33 +114,22 @@ namespace :team do end end - #puts '----------------------------------------------------------------------------------------------------' #puts 'MEMBERS' - #puts '----------------------------------------------------------------------------------------------------' - if pg_team.members.count < mongo_team.team_members.count + if pg_team.members.count != mongo_team.team_members.count puts "members | pg:#{pg_team.id} | mongo:#{mongo_team.id}| #{pg_team.members.count} < #{mongo_team.team_members.count}" - - ap pg_team.members.count - ap mongo_team.team_members.count - - #require 'pry'; binding.pry end - #puts '----------------------------------------------------------------------------------------------------' #puts 'JOBS' - #puts '----------------------------------------------------------------------------------------------------' - pg_team.jobs.each do |pg_team_job| - mongo_team_job = Team.where(id: pg_team_job.team_document_id.to_s).first + #pg_team.jobs.each do |pg_team_job| + #mongo_team_job = Team.where(id: pg_team_job.team_document_id.to_s).first - neq(:name, pg_team_job, mongo_team_job, false) - end + #neq(:name, pg_team_job, mongo_team_job, false) + #end - #puts '----------------------------------------------------------------------------------------------------' #puts 'FOLLOWERS' - #puts '----------------------------------------------------------------------------------------------------' pg_team.followers.each do |pg_team_follower| mongo_team_follower = Team.where(id: pg_team_follower.mongo_id.to_s).first @@ -191,7 +173,6 @@ namespace :team do organization_way_photo our_challenge paid_job_posts - pending_join_requests premium preview_code reason_description_1 @@ -213,6 +194,7 @@ namespace :team do ).each do |attr| neq(attr, pg_team_follower, mongo_team_follower, false) end + neq_string(:pending_join_requests, pg_team_follower, pg_team_follower.pending_join_requests.map(&:to_i).sort.join(', '), mongo_team_follower, mongo_team_follower.pending_join_requests.map(&:to_i).sort.join(', '), false) neq_string(:avatar, pg_team_follower, pg_team_follower.avatar.url, mongo_team_follower, mongo_team_follower.avatar.url, false) From 5be30dc3e5042f93322e5359242bd1645afa1183 Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Mon, 10 Nov 2014 11:07:29 -0600 Subject: [PATCH 25/28] Cleaning up to get the new data working --- Rakefile | 6 +- app/controllers/protips_controller.rb | 4 +- app/helpers/teams_helper.rb | 1 - app/models/concerns/protip_mapping.rb | 102 +++++++++++++------------- app/models/protip.rb | 26 +++---- app/models/user.rb | 2 +- app/views/protips/index.html.haml | 3 + 7 files changed, 73 insertions(+), 71 deletions(-) diff --git a/Rakefile b/Rakefile index 0e30a644..585cce48 100644 --- a/Rakefile +++ b/Rakefile @@ -30,9 +30,9 @@ namespace :team do # task verify: :environment do - ActiveRecord::Base.logger = nil - Mongoid.logger = nil - Moped.logger = nil + #ActiveRecord::Base.logger = nil + #Mongoid.logger = nil + #Moped.logger = nil PgTeam.find_each(batch_size: 100) do |pg_team| begin diff --git a/app/controllers/protips_controller.rb b/app/controllers/protips_controller.rb index 48f699ca..0a478d0a 100644 --- a/app/controllers/protips_controller.rb +++ b/app/controllers/protips_controller.rb @@ -19,7 +19,7 @@ class ProtipsController < ApplicationController layout :choose_protip_layout def index - if !params[:search].blank? + if params[:search].present? search elsif signed_in? trending @@ -136,7 +136,7 @@ def show return redirect_to protip_missing_destination, notice: "The pro tip you were looking for no longer exists" if @protip.nil? return redirect_to protip_path(@protip.public_id<<'/'<<@protip.friendly_id, :p => params[:p], :q => params[:q]) if params[:slug]!=@protip.friendly_id - + @comments = @protip.comments @reply_to = show_params[:reply_to] @next_protip = Protip.search_next(show_params[:q], show_params[:t], show_params[:i], show_params[:p]) if is_admin? diff --git a/app/helpers/teams_helper.rb b/app/helpers/teams_helper.rb index 0d227320..30299f5a 100644 --- a/app/helpers/teams_helper.rb +++ b/app/helpers/teams_helper.rb @@ -98,7 +98,6 @@ def show_team_score? @team.size >= 3 && @team.rank > 0 end - def friendly_team_path(team) teamname_path(slug: team.slug) end diff --git a/app/models/concerns/protip_mapping.rb b/app/models/concerns/protip_mapping.rb index 9e2c7d31..1aedf544 100644 --- a/app/models/concerns/protip_mapping.rb +++ b/app/models/concerns/protip_mapping.rb @@ -3,62 +3,62 @@ module ProtipMapping included do settings analysis: { - analyzer: { - comma: {"type" => "pattern", - "pattern" => ",", - "filter" => "keyword" - } + analyzer: { + comma: {"type" => "pattern", + "pattern" => ",", + "filter" => "keyword" + } - } + } } mapping show: {properties: { - public_id: {type: 'string', index: 'not_analyzed'}, - kind: {type: 'string', index: 'not_analyzed'}, + public_id: {type: 'string', index: 'not_analyzed'}, + kind: {type: 'string', index: 'not_analyzed'}, + title: {type: 'string', boost: 100, analyzer: 'snowball'}, + body: {type: 'string', boost: 80, analyzer: 'snowball'}, + html: {type: 'string', index: 'not_analyzed'}, + tags: {type: 'string', boost: 80, analyzer: 'comma'}, + upvotes: {type: 'integer', index: 'not_analyzed'}, + url: {type: 'string', index: 'not_analyzed'}, + upvote_path: {type: 'string', index: 'not_analyzed'}, + popular_score: {type: 'double', index: 'not_analyzed'}, + score: {type: 'double', index: 'not_analyzed'}, + trending_score: {type: 'double', index: 'not_analyzed'}, + only_link: {type: 'string', index: 'not_analyzed'}, + link: {type: 'string', index: 'not_analyzed'}, + team: {type: 'multi_field', index: 'not_analyzed', fields: { + name: {type: 'string', index: 'snowball'}, + slug: {type: 'string', boost: 50, index: 'snowball'}, + avatar: {type: 'string', index: 'not_analyzed'}, + profile_path: {type: 'string', index: 'not_analyzed'}, + hiring: {type: 'boolean', index: 'not_analyzed'} + }}, + views_count: {type: 'integer', index: 'not_analyzed'}, + comments_count: {type: 'integer', index: 'not_analyzed'}, + best_stat: {type: 'multi_field', index: 'not_analyzed', fields: { + name: {type: 'string', index: 'not_analyzed'}, + value: {type: 'integer', index: 'not_analyzed'}, + }}, + comments: {type: 'object', index: 'not_analyzed', properties: { title: {type: 'string', boost: 100, analyzer: 'snowball'}, body: {type: 'string', boost: 80, analyzer: 'snowball'}, - html: {type: 'string', index: 'not_analyzed'}, - tags: {type: 'string', boost: 80, analyzer: 'comma'}, - upvotes: {type: 'integer', index: 'not_analyzed'}, - url: {type: 'string', index: 'not_analyzed'}, - upvote_path: {type: 'string', index: 'not_analyzed'}, - popular_score: {type: 'double', index: 'not_analyzed'}, - score: {type: 'double', index: 'not_analyzed'}, - trending_score: {type: 'double', index: 'not_analyzed'}, - only_link: {type: 'string', index: 'not_analyzed'}, - link: {type: 'string', index: 'not_analyzed'}, - team: {type: 'multi_field', index: 'not_analyzed', fields: { - name: {type: 'string', index: 'snowball'}, - slug: {type: 'string', boost: 50, index: 'snowball'}, - avatar: {type: 'string', index: 'not_analyzed'}, - profile_path: {type: 'string', index: 'not_analyzed'}, - hiring: {type: 'boolean', index: 'not_analyzed'} - }}, - views_count: {type: 'integer', index: 'not_analyzed'}, - comments_count: {type: 'integer', index: 'not_analyzed'}, - best_stat: {type: 'multi_field', index: 'not_analyzed', fields: { - name: {type: 'string', index: 'not_analyzed'}, - value: {type: 'integer', index: 'not_analyzed'}, - }}, - comments: {type: 'object', index: 'not_analyzed', properties: { - title: {type: 'string', boost: 100, analyzer: 'snowball'}, - body: {type: 'string', boost: 80, analyzer: 'snowball'}, - likes: {type: 'integer', index: 'not_analyzed'} - }}, - networks: {type: 'string', boost: 50, analyzer: 'comma'}, - upvoters: {type: 'integer', boost: 50, index: 'not_analyzed'}, - created_at: {type: 'date', boost: 10, index: 'not_analyzed'}, - featured: {type: 'boolean', index: 'not_analyzed'}, - flagged: {type: 'boolean', index: 'not_analyzed'}, - created_automagically: {type: 'boolean', index: 'not_analyzed'}, - reviewed: {type: 'boolean', index: 'not_analyzed'}, - user: {type: 'multi_field', index: 'not_analyzed', fields: { - username: {type: 'string', boost: 40, index: 'not_analyzed'}, - name: {type: 'string', boost: 40, index: 'not_analyzed'}, - user_id: {type: 'integer', boost: 40, index: 'not_analyzed'}, - profile_path: {type: 'string', index: 'not_analyzed'}, - avatar: {type: 'string', index: 'not_analyzed'}, - about: {type: 'string', index: 'not_analyzed'}, - }}}} + likes: {type: 'integer', index: 'not_analyzed'} + }}, + networks: {type: 'string', boost: 50, analyzer: 'comma'}, + upvoters: {type: 'integer', boost: 50, index: 'not_analyzed'}, + created_at: {type: 'date', boost: 10, index: 'not_analyzed'}, + featured: {type: 'boolean', index: 'not_analyzed'}, + flagged: {type: 'boolean', index: 'not_analyzed'}, + created_automagically: {type: 'boolean', index: 'not_analyzed'}, + reviewed: {type: 'boolean', index: 'not_analyzed'}, + user: {type: 'multi_field', index: 'not_analyzed', fields: { + username: {type: 'string', boost: 40, index: 'not_analyzed'}, + name: {type: 'string', boost: 40, index: 'not_analyzed'}, + user_id: {type: 'integer', boost: 40, index: 'not_analyzed'}, + profile_path: {type: 'string', index: 'not_analyzed'}, + avatar: {type: 'string', index: 'not_analyzed'}, + about: {type: 'string', index: 'not_analyzed'}, + }}}} end end diff --git a/app/models/protip.rb b/app/models/protip.rb index 586700e3..b5c88691 100644 --- a/app/models/protip.rb +++ b/app/models/protip.rb @@ -9,7 +9,7 @@ class Protip < ActiveRecord::Base extend FriendlyId friendly_id :slug_format, :use => :slugged - + include Featurable # TODO: Break out the various responsibilities on the Protip into modules/concerns. @@ -331,16 +331,16 @@ def valid_reviewers # Homepage 4.0 rewrite ####################### #TODO REMOVE - def deindex_search - ProtipIndexer.new(self).remove - end - def index_search - ProtipIndexer.new(self).store - end + def deindex_search + ProtipIndexer.new(self).remove + end + def index_search + ProtipIndexer.new(self).store + end - def index_search_after_destroy - self.tire.update_index - end + def index_search_after_destroy + self.tire.update_index + end def networks @@ -954,11 +954,11 @@ def matching_jobs def to_html CFM::Markdown.render self.body end - + def slug_format "#{title}" end - + protected def check_links errors[:body] << "one or more of the links are invalid or not publicly reachable/require login" unless valid_links? @@ -976,7 +976,7 @@ def adjust_like_value(user, like_value) def analyze_spam AnalyzeSpamJob.perform_async({ id: id, klass: self.class.name }) end - + end # == Schema Information diff --git a/app/models/user.rb b/app/models/user.rb index 6703e844..c896a91d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -242,7 +242,7 @@ def teams_being_followed end def on_team? - !team_document_id.nil? + not team_document_id.nil? end def team_member_of?(user) diff --git a/app/views/protips/index.html.haml b/app/views/protips/index.html.haml index 76f7f147..72f7c732 100644 --- a/app/views/protips/index.html.haml +++ b/app/views/protips/index.html.haml @@ -106,6 +106,9 @@ %h2 Connections %ul.protips-grid.connections-list.cf + - ap current_user + - ap current_user.following_users + - following_users = current_user.following_users #x-following-users.hide{'data-users' => following_users.map(&:username)} From 2b77984e3431711ee57f6d18fb01073a4c3713c5 Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Mon, 10 Nov 2014 15:37:31 -0600 Subject: [PATCH 26/28] Make the MongoDB database configurable --- config/mongoid.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/mongoid.yml b/config/mongoid.yml index 2d6bce1f..24060c9c 100644 --- a/config/mongoid.yml +++ b/config/mongoid.yml @@ -1,7 +1,7 @@ development: sessions: default: - database: badgify_development + database: <%= ENV['MONGO_DATABASE'] || 'badgify_development' %> hosts: - <%= ENV['MONGO_URL'] || 'localhost:27017' %> From d312e6bb9b57d986d3e5fa6775ecaa5f9633cfca Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Mon, 10 Nov 2014 15:38:02 -0600 Subject: [PATCH 27/28] Updated schema to latest migration --- db/schema.rb | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index e460520d..75829915 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -14,6 +14,7 @@ ActiveRecord::Schema.define(:version => 20141015182230) do add_extension "citext" + add_extension "hstore" create_table "alias_tags", :id => false, :force => true do |t| t.integer "tag_id" @@ -104,7 +105,7 @@ create_table "followed_teams", :force => true do |t| t.integer "user_id" t.string "team_document_id" - t.datetime "created_at", :default => '2014-02-20 22:39:11' + t.datetime "created_at", :default => '2012-03-12 21:01:09' end add_index "followed_teams", ["team_document_id"], :name => "index_followed_teams_on_team_document_id" @@ -396,20 +397,20 @@ t.text "organization_way" t.text "organization_way_name" t.text "organization_way_photo" - t.string "office_photos", :default => [], :array => true - t.string "upcoming_events", :default => [], :array => true + t.string "office_photos", :default => "{}" + t.string "upcoming_events", :default => "{}" t.string "featured_links_title" t.text "blog_feed" t.text "our_challenge" t.text "your_impact" - t.string "interview_steps", :default => [], :array => true + t.string "interview_steps", :default => "{}" t.text "hiring_tagline" t.text "link_to_careers_page" t.string "avatar" t.integer "achievement_count", :default => 0 t.integer "endorsement_count", :default => 0 - t.string "invited_emails", :default => [], :array => true - t.string "pending_join_requests", :default => [], :array => true + t.string "invited_emails", :default => "{}" + t.string "pending_join_requests", :default => "{}" t.datetime "upgraded_at" t.integer "paid_job_posts", :default => 0 t.boolean "monthly_subscription", :default => false @@ -486,7 +487,7 @@ t.integer "user_id" t.string "name" t.text "data" - t.datetime "created_at", :default => '2014-02-20 22:39:11' + t.datetime "created_at", :default => '2012-03-12 21:01:10' end create_table "users", :force => true do |t| @@ -507,8 +508,8 @@ t.string "bitbucket" t.string "codeplex" t.integer "login_count", :default => 0 - t.datetime "last_request_at", :default => '2014-07-17 13:10:04' - t.datetime "achievements_checked_at", :default => '1914-02-20 22:39:10' + t.datetime "last_request_at", :default => '2014-07-23 03:14:36' + t.datetime "achievements_checked_at", :default => '1911-08-12 21:49:21' t.text "claim_code" t.integer "github_id" t.string "country" @@ -518,7 +519,7 @@ t.float "lng" t.integer "http_counter" t.string "github_token" - t.datetime "twitter_checked_at", :default => '1914-02-20 22:39:10' + t.datetime "twitter_checked_at", :default => '1911-08-12 21:49:21' t.string "title" t.string "company" t.string "blog" @@ -555,6 +556,7 @@ t.string "tracking_code" t.string "utm_campaign" t.float "score_cache", :default => 0.0 + t.string "gender" t.boolean "notify_on_follow", :default => true t.string "api_key" t.datetime "remind_to_create_team" @@ -565,6 +567,12 @@ t.text "team_responsibilities" t.string "team_avatar" t.string "team_banner" + t.string "stat_name_1" + t.string "stat_number_1" + t.string "stat_name_2" + t.string "stat_number_2" + t.string "stat_name_3" + t.string "stat_number_3" t.float "ip_lat" t.float "ip_lng" t.float "penalty", :default => 0.0 @@ -573,9 +581,12 @@ t.string "resume" t.string "sourceforge" t.string "google_code" + t.boolean "sales_rep", :default => false t.string "visits", :default => "" t.string "visit_frequency", :default => "rarely" + t.integer "pitchbox_id" t.boolean "join_badge_orgs", :default => false + t.boolean "use_social_for_pitchbox", :default => false t.datetime "last_asm_email_at" t.datetime "banned_at" t.string "last_ip" @@ -639,9 +650,9 @@ t.string "homepage" t.boolean "fork", :default => false t.integer "forks_count", :default => 0 - t.datetime "forks_count_updated_at", :default => '2014-07-18 23:03:00' + t.datetime "forks_count_updated_at", :default => '2014-07-23 03:14:37' t.integer "stargazers_count", :default => 0 - t.datetime "stargazers_count_updated_at", :default => '2014-07-18 23:03:00' + t.datetime "stargazers_count_updated_at", :default => '2014-07-23 03:14:37' t.string "language" t.integer "followers_count", :default => 0, :null => false t.integer "github_id", :null => false From dcbccf341f56941ad2e63ff4fc3593b091e927f9 Mon Sep 17 00:00:00 2001 From: Mike Hall Date: Mon, 10 Nov 2014 15:57:44 -0600 Subject: [PATCH 28/28] Updated with the latest migration --- db/schema.rb | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 24a2a95c..47478cf4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -398,8 +398,6 @@ t.text "organization_way" t.text "organization_way_name" t.text "organization_way_photo" - t.string "office_photos", :default => "{}" - t.string "upcoming_events", :default => "{}" t.string "featured_links_title" t.text "blog_feed" t.text "our_challenge" @@ -409,14 +407,6 @@ t.string "avatar" t.integer "achievement_count", :default => 0 t.integer "endorsement_count", :default => 0 - t.string "interview_steps", :default => "{}" - t.text "hiring_tagline" - t.text "link_to_careers_page" - t.string "avatar" - t.integer "achievement_count", :default => 0 - t.integer "endorsement_count", :default => 0 - t.string "invited_emails", :default => "{}" - t.string "pending_join_requests", :default => "{}" t.datetime "upgraded_at" t.integer "paid_job_posts", :default => 0 t.boolean "monthly_subscription", :default => false