From 75d9339010823cf6e2928eba502bdf41db38b125 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Wed, 6 Jan 2016 10:23:01 +0800 Subject: [PATCH 1/5] make mapping polymorphism migration handle mapping problems --- db/migrate/20151001024122_mapping_polymorphism.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/db/migrate/20151001024122_mapping_polymorphism.rb b/db/migrate/20151001024122_mapping_polymorphism.rb index e41233f6..e6bbd5fc 100644 --- a/db/migrate/20151001024122_mapping_polymorphism.rb +++ b/db/migrate/20151001024122_mapping_polymorphism.rb @@ -15,12 +15,16 @@ class MappingPolymorphism < ActiveRecord::Migration end unless mapping.synapse_id.nil? - mapping.mappable = Synapse.find(mapping.synapse_id) + mapping.mappable = Synapse.find_by(id: mapping.synapse_id) else - next if mapping.topic_id == 0 - mapping.mappable = Topic.find(mapping.topic_id) + mapping.mappable = Topic.find_by(id: mapping.topic_id) + end + + if mapping.mappable.nil? + mapping.delete + else + mapping.save end - mapping.save end end From 062522bfdc9f1429f95bfbe12a3f1080f75a4413 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Wed, 6 Jan 2016 11:25:55 +0800 Subject: [PATCH 2/5] remove unnecessary step from windows docs --- doc/WindowsInstallation.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/doc/WindowsInstallation.md b/doc/WindowsInstallation.md index 7e601a08..56b4f657 100644 --- a/doc/WindowsInstallation.md +++ b/doc/WindowsInstallation.md @@ -8,11 +8,6 @@ During the installation of the PostgreSQL database, you'll need to choose a data Once you are ready, create a new folder to hold this and any other git repositories. As an example, let's pretend you've chose C:\git, and made that folder writable by your user account. -Open a command prompt ("cmd.exe"), and navigate to the folder you chose. Then use the gem command (which is part of Ruby) to install Ruby on Rails. - - cd .\git - gem install rails -v 4.2 - Now you are ready to clone the Metamaps git repository: git clone https://github.com/metamaps/metamaps_gen002.git --branch develop From 70f5a5db11253da5ee001aa91f135d86f0fc5452 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Wed, 6 Jan 2016 22:36:29 +0800 Subject: [PATCH 3/5] centralize config in .env file, which includes remaving database.yml.default and overriding that file's local changes in favour of env variables. In future, all instance config can go in .env --- .example-env | 58 +++++++++++-------- .gitignore | 7 +-- config/{database.yml.default => database.yml} | 10 ++-- configure.sh | 2 +- doc/MacInstallation.md | 34 ++++++----- doc/UbuntuInstallation.md | 8 ++- doc/WindowsInstallation.md | 2 +- 7 files changed, 67 insertions(+), 54 deletions(-) rename config/{database.yml.default => database.yml} (63%) diff --git a/.example-env b/.example-env index c8fb94af..b974c5b2 100644 --- a/.example-env +++ b/.example-env @@ -1,14 +1,39 @@ -RAILS_ENV=development +export RAILS_ENV='development' -AWS_ACCESS_KEY_ID -AWS_SECRET_ACCESS_KEY -BUNDLE_GEMFILE -SMTP_DOMAIN -SMTP_PASSWORD -SMTP_PORT -SMTP_SERVER -SMTP_USERNAME -SSO_KEY +export DB_USERNAME='postgres' +export DB_PASSWORD='3112' +export DB_HOST='localhost' +export DB_PORT='5432' +export REALTIME_SERVER='https://realtime.metamaps.cc' + +# you can safely leave the rest of these blank, unless you're +# deploying an instance, in which case you'll need to set them up + +export AWS_ACCESS_KEY_ID +export AWS_SECRET_ACCESS_KEY +export SSO_KEY + +export SMTP_DOMAIN +export SMTP_PASSWORD +export SMTP_PORT +export SMTP_SERVER +export SMTP_USERNAME + +#ruby garbage collection stuff + +export RUBY_GC_TUNE=0 #set to 1 to enable GC test +export RUBY_GC_TOKEN=4f4380fc9a2857d1f008005a3eb86928 +export RUBY_GC_HEAP_INIT_SLOTS=186426 +export RUBY_GC_HEAP_FREE_SLOTS=559278 +export RUBY_GC_HEAP_GROWTH_FACTOR=1.03 +export RUBY_GC_HEAP_GROWTH_MAX_SLOTS=74570 +export RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR=1.4 +export RUBY_GC_MALLOC_LIMIT=32883406 +export RUBY_GC_MALLOC_LIMIT_MAX=69055153 +export RUBY_GC_MALLOC_LIMIT_GROWTH_FACTOR=1.68 +export RUBY_GC_OLDMALLOC_LIMIT=32509481 +export RUBY_GC_OLDMALLOC_LIMIT_MAX=68269910 +export RUBY_GC_OLDMALLOC_LIMIT_GROWTH_FACTOR=1.4 ## find the ENV currently in use in the app using : ## grep -rIso -P "(?<=ENV)(\.fetch\(|\[).[A-Z_]+.(\)|\])" @@ -16,16 +41,3 @@ SSO_KEY # for a uniq ordered list of env vars: ## grep -rIsoh -P "(?<=ENV)(\.fetch\(|\[).[A-Z_]+.(\)|\])" | grep -oP "[A-Z_]+" | sort -u > temp -RUBY_GC_TUNE=0 #set to 1 to enable GC test -RUBY_GC_TOKEN=4f4380fc9a2857d1f008005a3eb86928 -RUBY_GC_HEAP_INIT_SLOTS=186426 -RUBY_GC_HEAP_FREE_SLOTS=559278 -RUBY_GC_HEAP_GROWTH_FACTOR=1.03 -RUBY_GC_HEAP_GROWTH_MAX_SLOTS=74570 -RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR=1.4 -RUBY_GC_MALLOC_LIMIT=32883406 -RUBY_GC_MALLOC_LIMIT_MAX=69055153 -RUBY_GC_MALLOC_LIMIT_GROWTH_FACTOR=1.68 -RUBY_GC_OLDMALLOC_LIMIT=32509481 -RUBY_GC_OLDMALLOC_LIMIT_MAX=68269910 -RUBY_GC_OLDMALLOC_LIMIT_GROWTH_FACTOR=1.4 diff --git a/.gitignore b/.gitignore index c6358ead..db060afa 100644 --- a/.gitignore +++ b/.gitignore @@ -8,17 +8,12 @@ realtime/node_modules public/assets -#secrets -config/database.yml -config/secrets.yml +#secrets and config .env # Ignore bundler config .bundle -# Ignore the default SQLite database. -db/*.sqlite3 - # Ignore all logfiles and tempfiles. log/*.log tmp diff --git a/config/database.yml.default b/config/database.yml similarity index 63% rename from config/database.yml.default rename to config/database.yml index f8121488..9705a795 100644 --- a/config/database.yml.default +++ b/config/database.yml @@ -1,12 +1,12 @@ default: &default min_messages: WARNING - adapter: postgresql - host: 127.0.0.1 - port: 5432 encoding: unicode pool: 5 - username: postgres - password: "3112" + adapter: postgresql + host: <%= ENV['DB_HOST'] %> + port: <%= ENV['DB_PORT'] %> + username: <%= ENV['DB_USERNAME'] %> + password: <%= ENV['DB_PASSWORD'] %> development: <<: *default diff --git a/configure.sh b/configure.sh index 13e18244..481ca907 100755 --- a/configure.sh +++ b/configure.sh @@ -11,7 +11,7 @@ vagrant ssh --command "cd /vagrant; gem install bundler"; vagrant ssh --command "cd /vagrant; bundle install"; # copy the db config -vagrant ssh --command "cd /vagrant; cp config/database.yml.default config/database.yml"; +vagrant ssh --command "cd /vagrant; cp .example-env .env"; # Rake all the things vagrant ssh --command "cd /vagrant; rake db:create; rake db:schema:load; rake db:fixtures:load" diff --git a/doc/MacInstallation.md b/doc/MacInstallation.md index 2d36494e..1ccd3f78 100644 --- a/doc/MacInstallation.md +++ b/doc/MacInstallation.md @@ -1,6 +1,10 @@ +# OSX Install + If you are doing an upgrade and or recent pull for changes you will need to change your default ruby package from 2.1.1 to ruby 2.1.2 -install homebrew +Some of these steps are pulled from http://www.moncefbelyamani.com/how-to-install-postgresql-on-a-mac-with-homebrew-and-lunchy/ + +Install homebrew \curl -sSL https://get.rvm.io | bash -s stable --rails @@ -10,33 +14,33 @@ install homebrew gem install lunchy -(http://www.moncefbelyamani.com/how-to-install-postgresql-on-a-mac-with-homebrew-and-lunchy/) +Now install homebrew. + ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + +Then install nodejs + + brew install nodejs + +And postgresql: brew install postgresql ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents createuser metamaps -P -s -d -set a password +Set a password, then start the service: lunchy start postgres - -cd into the metamaps directory +Change directory to the metamaps git repository, and run: bundle install - -copy the database.yml.default file and rename it database.yml -make sure the username and password match the POSTGRES username and password you set - - -http://nodejs.org/ hit install, download, open, install - +Copy the .example-env file and rename it to .env. Then modify the DB_USERNAME and DB_PASSWORD values to match the postgres username and password you set rake db:create rake db:schema:load rake db:fixtures:load - rails s - -( to start the server) + rails server + +Now open a browser to http://localhost:3000! diff --git a/doc/UbuntuInstallation.md b/doc/UbuntuInstallation.md index 54872124..e23de937 100644 --- a/doc/UbuntuInstallation.md +++ b/doc/UbuntuInstallation.md @@ -57,13 +57,15 @@ Install the specific version of ruby needed this will take some time rvm install ruby-2.1.3 -Now we also need to rename your database file which is in ./config/database.default.yml to database.yml +Now we also need to copy .example-env to a new file named .env. Review the configuration in here to see if you need any changes. -now run inside your metamaps_gen002 folder + cp .example-env .env + +Now run inside your metamaps_gen002 folder bundle install -in your top lvl directory for metamaps this is a lengthy process so you might want to go and make a coffee or something :) +in your top level directory for metamaps this is a lengthy process so you might want to go and make a coffee or something :) alright now we need to make sure your postgres password is the same as it is listed in the DB file so we are going to set it by diff --git a/doc/WindowsInstallation.md b/doc/WindowsInstallation.md index 7e601a08..89e32ea5 100644 --- a/doc/WindowsInstallation.md +++ b/doc/WindowsInstallation.md @@ -25,7 +25,7 @@ At this point you should be in C:\git\metamaps_gen002, or whatever equivalent di start config -This command will open a Windows Explorer window of the "config" directory of Metamaps. Copy database.yml.default, and rename the copy to database.yml. Edit the file and set the password to be whatever you set up with postgres earlier. Once you're done, then move back into the command prompt. The next few commands will fail unless database.yml is correctly configured and Postgres is running. +This command will open a Windows Explorer window of the "config" directory of Metamaps. Copy `.example-env`, and rename the copy to `.env`. Edit the file and set the DB_PASSWORD to be whatever you set up with postgres earlier. Once you're done, then move back into the command prompt. The next few commands will fail unless `.env` is correctly configured and Postgres is running. rake db:create rake db:schema:load From 3cdab531a67df33a46690734e982ae23d7c40df5 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Wed, 6 Jan 2016 22:57:01 +0800 Subject: [PATCH 4/5] move more config into .example-env --- .example-env | 11 ++++++++++- app/assets/javascripts/src/Metamaps.js.erb | 8 ++------ app/views/layouts/application.html.erb | 2 +- config/environments/production.rb | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.example-env b/.example-env index b974c5b2..417e79ea 100644 --- a/.example-env +++ b/.example-env @@ -4,7 +4,16 @@ export DB_USERNAME='postgres' export DB_PASSWORD='3112' export DB_HOST='localhost' export DB_PORT='5432' -export REALTIME_SERVER='https://realtime.metamaps.cc' + +export MAILER_DEFAULT_URL='localhost:3000' +# you could also use +# export MAILER_DEFAULT_URL='metamaps.herokuapp.com' + +export REALTIME_SERVER='http://localhost:5001' +# you could also use +# export REALTIME_SERVER='https://realtime.metamaps.cc' +# export REALTIME_SERVER='https://my-heroku-realtime-server.herokuapp.com', + # you can safely leave the rest of these blank, unless you're # deploying an instance, in which case you'll need to set them up diff --git a/app/assets/javascripts/src/Metamaps.js.erb b/app/assets/javascripts/src/Metamaps.js.erb index 069fdc21..c8e61868 100644 --- a/app/assets/javascripts/src/Metamaps.js.erb +++ b/app/assets/javascripts/src/Metamaps.js.erb @@ -1910,9 +1910,6 @@ Metamaps.Util = { * */ Metamaps.Realtime = { - stringForLocalhost: '//localhost:5001', - stringForMetamaps: 'https://realtime.metamaps.cc', - stringForHeroku: 'https://gentle-savannah-1303.herokuapp.com', socket: null, isOpen: false, changing: false, @@ -1936,9 +1933,8 @@ Metamaps.Realtime = { }); $('body').click(self.close); - var railsEnv = $('body').data('env'); - var whichToConnect = railsEnv === 'development' ? self.stringForLocalhost : self.stringForHeroku; - self.socket = io.connect(whichToConnect); + var realtimeServerUrl = '<%= ENV['REALTIME_SERVER'] %>' + self.socket = io.connect(realtimeServerUrl); self.socket.on('connect', function () { self.startActiveMap(); }); diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 8057d576..03a9ebf7 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -66,7 +66,7 @@ -"> +"> <% if devise_error_messages? %>

