From 9bd32acc3dccaaca35f38a094f7ce7e37e3f53c5 Mon Sep 17 00:00:00 2001 From: Cole A Date: Tue, 3 Jan 2017 17:03:05 -0500 Subject: [PATCH 1/5] Update config for remote db --- Pearlception/config/database.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Pearlception/config/database.yml b/Pearlception/config/database.yml index eb86080..140a8da 100644 --- a/Pearlception/config/database.yml +++ b/Pearlception/config/database.yml @@ -14,9 +14,19 @@ default: &default encoding: utf8 pool: 5 username: root - password: + password: terps socket: /var/run/mysqld/mysqld.sock +stats: + adapter: mysql2 + encoding: utf8 + pool: 5 + username: ivauser + password: ivapassword + host: taylors.c02zesysnssi.us-west-2.rds.amazonaws.com + port: 3306 + database: taylors + development: <<: *default database: Pearlception_development From 6b68be2b174a01f47432697efc596a8385232ca2 Mon Sep 17 00:00:00 2001 From: Cole A Date: Wed, 4 Jan 2017 15:13:48 -0500 Subject: [PATCH 2/5] Fix db --- Pearlception/app/models/oyster.rb | 4 ++++ Pearlception/config/database.yml | 4 ++-- Pearlception/db/schema.rb | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 Pearlception/app/models/oyster.rb create mode 100644 Pearlception/db/schema.rb diff --git a/Pearlception/app/models/oyster.rb b/Pearlception/app/models/oyster.rb new file mode 100644 index 0000000..7600c3a --- /dev/null +++ b/Pearlception/app/models/oyster.rb @@ -0,0 +1,4 @@ +class Oyster < ActiveRecord::Base + establish_connection("stats") + +end diff --git a/Pearlception/config/database.yml b/Pearlception/config/database.yml index 140a8da..835347d 100644 --- a/Pearlception/config/database.yml +++ b/Pearlception/config/database.yml @@ -21,8 +21,8 @@ stats: adapter: mysql2 encoding: utf8 pool: 5 - username: ivauser - password: ivapassword + username: <%= ENV['DB_USER'] %> + password: <%= ENV['DB_PASS'] %> host: taylors.c02zesysnssi.us-west-2.rds.amazonaws.com port: 3306 database: taylors diff --git a/Pearlception/db/schema.rb b/Pearlception/db/schema.rb new file mode 100644 index 0000000..52ab025 --- /dev/null +++ b/Pearlception/db/schema.rb @@ -0,0 +1,15 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 0) do + +end From 92b58aa6808632ce5c0762843679f46828be18a3 Mon Sep 17 00:00:00 2001 From: Cole A Date: Wed, 4 Jan 2017 16:12:58 -0500 Subject: [PATCH 3/5] Connect remote dbs --- Pearlception/app/models/oyster.rb | 8 +++++--- Pearlception/app/models/run.rb | 4 ++++ Pearlception/config/database.yml | 10 +++++++--- Pearlception/test/models/oyster_test.rb | 9 +++++++++ 4 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 Pearlception/app/models/run.rb create mode 100644 Pearlception/test/models/oyster_test.rb diff --git a/Pearlception/app/models/oyster.rb b/Pearlception/app/models/oyster.rb index 7600c3a..0a7cdb6 100644 --- a/Pearlception/app/models/oyster.rb +++ b/Pearlception/app/models/oyster.rb @@ -1,4 +1,6 @@ -class Oyster < ActiveRecord::Base - establish_connection("stats") - +class Oyster < ApplicationRecord + belongs_to :run + Oyster.establish_connection(:"stats_#{Rails.env}") + + end diff --git a/Pearlception/app/models/run.rb b/Pearlception/app/models/run.rb new file mode 100644 index 0000000..18c81f6 --- /dev/null +++ b/Pearlception/app/models/run.rb @@ -0,0 +1,4 @@ +class Run < ApplicationRecord + has_many :oysters + establish_connection(:"stats_#{Rails.env}") +end diff --git a/Pearlception/config/database.yml b/Pearlception/config/database.yml index 835347d..6d149be 100644 --- a/Pearlception/config/database.yml +++ b/Pearlception/config/database.yml @@ -17,15 +17,19 @@ default: &default password: terps socket: /var/run/mysqld/mysqld.sock -stats: +stats_development: &stats adapter: mysql2 encoding: utf8 pool: 5 - username: <%= ENV['DB_USER'] %> + username: ivauser password: <%= ENV['DB_PASS'] %> host: taylors.c02zesysnssi.us-west-2.rds.amazonaws.com port: 3306 - database: taylors + database: main + + +stats_test: + <<: *stats development: <<: *default diff --git a/Pearlception/test/models/oyster_test.rb b/Pearlception/test/models/oyster_test.rb new file mode 100644 index 0000000..c29d260 --- /dev/null +++ b/Pearlception/test/models/oyster_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class OysterTest < ActiveSupport::TestCase + test "the_truth" do + f = Oyster.first + puts f.inspect + assert true + end +end From c8a1989c11909e5bf54ab7c49ee658db38087b2e Mon Sep 17 00:00:00 2001 From: Cole A Date: Wed, 4 Jan 2017 16:37:33 -0500 Subject: [PATCH 4/5] add env vars support in config --- Pearlception/config/database.yml | 6 +++--- Pearlception/test/models/oyster_test.rb | 14 +++++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Pearlception/config/database.yml b/Pearlception/config/database.yml index 6d149be..44aecc7 100644 --- a/Pearlception/config/database.yml +++ b/Pearlception/config/database.yml @@ -21,9 +21,9 @@ stats_development: &stats adapter: mysql2 encoding: utf8 pool: 5 - username: ivauser - password: <%= ENV['DB_PASS'] %> - host: taylors.c02zesysnssi.us-west-2.rds.amazonaws.com + username: <%= ENV['STATS_DB_USER'] %> + password: <%= ENV['STATS_DB_PASS'] %> + host: <%= ENV['STATS_DB_URL'] %> port: 3306 database: main diff --git a/Pearlception/test/models/oyster_test.rb b/Pearlception/test/models/oyster_test.rb index c29d260..ff3bd27 100644 --- a/Pearlception/test/models/oyster_test.rb +++ b/Pearlception/test/models/oyster_test.rb @@ -1,9 +1,17 @@ require 'test_helper' class OysterTest < ActiveSupport::TestCase - test "the_truth" do - f = Oyster.first - puts f.inspect + + test "check_connection" do + Oyster.connection assert true end + + test "get_first_oyster" do + first = Oyster.first + id = first.oyster_id == 1 + run = first.run_id == 257 + grade = first.grade == "Rej" + assert id && run && grade + end end From 42794a71b81ea5e2030695d7f897fe6b6264c6b6 Mon Sep 17 00:00:00 2001 From: Cole A Date: Wed, 4 Jan 2017 16:48:33 -0500 Subject: [PATCH 5/5] Update tests --- Pearlception/test/models/oyster_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Pearlception/test/models/oyster_test.rb b/Pearlception/test/models/oyster_test.rb index ff3bd27..c1c5d0b 100644 --- a/Pearlception/test/models/oyster_test.rb +++ b/Pearlception/test/models/oyster_test.rb @@ -14,4 +14,5 @@ class OysterTest < ActiveSupport::TestCase grade = first.grade == "Rej" assert id && run && grade end + end