问题
I know this is probably dumb question but...
Simply put, I have an app with a database of hundreds of records in development mode. When I push to production and deploy onto the internet, will I lose my database and have to redo it all in production mode?
Just being safe!
回答1:
Your production database is not pushed. An empty database with your schemas will be created when you run rake exec db:migrate on your production server.
If you want to automate adding your development database records to your production database, there is a gem called yaml_db. It is easy to use and works on MySQL and PostgreSQl. https://github.com/yamldb/yaml_db.
In gemfile:
gem 'yaml_db'
Then, in your console
$ bundle install
rake db:data:dump -> Dump contents of Rails database to db/data.yml
rake db:data:load -> Load contents of db/data.yml into the database
Take a look at the spec for all details.
EDITED: Addition
RAILS_ENV=development bundle exec rake db:data:dump
RAILS_ENV=production bundle exec rake db:data:load
回答2:
Sort of, you won't lose the data itself, that's stored in a database you configured for the development environment, but your production environment likely will have configured another database, which will be empty.
You could copy the database from the development environment and configure rails to use that in production. Depends a bit on what kind of database you use: mysql, sqlite, etc.
来源:https://stackoverflow.com/questions/29172629/rails-will-i-lose-my-development-database-when-i-push-to-production