<%= devise_error_messages! %>

diff --git a/config/environments/production.rb b/config/environments/production.rb index 55220ee3..9654962a 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -42,7 +42,7 @@ Metamaps::Application.configure do authentication: 'plain', enable_starttls_auto: true, openssl_verify_mode: 'none' } - config.action_mailer.default_url_options = { :host => 'metamaps.herokuapp.com' } + config.action_mailer.default_url_options = { :host => ENV['MAILER_DEFAULT_URL'] } # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = true From 7d7003a1bc66b049cd7045335d0047652a8b7769 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Wed, 6 Jan 2016 23:16:34 +0800 Subject: [PATCH 5/5] get more hard headed about having development values in .example-env --- .example-env | 15 +++++---------- config/initializers/devise.rb | 9 ++------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/.example-env b/.example-env index 417e79ea..dfdbd8ac 100644 --- a/.example-env +++ b/.example-env @@ -5,18 +5,13 @@ export DB_PASSWORD='3112' export DB_HOST='localhost' export DB_PORT='5432' -export MAILER_DEFAULT_URL='localhost:3000' -# you could also use -# export MAILER_DEFAULT_URL='metamaps.herokuapp.com' - export REALTIME_SERVER='http://localhost:5001' -# you could also use -# export REALTIME_SERVER='https://realtime.metamaps.cc' -# export REALTIME_SERVER='https://my-heroku-realtime-server.herokuapp.com', +export MAILER_DEFAULT_URL='localhost:3000' +export DEVISE_MAILER_SENDER='team@metamaps.cc' +export DEVISE_SECRET_KEY='f71c467e526f23d614b3b08866cad4788c502bed869c282f06e73ee6c94675b62fe1f6d52fa7ba8196b33031f0d2f3b67e27ea07693c52ecebccb01700cad614' - -# you can safely leave the rest of these blank, unless you're -# deploying an instance, in which case you'll need to set them up +# you can safely leave these blank, unless you're deploying an instance, in which +# case you'll need to set them up export AWS_ACCESS_KEY_ID export AWS_SECRET_ACCESS_KEY diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index d01678be..6590fddf 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -11,18 +11,13 @@ Devise.setup do |config| # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use your own mailer class with default "from" parameter. - config.mailer_sender = "team@metamaps.cc" + config.mailer_sender = ENV['DEVISE_MAILER_SENDER'] # Configure the class responsible to send e-mails. # config.mailer = "Devise::Mailer" - if Rails.env.development? # this is for Connors localhost - config.secret_key = 'f71c467e526f23d614b3b08866cad4788c502bed869c282f06e73ee6c94675b62fe1f6d52fa7ba8196b33031f0d2f3b67e27ea07693c52ecebccb01700cad614' - end - if Rails.env.production? # this is for the heroku staging environment - config.secret_key = 'd91ba0da95749174ee2b8922034783cbde4945409ed28b13383e18e72844beb74467f8199e9e216f0687cd2290c6e46bf74da24486d14bba3671d76c5b10c753' - end + config.secret_key = ENV['DEVISE_SECRET_KEY'] # ==> ORM configuration # Load and configure the ORM. Supports :active_record (default) and