Rails - Will I lose my development database when I

2019-08-06 15:50发布

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!

2条回答
Emotional °昔
2楼-- · 2019-08-06 16:08

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
查看更多
We Are One
3楼-- · 2019-08-06 16:09

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.

查看更多
登录 后发表回答