3

I am using sqlite for both (for now) my development and production system on rails. I have a development.sqlite3 file that I want to copy over to production.sqlite3 to run some testing in a production environment.

I've tried to copy the development db over to the production just by doing mv development.sqlite3 production.sqlite3 and that doesn't seem to be working.

Any ideas on how best to go about doing this?

Noah Clark
  • 8,101
  • 14
  • 74
  • 116

1 Answers1

4

According to this question the following code does it.

RAILS_ENV=production rake db:create db:schema:load

This empties out the current production.sqlite3. After the database creation and loading of the structure you can copy the development.sqlite3 to production.sqlite3 to copy your data.

cp db/development.sqlite3 db/production.sqlite3
Community
  • 1
  • 1
Frans
  • 1,389
  • 2
  • 16
  • 28
  • I've tried that and it doesn't seem to be working. Is there a way to test to make sure the data is in production.sqlite3 and a way to make sure that rails knows it is in the production environment. – Noah Clark Dec 10 '11 at 15:05
  • I just ran `select * from posts;` inside of sqlite3 and confirmed there is no data in the db. Am I doing something wrong? I ran those commands from the command line and it seemed to work with output that you would expect. – Noah Clark Dec 10 '11 at 15:37
  • To start rails server in production you run `rails server production`, and to start the console you run `rails console -e production`. You found no data in production.sqlite3 with sqlite3? If you've copied development.sqlite3 you should have the exact same data, no matter what Rails can see. – Frans Dec 10 '11 at 18:21
  • Did you copy the file again after db:create and db:schema:load? Otherwise it actually should be empty, as db:schema:load clears out the current db. – Frans Dec 10 '11 at 18:27
  • yeah, I forgot to copy it over after I ran that. – Noah Clark Dec 10 '11 at 19:38