Add migrate runs script

This commit is contained in:
cole m alban 2017-03-01 17:19:38 -05:00
parent 4f1715023b
commit c3e32ee7ba
2 changed files with 57 additions and 8 deletions

View File

@ -31,8 +31,8 @@ stats_test:
development: development:
<<: *default <<: *default
database: Pearlception_development database: Pearlception_development
username: colealban username: bmv
password: 1156244Terps! password: 1156244terps!
# Warning: The database defined as "test" will be erased and # Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake". # re-generated from your development database when you run "rake".

View File

@ -4,7 +4,36 @@ require 'fileutils'
$company_data_endpoint = "companydata.c02zesysnssi.us-west-2.rds.amazonaws.com" $company_data_endpoint = "companydata.c02zesysnssi.us-west-2.rds.amazonaws.com"
#A class to represent a run
class Run class Run
def initialize(params)
@run_id = params["run_id"]
@runDate = params["runDate"].strftime('%Y-%m-%d %H:%M:%S') || nil
@location = params["location"] || "NULL"
@supplier = params["supplier"] || "NULL"
@other = params["other"] || "NULL"
@machine_id = params["machine_id"] || "NULL"
@harvest_time = params["harvest time"] || "NULL"
@distributor = params["distributor"] || "NULL"
end
def to_insert_query
puts "#{@runDate}"
"INSERT into runs (id, runDate, location, harvest_time, supplier, distributor, other, machine_id,created_at,updated_at) VALUES
(#{@run_id}, '#{@runDate}',\"#{@location}\",NOW(),\"#{@supplier}\",\"#{@distributor}\",
\"#{@other}\",#{@machine_id},NOW(),NOW());"
end
end
#A class to represent a grade
def Grade
def initialize(params)
@id = params["grade_id"]
@full_name = params["Full_Name"] || "NULL"
end
end end
@ -31,14 +60,34 @@ def bundle
end end
end end
#This will insert the initial IVA admin needed to run the website.
def setup_initial_admin def setup_initial_admin
client = Mysql2::Client.new(host:'localhost' ,username:"colealban", password:"1156244Terps!", database: "Pearlception_development") client = Mysql2::Client.new(host:'localhost' ,username:"colealban", password:"1156244terps!", database: "Pearlception_development")
client.query("INSERT INTO companies (company_name, company_token, created_at, updated_at) VALUES (\"IVA\", \"a41b23cf-1d61-4fb4-9b69-0167abd7c583\",NOW(),NOW())") client.query("INSERT INTO companies (company_name, company_token, created_at, updated_at) VALUES (\"IVA\", \"a41b23cf-1d61-4fb4-9b69-0167abd7c583\",NOW(),NOW())")
end end
#This will migrate over all the runs that are on the AWS database to your local db
def migrate_runs
client = Mysql2::Client.new(host: $company_data_endpoint, username: 'ivauser', password: 'ivapassword', database: 'Hooper\'s Island')
local_client = Mysql2::Client.new(host:'localhost' ,username:"bmv", password:"1156244terps!", database: "Pearlception_development")
client.query("SELECT * FROM runs").each do |params|
run = Run.new(params)
puts run.to_insert_query
local_client.query(run.to_insert_query)
end
end
#This will migrate over all the oystersd
def migrate_grades
client = Mysql2::Client.new(host: $company_data_endpoint, username: 'ivauser', password: 'ivapassword', database: 'Hooper\'s Island')
client.query("SELECT * FROM grades").each do |params|
puts params
end
end
########## MAIN METHOD ##################### ########## MAIN METHOD #####################
bundle #bundle install #bundle #bundle install
initial_migration #Setup db #initial_migration #Setup db
setup_initial_admin #setup_initial_admin #Insert the initial admin
#add in og admin migrate_grades #Migrate all the runs over
#Migrate all the oysters,runs,results from the AWS DB