ruby on rails - Ran Seed Data on Production Mysql Database Cleardb Heroku Data randomly generated fabricator faker -
i have simple rails app hosted on heroku using cleardb mysql add on. developing on mysql locally. having problem seeding data on production db on heroku.
my seed data looks in db/seeds.rb. app using faker , fabrication gems. have user model , person model.
fabricator(:user) first_name { faker::name.first_name } last_name { faker::name.last_name } birthday { faker::date.backward(14000) } phone_number { faker::phonenumber.phone_number } street { faker::address.street_address } city { faker::address.city } state { faker::address.state_abbr } zip_code { faker::address.zip } education { "bachelor" } image { file.open("app/assets/images/helloworld.jpg")} end fabricator(:person) full_name { faker::name.name } email { faker::internet.email } image { file.open("app/assets/images/puppy.jpg")} friend_test { 0 } user end #40.times { fabricate(:user)} #comment out because running below command generate user 40.times { fabricate(:person)} person.create(full_name: "ben franklin", email: "ben@gmail.com", friend_test: 0, image: file.open("app/assets/images/puppy.jpg"), user_id: 1) person.create(full_name: "george washington", email: "george@gmail.com", friend_test: 0, image: file.open("app/assets/images/puppy.jpg"), user_id: 1) person.create(full_name: "john adam", email: "john@gmail.com", friend_test: 0, image: file.open("app/assets/images/puppy.jpg"), user_id: 1) person.create(full_name: "barack obama", email: "barack@gmail.com", friend_test: 0, image: file.open("app/assets/images/puppy.jpg"), user_id: 2) person.create(full_name: "john kennedy", email: "john@gmail.com", friend_test: 0, image: file.open("app/assets/images/puppy.jpg"), user_id: 2) person.create(full_name: "andrew jackson", email: "andrew@gmail.com", friend_test: 0, image: file.open("app/assets/images/puppy.jpg"), user_id: 2) person.create(full_name: "jimmy carter", email: "jimmy@gmail.com", friend_test: 0, image: file.open("app/assets/images/puppy.jpg"), user_id: 3) person.create(full_name: "gerald ford", email: "gerald@gmail.com", friend_test: 0, image: file.open("app/assets/images/puppy.jpg"), user_id: 3) person.create(full_name: "richard nixon", email: "richard@gmail.com", friend_test: 0, image: file.open("app/assets/images/puppy.jpg"), user_id: 3)
initially thought didn't seed correctly because not clearing db correctly (since heroku don't play mysql) . ran through of these steps , think narrow down problem seeding action instead.
heroku run rake db:drop heroku run rake db:create heroku run rake db:migrate heroku run rake db:setup heroku run rake db:seed #problem
when run
heroku run rails console
and user.all
the seed data created user_id =1 jump user_id = 11 , user_id = 21. same person model. odd since locally when run commands locally user id 1 40 , same person_id 1 40. local db fine. have logic in view depends on records go 1 1 , not randomly.
also rails 4.1.8
app.
updated of dec 8 2014
yes using mysql both locally , in production, here database.yml file
development: adapter: mysql2 encoding: utf8 database: mini_facebook_development pool: 5 username: root password: socket: /tmp/mysql.sock staging: adapter: mysql2 encoding: utf8 database: mini_facebook_staging pool: 5 username: root password: socket: /tmp/mysql.sock test: adapter: mysql2 encoding: utf8 database: mini_facebook_test pool: 5 username: root password: socket: /tmp/mysql.sock
and
gem 'mysql2', '~> 0.3.17'
i don't have production set here. using heroku config , heroku docs, there database.yml generated anyway.
Comments
Post a Comment