Ron Warholic 11 years ago
parent
commit
6cbe0f8b57
  1. 10
      db/seeds.rb

10
db/seeds.rb

@ -14,10 +14,12 @@ end
#Load bike brands and models from sql #Load bike brands and models from sql
if BikeBrand.all.empty? and BikeModel.all.empty? if BikeBrand.all.empty? and BikeModel.all.empty?
sql_path = File.join(Rails.root, 'db', 'seed', 'sql', 'bike_brands_and_models.sql') # Need to use DEFAULT instead of explicit IDs that are used in the sql file,
db_config = Rails.application.config.database_configuration[Rails.env] # so that the PG table ID sequence is incremented
cmd = "psql #{db_config["database"]} < #{sql_path}" load_statements = File.readlines(File.join(Rails.root, 'db', 'seed', 'sql', 'bike_brands_and_models.sql')).drop(1).map do |statement|
system cmd statement.sub(/VALUES\(\d+,/, 'VALUES(DEFAULT,').tap {|x| puts x }
end
ActiveRecord::Base.connection.execute(load_statements.join)
end end
if Rails.env.development? if Rails.env.development?

Loading…
Cancel
Save