Skip to content

Instantly share code, notes, and snippets.

View duderman's full-sized avatar
🤘

Nick Norkin duderman

🤘
  • London
  • 12:31 (UTC)
View GitHub Profile
@duderman
duderman / load_supplier_products.rb
Last active August 29, 2015 14:14
Loads supplier products from csv file
def import_supplier_products(path)
fail unless File.file? path
supplier_mappings = {
'224' => '372bd2a4-258d-48f3-9f84-598e1f09b657',
'445' => '0235c6b5-b399-40ad-91f3-cbe7b02ca565'
}
imported, failed = [], []
CSV.foreach(path) do |row|
manufacturer = Registry::Manufacturer.find_or_create_by(name: row[3])
sp = SupplierProduct.new(
@duderman
duderman / load_missed_migrations.rb
Last active August 29, 2015 14:09
Loads all migrations
files = Dir.glob("db/migrate/*")
timestamps = files.collect{|f| f.split("/").last.split("_").first}
timestamps.count
migrations = ActiveRecord::Base.connection.execute("SELECT version FROM schema_migrations", as: :array).to_a.flatten
needs = timestamps - migrations
files_needs = files.select { |f| needs.include? f.split("/").last.split("_").first }
files_needs.sort.each do |f|
begin
require "#{Rails.root}/#{f}"
f.split('/').last.split('_')[1..-1].join('_').split('.').first.camelize.constantize.new.up