mirror of
https://github.com/oonyeje/Pearlception_Website_RoR.git
synced 2025-12-25 03:37:40 +00:00
Add migration script for aws->local server data migration
This commit is contained in:
parent
a2d7d91615
commit
80d4df4b34
@ -13,9 +13,6 @@ default: &default
|
|||||||
adapter: mysql2
|
adapter: mysql2
|
||||||
encoding: utf8
|
encoding: utf8
|
||||||
pool: 5
|
pool: 5
|
||||||
username: <%= ENV['TEST_USER'] %>
|
|
||||||
password: <%= ENV['TEST_PASS'] %>
|
|
||||||
socket: <%= ENV['TEST_SOCKET'] %>
|
|
||||||
|
|
||||||
stats_development: &stats
|
stats_development: &stats
|
||||||
adapter: mysql2
|
adapter: mysql2
|
||||||
@ -34,8 +31,8 @@ stats_test:
|
|||||||
development:
|
development:
|
||||||
<<: *default
|
<<: *default
|
||||||
database: Pearlception_development
|
database: Pearlception_development
|
||||||
username: root
|
username: bmv
|
||||||
password: Kemitscafe1
|
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".
|
||||||
@ -43,8 +40,8 @@ development:
|
|||||||
test:
|
test:
|
||||||
<<: *default
|
<<: *default
|
||||||
database: Pearlception_test
|
database: Pearlception_test
|
||||||
username: root
|
username: bmv
|
||||||
password: Kemitscafe1
|
password: 1156244terps!
|
||||||
|
|
||||||
# As with config/secrets.yml, you never want to store sensitive information,
|
# 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
|
# like your database password, in your source code. If your source code is
|
||||||
|
|||||||
40
migrate.rb
Normal file
40
migrate.rb
Normal 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
|
||||||
Loading…
x
Reference in New Issue
Block a user