From c3e32ee7ba35eedc31f9caa76414c445ae160f4c Mon Sep 17 00:00:00 2001 From: cole m alban Date: Wed, 1 Mar 2017 17:19:38 -0500 Subject: [PATCH] Add migrate runs script --- Pearlception/config/database.yml | 4 +-- setup.rb | 61 ++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/Pearlception/config/database.yml b/Pearlception/config/database.yml index e978a3a..025b1d5 100644 --- a/Pearlception/config/database.yml +++ b/Pearlception/config/database.yml @@ -31,8 +31,8 @@ stats_test: development: <<: *default database: Pearlception_development - username: colealban - password: 1156244Terps! + username: bmv + password: 1156244terps! # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". diff --git a/setup.rb b/setup.rb index 62d2d3e..5674683 100644 --- a/setup.rb +++ b/setup.rb @@ -4,7 +4,36 @@ require 'fileutils' $company_data_endpoint = "companydata.c02zesysnssi.us-west-2.rds.amazonaws.com" +#A class to represent a 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 @@ -31,14 +60,34 @@ def bundle end end +#This will insert the initial IVA admin needed to run the website. 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())") 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 ##################### -bundle #bundle install -initial_migration #Setup db -setup_initial_admin -#add in og admin -#Migrate all the oysters,runs,results from the AWS DB +#bundle #bundle install +#initial_migration #Setup db +#setup_initial_admin #Insert the initial admin +migrate_grades #Migrate all the runs over