diff --git a/Pearlception/app/models/oyster.rb b/Pearlception/app/models/oyster.rb new file mode 100644 index 0000000..0a7cdb6 --- /dev/null +++ b/Pearlception/app/models/oyster.rb @@ -0,0 +1,6 @@ +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 eb86080..44aecc7 100644 --- a/Pearlception/config/database.yml +++ b/Pearlception/config/database.yml @@ -14,9 +14,23 @@ default: &default encoding: utf8 pool: 5 username: root - password: + password: terps socket: /var/run/mysqld/mysqld.sock +stats_development: &stats + adapter: mysql2 + encoding: utf8 + pool: 5 + username: <%= ENV['STATS_DB_USER'] %> + password: <%= ENV['STATS_DB_PASS'] %> + host: <%= ENV['STATS_DB_URL'] %> + port: 3306 + database: main + + +stats_test: + <<: *stats + development: <<: *default database: Pearlception_development diff --git a/Pearlception/db/schema.rb b/Pearlception/db/schema.rb index f30ee8a..11318a1 100644 --- a/Pearlception/db/schema.rb +++ b/Pearlception/db/schema.rb @@ -10,6 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. +<<<<<<< HEAD ActiveRecord::Schema.define(version: 20170109174008) do create_table "companies", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| @@ -36,5 +37,8 @@ ActiveRecord::Schema.define(version: 20170109174008) do t.index ["email"], name: "index_users_on_email", unique: true, using: :btree t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree end +======= +ActiveRecord::Schema.define(version: 0) do +>>>>>>> master end diff --git a/Pearlception/test/models/oyster_test.rb b/Pearlception/test/models/oyster_test.rb new file mode 100644 index 0000000..c1c5d0b --- /dev/null +++ b/Pearlception/test/models/oyster_test.rb @@ -0,0 +1,18 @@ +require 'test_helper' + +class OysterTest < ActiveSupport::TestCase + + 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