Add migration script for aws->local server data migration

This commit is contained in:
cole m alban 2017-02-22 16:22:05 -05:00
parent a2d7d91615
commit 80d4df4b34
2 changed files with 44 additions and 7 deletions

View File

@ -13,9 +13,6 @@ default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: <%= ENV['TEST_USER'] %>
password: <%= ENV['TEST_PASS'] %>
socket: <%= ENV['TEST_SOCKET'] %>
stats_development: &stats
adapter: mysql2
@ -34,8 +31,8 @@ stats_test:
development:
<<: *default
database: Pearlception_development
username: root
password: Kemitscafe1
username: bmv
password: 1156244terps!
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
@ -43,8 +40,8 @@ development:
test:
<<: *default
database: Pearlception_test
username: root
password: Kemitscafe1
username: bmv
password: 1156244terps!
# 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

40
migrate.rb Normal file
View File

@ -0,0 +1,40 @@
#Script to migrate things to the bmv server from a csv file
require 'mysql2'
require 'csv'
class Run
attr_accessor :id, :run_date, :location, :harvest_time, :supplier, :distributor, :other, :machine_id
def initialize(id, run_date, location, harvest_time, supplier, distributor, other, machine_id)
@id = id
@run_date = run_date
@location = location
@harvest_time = harvest_time
@supplier = supplier
@distributor = distributor
@other = other
@machine_id = machine_id
end
end
client = Mysql2::Client.new(
#INSERT LOGIN INFO HERE
)
runs = []
CSV.foreach("#{ARGV[0]}") do |row|
runs.push(Run.new(*row)) unless row[0] == "run_id"
end
runs.each do |run|
puts run.inspect
query = "INSERT INTO runs (id, runDate, location, harvest_time, supplier, distributor,
other, machine_id, created_at, updated_at)
VALUES
(#{run.id},NOW(), \"UMD\" ,\"#{run.location}\",\"#{run.supplier}\",
\"#{run.distributor}\",\"\",1,NOW(),NOW());"
res = client.query(query)
puts res
end