diff --git a/Pearlception/Gemfile b/Pearlception/Gemfile
index 9db7abe..eef33ba 100644
--- a/Pearlception/Gemfile
+++ b/Pearlception/Gemfile
@@ -40,6 +40,7 @@ gem 'devise'
gem 'kaminari'
#for popovers and tooltips
gem 'bootstrap-popover-rails'
+gem 'apartment'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
diff --git a/Pearlception/Gemfile.lock b/Pearlception/Gemfile.lock
index e1dd0bc..25d69d9 100644
--- a/Pearlception/Gemfile.lock
+++ b/Pearlception/Gemfile.lock
@@ -38,6 +38,9 @@ GEM
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
+ apartment (1.2.0)
+ activerecord (>= 3.1.2, < 6.0)
+ rack (>= 1.3.6)
arel (7.1.4)
awesome_print (1.7.0)
awesome_rails_console (0.4.0)
@@ -205,6 +208,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ apartment
awesome_rails_console
bcrypt (~> 3.1.7)
bootstrap-popover-rails
diff --git a/Pearlception/app/controllers/registrations_controller.rb b/Pearlception/app/controllers/registrations_controller.rb
index a4d3588..b17fba2 100644
--- a/Pearlception/app/controllers/registrations_controller.rb
+++ b/Pearlception/app/controllers/registrations_controller.rb
@@ -1,7 +1,9 @@
class RegistrationsController < Devise::RegistrationsController
include ApplicationHelper
#protected
-
+ def new
+ Apartment::Tenant.switch!
+ end
def create
@@ -23,6 +25,9 @@ class RegistrationsController < Devise::RegistrationsController
end
@user.save
sign_in @user
+ if !@user.admin
+ Apartment::Tenant.switch(Company.find(@user.company_id).company_name.gsub(/'/,'').gsub(/\s/,''))
+ end
redirect_to "/"
end
diff --git a/Pearlception/app/controllers/sessions_controller.rb b/Pearlception/app/controllers/sessions_controller.rb
new file mode 100644
index 0000000..528ff53
--- /dev/null
+++ b/Pearlception/app/controllers/sessions_controller.rb
@@ -0,0 +1,17 @@
+class SessionsController < Devise::RegistrationsController
+ include ApplicationHelper
+ #def new
+ # Apartment::Tenant.switch!
+ #end
+
+ def create
+ binding.pry
+ resource = warden.authenticate!(:scope => :user)
+ binding.pry
+ sign_in(:user, resource)
+ if !current_user.admin
+ Apartment::Tenant.switch!(Company.find(current_user.company_id).company_name.gsub(/'/,'').gsub(/\s/,''))
+ end
+ redirect_to "/"
+ end
+end
\ No newline at end of file
diff --git a/Pearlception/app/models/company.rb b/Pearlception/app/models/company.rb
index fdc526f..e38d444 100644
--- a/Pearlception/app/models/company.rb
+++ b/Pearlception/app/models/company.rb
@@ -1,4 +1,16 @@
class Company < ApplicationRecord
has_many :users
has_many :runs
+
+ after_create :create_tenant
+
+ private
+
+ def create_tenant
+ binding.pry
+ if company_name != "IVA"
+ Apartment::Tenant.create(company_name.gsub(/'/,'').gsub(/\s/,''))
+ Apartment::Tenant.switch!
+ end
+ end
end
diff --git a/Pearlception/app/models/grade.rb b/Pearlception/app/models/grade.rb
new file mode 100644
index 0000000..734eff4
--- /dev/null
+++ b/Pearlception/app/models/grade.rb
@@ -0,0 +1,3 @@
+class Grade < ApplicationRecord
+ self.primary_key = 'Short_name'
+end
diff --git a/Pearlception/app/models/machine.rb b/Pearlception/app/models/machine.rb
new file mode 100644
index 0000000..de10732
--- /dev/null
+++ b/Pearlception/app/models/machine.rb
@@ -0,0 +1,2 @@
+class Machine < ApplicationRecord
+end
diff --git a/Pearlception/app/models/oyster.rb b/Pearlception/app/models/oyster.rb
index cfe3ccb..799448e 100644
--- a/Pearlception/app/models/oyster.rb
+++ b/Pearlception/app/models/oyster.rb
@@ -1,12 +1,12 @@
class Oyster < ApplicationRecord
- belongs_to :run
- #Oyster.establish_connection(:"stats_#{Rails.env}")
- Oyster.establish_connection(
- :adapter => "mysql2",
- :host => ENV['STATS_DB_URL'],
- :username => ENV['STATS_DB_USER'],
- :password => ENV['STATS_DB_PASS'],
- :database => "main"
- )
+ belongs_to :run
+ #Oyster.establish_connection(:"stats_#{Rails.env}")
+ #Oyster.establish_connection(
+ #:adapter => "mysql2",
+ #:host => ENV['STATS_DB_URL'],
+ #:username => ENV['STATS_DB_USER'],
+ #:password => ENV['STATS_DB_PASS'],
+ #:database => "main"
+ #)
scope :run_id, -> (id) { where run_id: id.to_i }
end
diff --git a/Pearlception/app/models/result.rb b/Pearlception/app/models/result.rb
index cbd0ed2..fb44048 100644
--- a/Pearlception/app/models/result.rb
+++ b/Pearlception/app/models/result.rb
@@ -1,10 +1,10 @@
class Result < ApplicationRecord
- #establish_connection(:"stats_#{Rails.env}")
- Result.establish_connection(
- :adapter => "mysql2",
- :host => ENV['STATS_DB_URL'],
- :username => ENV['STATS_DB_USER'],
- :password => ENV['STATS_DB_PASS'],
- :database => "main"
- )
+ #establish_connection(:"stats_#{Rails.env}")
+ #Result.establish_connection(
+ #:adapter => "mysql2",
+ #:host => ENV['STATS_DB_URL'],
+ #:username => ENV['STATS_DB_USER'],
+ #:password => ENV['STATS_DB_PASS'],
+ #:database => "main"
+ #)
end
diff --git a/Pearlception/app/models/run.rb b/Pearlception/app/models/run.rb
index 1dd5a5e..be69ff8 100644
--- a/Pearlception/app/models/run.rb
+++ b/Pearlception/app/models/run.rb
@@ -1,12 +1,12 @@
class Run < ApplicationRecord
- has_many :oysters
- belongs_to :companies
- # establish_connection(:"stats_#{Rails.env}")
- Run.establish_connection(
- :adapter => "mysql2",
- :host => ENV['STATS_DB_URL'],
- :username => ENV['STATS_DB_USER'],
- :password => ENV['STATS_DB_PASS'],
- :database => "main"
- )
+ has_many :oysters
+ #belongs_to :companies
+ # establish_connection(:"stats_#{Rails.env}")
+ #Run.establish_connection(
+ #:adapter => "mysql2",
+ #:host => ENV['STATS_DB_URL'],
+ #:username => ENV['STATS_DB_USER'],
+ #:password => ENV['STATS_DB_PASS'],
+ #:database => "main"
+ #)
end
diff --git a/Pearlception/app/models/user.rb b/Pearlception/app/models/user.rb
index a44f648..4b7680d 100644
--- a/Pearlception/app/models/user.rb
+++ b/Pearlception/app/models/user.rb
@@ -5,4 +5,12 @@ class User < ApplicationRecord
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
+
+ def after_database_authentication
+ binding.pry
+ if !self.admin
+ binding.pry
+ Apartment::Tenant.switch!(Company.find(self.company_id).company_name.gsub(/'/,'').gsub(/\s/,''))
+ end
+ end
end
diff --git a/Pearlception/app/views/partials/_login_form.html.erb b/Pearlception/app/views/partials/_login_form.html.erb
new file mode 100644
index 0000000..60aa291
--- /dev/null
+++ b/Pearlception/app/views/partials/_login_form.html.erb
@@ -0,0 +1,20 @@
+
\ No newline at end of file
diff --git a/Pearlception/app/views/registrations/new.html.erb b/Pearlception/app/views/registrations/new.html.erb
index f5b6223..2b78d5b 100644
--- a/Pearlception/app/views/registrations/new.html.erb
+++ b/Pearlception/app/views/registrations/new.html.erb
@@ -1,4 +1,8 @@
-Sign up!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Sign up!
+
+ <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
+ <%= devise_error_messages! %>
+
+ <%= f.label :company_Serial %>
+ <%= text_field_tag :company_serial, params[:company_serial], class: 'form-control center-text', placeholder: "XXXXX-XXXXXX-XXXXX-XXXX" %>
+
+
+
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, class: 'form-control center-text', placeholder: "example@test.com" %>
+
+
+
+ <%= f.label :password %>
+ <% if @minimum_password_length %>
+ (<%= @minimum_password_length %> characters minimum)
+ <% end %>
+ <%= f.password_field :password, autocomplete: "off", class: 'form-control center-text', placeholder: "password" %>
+
+
+
+ <%= f.label :password_Confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control center-text', placeholder: "confirm password" %>
+
+
+
+ <%= f.submit "Sign up", class: "btn" %>
+
+ <% end %>
+
+
+
+ <%= render 'partials/login_form' %>
+
+
+
+
+
+
+
diff --git a/Pearlception/app/views/users/sessions/new.html.erb b/Pearlception/app/views/sessions/new.html.erb
similarity index 97%
rename from Pearlception/app/views/users/sessions/new.html.erb
rename to Pearlception/app/views/sessions/new.html.erb
index d6fde2b..d3e851c 100644
--- a/Pearlception/app/views/users/sessions/new.html.erb
+++ b/Pearlception/app/views/sessions/new.html.erb
@@ -1,4 +1,4 @@
-Log
+Log In
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
diff --git a/Pearlception/app/views/shared/_links.html.erb b/Pearlception/app/views/shared/_links.html.erb
new file mode 100644
index 0000000..e6a3e41
--- /dev/null
+++ b/Pearlception/app/views/shared/_links.html.erb
@@ -0,0 +1,25 @@
+<%- if controller_name != 'sessions' %>
+ <%= link_to "Log in", new_session_path(resource_name) %>
+<% end -%>
+
+<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
+ <%= link_to "Sign up", new_registration_path(resource_name) %>
+<% end -%>
+
+<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
+ <%= link_to "Forgot your password?", new_password_path(resource_name) %>
+<% end -%>
+
+<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
+ <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
+<% end -%>
+
+<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
+ <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
+<% end -%>
+
+<%- if devise_mapping.omniauthable? %>
+ <%- resource_class.omniauth_providers.each do |provider| %>
+ <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %>
+ <% end -%>
+<% end -%>
diff --git a/Pearlception/app/views/users/registrations/new.html.erb b/Pearlception/app/views/users/registrations/new.html.erb
index 64d7da6..ab22ed1 100644
--- a/Pearlception/app/views/users/registrations/new.html.erb
+++ b/Pearlception/app/views/users/registrations/new.html.erb
@@ -30,4 +30,4 @@
<% end %>
-<%= render "users/shared/links" %>
+
diff --git a/Pearlception/app/views/users/shared/_links.html.erb b/Pearlception/app/views/users/shared/_links.html.erb
index e6a3e41..c77adb4 100644
--- a/Pearlception/app/views/users/shared/_links.html.erb
+++ b/Pearlception/app/views/users/shared/_links.html.erb
@@ -22,4 +22,4 @@
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %>
<% end -%>
-<% end -%>
+<% end -%>
\ No newline at end of file
diff --git a/Pearlception/config/application.rb b/Pearlception/config/application.rb
index 2a5f5dd..5e79c8f 100644
--- a/Pearlception/config/application.rb
+++ b/Pearlception/config/application.rb
@@ -11,5 +11,7 @@ module Pearlception
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
+ config.middleware.use 'Apartment::Elevators::Subdomain'
+ Rails.application.config.middleware.insert_before 'Warden::Manager', 'Apartment::Elevators::Subdomain'
end
end
diff --git a/Pearlception/config/database.yml b/Pearlception/config/database.yml
index 07430f8..d5624af 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: <%= ENV['STATS_DB_USER'] %>
- password: <%= ENV['STATS_DB_PASS'] %>
- host: <%= ENV['STATS_DB_URL'] %>
+ username: # <%= ENV['STATS_DB_USER'] %>
+ password: # <%= ENV['STATS_DB_PASS'] %>
+ host: # <%= ENV['STATS_DB_URL'] %>
port: 3306
database: main
@@ -34,6 +34,8 @@ stats_test:
development:
<<: *default
database: Pearlception_development
+ username: root
+ password: Kemitscafe1
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
@@ -41,6 +43,8 @@ development:
test:
<<: *default
database: Pearlception_test
+ username: root
+ password: Kemitscafe1
# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
diff --git a/Pearlception/config/initializers/apartment.rb b/Pearlception/config/initializers/apartment.rb
new file mode 100644
index 0000000..73051b9
--- /dev/null
+++ b/Pearlception/config/initializers/apartment.rb
@@ -0,0 +1,115 @@
+# You can have Apartment route to the appropriate Tenant by adding some Rack middleware.
+# Apartment can support many different "Elevators" that can take care of this routing to your data.
+# Require whichever Elevator you're using below or none if you have a custom one.
+#
+# require 'apartment/elevators/generic'
+# require 'apartment/elevators/domain'
+require 'apartment/elevators/subdomain'
+# require 'apartment/elevators/first_subdomain'
+
+#
+# Apartment Configuration
+#
+Apartment.configure do |config|
+
+ # Add any models that you do not want to be multi-tenanted, but remain in the global (public) namespace.
+ # A typical example would be a Customer or Tenant model that stores each Tenant's information.
+ #
+ config.excluded_models = [ "User", "Company" ]
+
+ # In order to migrate all of your Tenants you need to provide a list of Tenant names to Apartment.
+ # You can make this dynamic by providing a Proc object to be called on migrations.
+ # This object should yield either:
+ # - an array of strings representing each Tenant name.
+ # - a hash which keys are tenant names, and values custom db config (must contain all key/values required in database.yml)
+ #
+ # config.tenant_names = lambda{ Customer.pluck(:tenant_name) }
+ # config.tenant_names = ['tenant1', 'tenant2']
+ # config.tenant_names = {
+ # 'tenant1' => {
+ # adapter: 'postgresql',
+ # host: 'some_server',
+ # port: 5555,
+ # database: 'postgres' # this is not the name of the tenant's db
+ # # but the name of the database to connect to before creating the tenant's db
+ # # mandatory in postgresql
+ # },
+ # 'tenant2' => {
+ # adapter: 'postgresql',
+ # database: 'postgres' # this is not the name of the tenant's db
+ # # but the name of the database to connect to before creating the tenant's db
+ # # mandatory in postgresql
+ # }
+ # }
+ # config.tenant_names = lambda do
+ # Tenant.all.each_with_object({}) do |tenant, hash|
+ # hash[tenant.name] = tenant.db_configuration
+ # end
+ # end
+ #
+
+ names = (Company.pluck :company_name) - ["IVA"]
+
+ #client = Mysql2::Client.new(
+ # :adapter => "mysql2",
+ # :host => ENV['STATS_DB_URL'],
+ # :username => ENV['STATS_DB_USER'],
+ # :password => ENV['STATS_DB_PASS']
+ #)
+
+ names.map!{|tenant| tenant.gsub(/'/,'').gsub(/\s/,'')}
+
+ #names.each {
+ # |tenant|
+ # binding.pry
+ # if ENV['RAILS_ENV'] == "production"
+ # client.query("CREATE DATABASE IF NOT EXISTS #{tenant};")
+ # else
+ # client.query("CREATE DATABASE IF NOT EXISTS #{tenant};")
+ # end
+ #}
+ # client.close
+ config.tenant_names = names
+
+ #names = (Company.pluck :company_name) - ["IVA"]
+#
+ # ==> PostgreSQL only options
+
+ # Specifies whether to use PostgreSQL schemas or create a new database per Tenant.
+ # The default behaviour is true.
+ #
+ config.use_schemas = false
+
+ # Apartment can be forced to use raw SQL dumps instead of schema.rb for creating new schemas.
+ # Use this when you are using some extra features in PostgreSQL that can't be respresented in
+ # schema.rb, like materialized views etc. (only applies with use_schemas set to true).
+ # (Note: this option doesn't use db/structure.sql, it creates SQL dump by executing pg_dump)
+ #
+ # config.use_sql = false
+
+ # There are cases where you might want some schemas to always be in your search_path
+ # e.g when using a PostgreSQL extension like hstore.
+ # Any schemas added here will be available along with your selected Tenant.
+ #
+ # config.persistent_schemas = %w{ hstore }
+
+ # <== PostgreSQL only options
+ #
+
+ # By default, and only when not using PostgreSQL schemas, Apartment will prepend the environment
+ # to the tenant name to ensure there is no conflict between your environments.
+ # This is mainly for the benefit of your development and test environments.
+ # Uncomment the line below if you want to disable this behaviour in production.
+ #
+ config.prepend_environment = !Rails.env.production?
+end
+
+# Setup a custom Tenant switching middleware. The Proc should return the name of the Tenant that
+# you want to switch to.
+# Rails.application.config.middleware.use 'Apartment::Elevators::Generic', lambda { |request|
+# request.host.split('.').first
+# }
+
+# Rails.application.config.middleware.use 'Apartment::Elevators::Domain'
+Rails.application.config.middleware.use 'Apartment::Elevators::Subdomain'
+# Rails.application.config.middleware.use 'Apartment::Elevators::FirstSubdomain'
diff --git a/Pearlception/config/routes.rb b/Pearlception/config/routes.rb
index 17e3991..7c9b104 100644
--- a/Pearlception/config/routes.rb
+++ b/Pearlception/config/routes.rb
@@ -12,5 +12,7 @@ Rails.application.routes.draw do
get 'signin' => 'registrations#new'
post 'signin' => 'registrations#create'
end
+
+
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
diff --git a/Pearlception/db/migrate/20170109174008_devise_create_users.rb b/Pearlception/db/migrate/20170109174008_devise_create_users.rb
index e04ea95..18c45b7 100644
--- a/Pearlception/db/migrate/20170109174008_devise_create_users.rb
+++ b/Pearlception/db/migrate/20170109174008_devise_create_users.rb
@@ -5,6 +5,7 @@ class DeviseCreateUsers < ActiveRecord::Migration[5.0]
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
t.integer :company_id, null: false
+ t.boolean :admin, null: false, default: false
## Recoverable
t.string :reset_password_token
diff --git a/Pearlception/db/migrate/20170210193338_create_grades.rb b/Pearlception/db/migrate/20170210193338_create_grades.rb
new file mode 100644
index 0000000..6cc397f
--- /dev/null
+++ b/Pearlception/db/migrate/20170210193338_create_grades.rb
@@ -0,0 +1,19 @@
+class CreateGrades < ActiveRecord::Migration[5.0]
+ def change
+ create_table :grades do |t|
+ t.string :Full_name, limit: 100, :null => false
+ t.string :Short_name, limit: 10, :null => false
+ t.column :Volume_max, :double
+ t.column :Volume_min, :double
+ t.column :Length_max, :double
+ t.column :Length_min, :double
+ t.column :Width_max, :double
+ t.column :Width_min, :double
+ t.column :Height_max, :double
+ t.column :Height_min, :double
+
+ t.timestamps
+ end
+ add_index :grades, :Short_name, unique: true
+ end
+end
diff --git a/Pearlception/db/migrate/20170210200122_create_runs.rb b/Pearlception/db/migrate/20170210200122_create_runs.rb
new file mode 100644
index 0000000..12a9bcf
--- /dev/null
+++ b/Pearlception/db/migrate/20170210200122_create_runs.rb
@@ -0,0 +1,16 @@
+class CreateRuns < ActiveRecord::Migration[5.0]
+ def change
+ create_table :runs do |t|
+ t.datetime :runDate, :null => false
+ t.string :location, limit: 50
+ t.string :harvest_time, limit: 50
+ t.string :supplier, limit: 50
+ t.string :distributor, limit: 50
+ t.string :other, limit: 50
+ t.integer :machine_id
+
+ t.timestamps
+ end
+ add_index :runs, :machine_id
+ end
+end
diff --git a/Pearlception/db/migrate/20170210200740_create_machines.rb b/Pearlception/db/migrate/20170210200740_create_machines.rb
new file mode 100644
index 0000000..1ddb5f6
--- /dev/null
+++ b/Pearlception/db/migrate/20170210200740_create_machines.rb
@@ -0,0 +1,9 @@
+class CreateMachines < ActiveRecord::Migration[5.0]
+ def change
+ create_table :machines do |t|
+ t.text :key, limit: 1000
+
+ t.timestamps
+ end
+ end
+end
diff --git a/Pearlception/db/migrate/20170210201958_create_results.rb b/Pearlception/db/migrate/20170210201958_create_results.rb
new file mode 100644
index 0000000..3c89b55
--- /dev/null
+++ b/Pearlception/db/migrate/20170210201958_create_results.rb
@@ -0,0 +1,23 @@
+class CreateResults < ActiveRecord::Migration[5.0]
+ def change
+ create_table :results do |t|
+ t.column :total, :integer , :null => false
+ t.column :grade1, :integer
+ t.column :grade2, :integer
+ t.column :grade3, :integer
+ t.column :grade4, :integer
+ t.column :grade5, :integer
+ t.column :grade6, :integer
+ t.column :grade7, :integer
+ t.column :grade8, :integer
+ t.column :grade9, :integer
+ t.column :grade10, :integer
+ t.integer :machine_id
+ t.integer :run_id
+
+ t.timestamps
+ end
+ add_index :results, :machine_id
+ add_index :results, :run_id
+ end
+end
diff --git a/Pearlception/db/migrate/20170210202948_create_oysters.rb b/Pearlception/db/migrate/20170210202948_create_oysters.rb
new file mode 100644
index 0000000..2063505
--- /dev/null
+++ b/Pearlception/db/migrate/20170210202948_create_oysters.rb
@@ -0,0 +1,17 @@
+class CreateOysters < ActiveRecord::Migration[5.0]
+ def change
+ create_table :oysters do |t|
+ t.integer :run_id, :null => false
+ t.string :grade, limit: 50, :null => false
+ t.column :volume, :double
+ t.column :length, :double
+ t.column :width, :double
+ t.column :height, :double
+ t.integer :machine_id
+
+ t.timestamps
+ end
+ add_index :oysters, :run_id
+ add_index :oysters, :machine_id
+ end
+end
diff --git a/Pearlception/db/schema.rb b/Pearlception/db/schema.rb
index 4a49eeb..a2a9051 100644
--- a/Pearlception/db/schema.rb
+++ b/Pearlception/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20170119161737) do
+ActiveRecord::Schema.define(version: 20170210202948) do
create_table "companies", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "company_name"
@@ -19,21 +19,90 @@ ActiveRecord::Schema.define(version: 20170119161737) do
t.datetime "updated_at", null: false
end
+ create_table "grades", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
+ t.string "Full_name", limit: 100, null: false
+ t.string "Short_name", limit: 10, null: false
+ t.float "Volume_max", limit: 53
+ t.float "Volume_min", limit: 53
+ t.float "Length_max", limit: 53
+ t.float "Length_min", limit: 53
+ t.float "Width_max", limit: 53
+ t.float "Width_min", limit: 53
+ t.float "Height_max", limit: 53
+ t.float "Height_min", limit: 53
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["Short_name"], name: "index_grades_on_Short_name", unique: true, using: :btree
+ end
+
+ create_table "machines", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
+ t.text "key", limit: 65535
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ create_table "oysters", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
+ t.integer "run_id", null: false
+ t.string "grade", limit: 50, null: false
+ t.float "volume", limit: 53
+ t.float "length", limit: 53
+ t.float "width", limit: 53
+ t.float "height", limit: 53
+ t.integer "machine_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["machine_id"], name: "index_oysters_on_machine_id", using: :btree
+ t.index ["run_id"], name: "index_oysters_on_run_id", using: :btree
+ end
+
+ create_table "results", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
+ t.integer "total", null: false
+ t.integer "grade1"
+ t.integer "grade2"
+ t.integer "grade3"
+ t.integer "grade4"
+ t.integer "grade5"
+ t.integer "grade6"
+ t.integer "grade7"
+ t.integer "grade8"
+ t.integer "grade9"
+ t.integer "grade10"
+ t.integer "machine_id"
+ t.integer "run_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["machine_id"], name: "index_results_on_machine_id", using: :btree
+ t.index ["run_id"], name: "index_results_on_run_id", using: :btree
+ end
+
+ create_table "runs", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
+ t.datetime "runDate", null: false
+ t.string "location", limit: 50
+ t.string "harvest_time", limit: 50
+ t.string "supplier", limit: 50
+ t.string "distributor", limit: 50
+ t.string "other", limit: 50
+ t.integer "machine_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["machine_id"], name: "index_runs_on_machine_id", using: :btree
+ end
+
create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
- t.string "email", default: "", null: false
- t.string "encrypted_password", default: "", null: false
- t.integer "company_id", null: false
- t.boolean "admin", default: false, null: false
+ t.string "email", default: "", null: false
+ t.string "encrypted_password", default: "", null: false
+ t.integer "company_id", default: -1, null: false
+ t.boolean "admin", default: false, null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
- t.integer "sign_in_count", default: 0, null: false
+ t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
- 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.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
diff --git a/Pearlception/db/seeds.rb b/Pearlception/db/seeds.rb
index 1beea2a..a9cafb7 100644
--- a/Pearlception/db/seeds.rb
+++ b/Pearlception/db/seeds.rb
@@ -5,3 +5,12 @@
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
+require 'securerandom'
+
+#create admin company for login access
+Company.create(company_name: 'IVA', company_token: 'a41b23cf-1d61-4fb4-9b69-0167abd7c583')
+
+if Rails.env == 'development'
+ Company.create(company_name: "Taylors", company_token: SecureRandom.uuid)
+ Company.create(company_name: "Hooper's Island", company_token: SecureRandom.uuid)
+end
diff --git a/Pearlception/scripts/provision_remote.rb b/Pearlception/scripts/provision_remote.rb
new file mode 100644
index 0000000..26399ab
--- /dev/null
+++ b/Pearlception/scripts/provision_remote.rb
@@ -0,0 +1,13 @@
+#!/bin/env ruby
+
+ENV['RAILS_ENV'] = "development" # Set to your desired Rails environment name
+require '/../config/environment.rb'
+require 'active_record'
+
+client = Mysql2::Client.new(:adapter => "mysql2",
+ :host => ENV['STATS_DB_URL'],
+ :username => ENV['STATS_DB_USER'],
+ :password => ENV['STATS_DB_PASS'],
+ )
+
+#client.query("CREATE DATABASE company_db")
\ No newline at end of file
diff --git a/Pearlception/test/fixtures/grades.yml b/Pearlception/test/fixtures/grades.yml
new file mode 100644
index 0000000..c487179
--- /dev/null
+++ b/Pearlception/test/fixtures/grades.yml
@@ -0,0 +1,25 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ Full_name: MyString
+ Short_name: MyString
+ Volume_max:
+ Volume_min:
+ Length_max:
+ Length_min:
+ Width_max:
+ Width_min:
+ Height_max:
+ Height_min:
+
+two:
+ Full_name: MyString
+ Short_name: MyString
+ Volume_max:
+ Volume_min:
+ Length_max:
+ Length_min:
+ Width_max:
+ Width_min:
+ Height_max:
+ Height_min:
diff --git a/Pearlception/test/fixtures/machines.yml b/Pearlception/test/fixtures/machines.yml
new file mode 100644
index 0000000..375e163
--- /dev/null
+++ b/Pearlception/test/fixtures/machines.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ key: MyText
+
+two:
+ key: MyText
diff --git a/Pearlception/test/fixtures/oysters.yml b/Pearlception/test/fixtures/oysters.yml
new file mode 100644
index 0000000..bbe8016
--- /dev/null
+++ b/Pearlception/test/fixtures/oysters.yml
@@ -0,0 +1,19 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ run_id: 1
+ grade: MyString
+ volume:
+ length:
+ width:
+ height:
+ machine_id: 1
+
+two:
+ run_id: 1
+ grade: MyString
+ volume:
+ length:
+ width:
+ height:
+ machine_id: 1
diff --git a/Pearlception/test/fixtures/results.yml b/Pearlception/test/fixtures/results.yml
new file mode 100644
index 0000000..a4ec989
--- /dev/null
+++ b/Pearlception/test/fixtures/results.yml
@@ -0,0 +1,17 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ total: 1
+ grade1: 1
+ grade2: 1
+ grade3: 1
+ machine_id: 1
+ run_id: 1
+
+two:
+ total: 1
+ grade1: 1
+ grade2: 1
+ grade3: 1
+ machine_id: 1
+ run_id: 1
diff --git a/Pearlception/test/fixtures/runs.yml b/Pearlception/test/fixtures/runs.yml
new file mode 100644
index 0000000..914af9d
--- /dev/null
+++ b/Pearlception/test/fixtures/runs.yml
@@ -0,0 +1,19 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ runDate: 2017-02-10 15:01:22
+ location: MyString
+ harvest_time: MyString
+ supplier: MyString
+ distributor: MyString
+ other: MyString
+ machine_id: 1
+
+two:
+ runDate: 2017-02-10 15:01:22
+ location: MyString
+ harvest_time: MyString
+ supplier: MyString
+ distributor: MyString
+ other: MyString
+ machine_id: 1
diff --git a/Pearlception/test/models/grade_test.rb b/Pearlception/test/models/grade_test.rb
new file mode 100644
index 0000000..e9528e4
--- /dev/null
+++ b/Pearlception/test/models/grade_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class GradeTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/Pearlception/test/models/machine_test.rb b/Pearlception/test/models/machine_test.rb
new file mode 100644
index 0000000..c344206
--- /dev/null
+++ b/Pearlception/test/models/machine_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class MachineTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/Pearlception/test/models/oyster_test.rb b/Pearlception/test/models/oyster_test.rb
index c1c5d0b..495e1bb 100644
--- a/Pearlception/test/models/oyster_test.rb
+++ b/Pearlception/test/models/oyster_test.rb
@@ -1,18 +1,7 @@
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
-
+ # test "the truth" do
+ # assert true
+ # end
end
diff --git a/Pearlception/test/models/result_test.rb b/Pearlception/test/models/result_test.rb
new file mode 100644
index 0000000..3b57edb
--- /dev/null
+++ b/Pearlception/test/models/result_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ResultTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/Pearlception/test/models/run_test.rb b/Pearlception/test/models/run_test.rb
new file mode 100644
index 0000000..a084480
--- /dev/null
+++ b/Pearlception/test/models/run_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class RunTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end