Skip to content

Instantly share code, notes, and snippets.

View nflorentin's full-sized avatar

Nicolas Florentin nflorentin

  • Sleede
  • Grenoble, France
View GitHub Profile
@nflorentin
nflorentin / script.rb
Created June 29, 2016 08:09
visualize a rails fixtures
ActiveRecord::FixtureSet::File.open("#{Rails.root}/test/fixtures/settings.yml") do |fh|
fh.each do |fn, row|
p fn
p row
end
end
# see https://github.com/rails/rails/blob/v4.2.6/activerecord/lib/active_record/fixtures.rb
class MigrateDataFromMachinesPricingsToPrices < ActiveRecord::Migration
def up
insert <<-SQL
DELETE FROM machines_pricings WHERE machine_id NOT IN ( select distinct machines.id from machines )
SQL
machines_pricings = select_all("SELECT * FROM machines_pricings")
machines_pricings.each do |m_pricing|
time = "'#{Time.now.to_s(:db)}'"