mirror of
https://github.com/oonyeje/Pearlception_Website_RoR.git
synced 2025-12-25 11:47:41 +00:00
Mutltiple database pattern for companies integrated
- When creating a new company as an admin, a new database containing models for Runs, Grades, Results, Machines, and Oysters is migrated and created - When a user registers, they are automatically switched to their company's db in the server - When a user signs in they are also automatically swithched
This commit is contained in:
parent
ac0ab198cb
commit
f06c2ca057
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
17
Pearlception/app/controllers/sessions_controller.rb
Normal file
17
Pearlception/app/controllers/sessions_controller.rb
Normal file
@ -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
|
||||
@ -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
|
||||
|
||||
3
Pearlception/app/models/grade.rb
Normal file
3
Pearlception/app/models/grade.rb
Normal file
@ -0,0 +1,3 @@
|
||||
class Grade < ApplicationRecord
|
||||
self.primary_key = 'Short_name'
|
||||
end
|
||||
2
Pearlception/app/models/machine.rb
Normal file
2
Pearlception/app/models/machine.rb
Normal file
@ -0,0 +1,2 @@
|
||||
class Machine < ApplicationRecord
|
||||
end
|
||||
@ -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"
|
||||
)
|
||||
#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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
class Run < ApplicationRecord
|
||||
has_many :oysters
|
||||
belongs_to :companies
|
||||
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"
|
||||
)
|
||||
#Run.establish_connection(
|
||||
#:adapter => "mysql2",
|
||||
#:host => ENV['STATS_DB_URL'],
|
||||
#:username => ENV['STATS_DB_USER'],
|
||||
#:password => ENV['STATS_DB_PASS'],
|
||||
#:database => "main"
|
||||
#)
|
||||
end
|
||||
|
||||
@ -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
|
||||
|
||||
20
Pearlception/app/views/partials/_login_form.html.erb
Normal file
20
Pearlception/app/views/partials/_login_form.html.erb
Normal file
@ -0,0 +1,20 @@
|
||||
<div class=" login_form">
|
||||
<h2 class="form-title">Login</h2>
|
||||
<%= form_for(:user, :url => session_path(:user)) do |f| %>
|
||||
<div class="form-group">
|
||||
<%= f.text_field :email, class: 'form-control', placeholder: 'email' %>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<%= f.password_field :password, class: 'form-control', placeholder: 'password' %>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= f.check_box :remember_me %>
|
||||
<%= f.label :remember_me %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= f.submit 'Sign in', class: 'btn btn-lg aqua-btn2 user-signin-btn' %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
@ -1,4 +1,8 @@
|
||||
<h2>Sign up!</h2>
|
||||
<head>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
|
||||
</head>
|
||||
<!--<h2>Sign up!</h2>
|
||||
|
||||
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
@ -30,4 +34,58 @@
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= render "users/shared/links" %>
|
||||
<%= render "shared/links" %>-->
|
||||
<div class="container">
|
||||
<div class="row new_user_row">
|
||||
<div class="col-md-8 col-md-offset-2">
|
||||
<div class="panel panel-primary">
|
||||
<ul class="nav nav-tabs">
|
||||
<li role="presentation" class="active"><a href="#register" aria-controls="register" role="tab" data-toggle="pill">Register</a></li>
|
||||
<li><a data-toggle="pill" href="#login">Login</a></li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-content">
|
||||
<!-- register tab -->
|
||||
<div role="tabpanel" class="tab-pane fade in active" id="register">
|
||||
<h2>Sign up!</h2>
|
||||
|
||||
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
<div class="field">
|
||||
<%= f.label :company_Serial %><br />
|
||||
<%= text_field_tag :company_serial, params[:company_serial], class: 'form-control center-text', placeholder: "XXXXX-XXXXXX-XXXXX-XXXX" %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :email %><br />
|
||||
<%= f.email_field :email, autofocus: true, class: 'form-control center-text', placeholder: "example@test.com" %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :password %>
|
||||
<% if @minimum_password_length %>
|
||||
<em>(<%= @minimum_password_length %> characters minimum)</em>
|
||||
<% end %><br />
|
||||
<%= f.password_field :password, autocomplete: "off", class: 'form-control center-text', placeholder: "password" %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :password_Confirmation %><br />
|
||||
<%= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control center-text', placeholder: "confirm password" %>
|
||||
</div>
|
||||
|
||||
<div class="actions center">
|
||||
<%= f.submit "Sign up", class: "btn" %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<!-- login tab -->
|
||||
<div role="tabpanel" class="tab-pane fade" id="login">
|
||||
<%= render 'partials/login_form' %>
|
||||
</div>
|
||||
</div>
|
||||
</div> <!--Panel tag-->
|
||||
</div> <!--col-md-8 tag-->
|
||||
</div> <!--row tag-->
|
||||
</div> <!--container tag-->
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<h2>Log</h2>
|
||||
<h2>Log In</h2>
|
||||
|
||||
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
|
||||
<div class="field">
|
||||
25
Pearlception/app/views/shared/_links.html.erb
Normal file
25
Pearlception/app/views/shared/_links.html.erb
Normal file
@ -0,0 +1,25 @@
|
||||
<%- if controller_name != 'sessions' %>
|
||||
<%= link_to "Log in", new_session_path(resource_name) %><br />
|
||||
<% end -%>
|
||||
|
||||
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
|
||||
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
|
||||
<% end -%>
|
||||
|
||||
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
|
||||
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
|
||||
<% end -%>
|
||||
|
||||
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
|
||||
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
|
||||
<% 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) %><br />
|
||||
<% 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) %><br />
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
@ -30,4 +30,4 @@
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= render "users/shared/links" %>
|
||||
<!--<%= render "users/shared/links" %>-->
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
115
Pearlception/config/initializers/apartment.rb
Normal file
115
Pearlception/config/initializers/apartment.rb
Normal file
@ -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'
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
19
Pearlception/db/migrate/20170210193338_create_grades.rb
Normal file
19
Pearlception/db/migrate/20170210193338_create_grades.rb
Normal file
@ -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
|
||||
16
Pearlception/db/migrate/20170210200122_create_runs.rb
Normal file
16
Pearlception/db/migrate/20170210200122_create_runs.rb
Normal file
@ -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
|
||||
@ -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
|
||||
23
Pearlception/db/migrate/20170210201958_create_results.rb
Normal file
23
Pearlception/db/migrate/20170210201958_create_results.rb
Normal file
@ -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
|
||||
17
Pearlception/db/migrate/20170210202948_create_oysters.rb
Normal file
17
Pearlception/db/migrate/20170210202948_create_oysters.rb
Normal file
@ -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
|
||||
@ -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.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
|
||||
|
||||
@ -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
|
||||
|
||||
13
Pearlception/scripts/provision_remote.rb
Normal file
13
Pearlception/scripts/provision_remote.rb
Normal file
@ -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")
|
||||
25
Pearlception/test/fixtures/grades.yml
vendored
Normal file
25
Pearlception/test/fixtures/grades.yml
vendored
Normal file
@ -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:
|
||||
7
Pearlception/test/fixtures/machines.yml
vendored
Normal file
7
Pearlception/test/fixtures/machines.yml
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
key: MyText
|
||||
|
||||
two:
|
||||
key: MyText
|
||||
19
Pearlception/test/fixtures/oysters.yml
vendored
Normal file
19
Pearlception/test/fixtures/oysters.yml
vendored
Normal file
@ -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
|
||||
17
Pearlception/test/fixtures/results.yml
vendored
Normal file
17
Pearlception/test/fixtures/results.yml
vendored
Normal file
@ -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
|
||||
19
Pearlception/test/fixtures/runs.yml
vendored
Normal file
19
Pearlception/test/fixtures/runs.yml
vendored
Normal file
@ -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
|
||||
7
Pearlception/test/models/grade_test.rb
Normal file
7
Pearlception/test/models/grade_test.rb
Normal file
@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class GradeTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
7
Pearlception/test/models/machine_test.rb
Normal file
7
Pearlception/test/models/machine_test.rb
Normal file
@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class MachineTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
@ -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
|
||||
|
||||
7
Pearlception/test/models/result_test.rb
Normal file
7
Pearlception/test/models/result_test.rb
Normal file
@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ResultTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
7
Pearlception/test/models/run_test.rb
Normal file
7
Pearlception/test/models/run_test.rb
Normal file
@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class RunTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user