Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to manually manupulate data in the production database?

Anthony Candaele asked in General

Hi,

I just successfully deployed my Rails app to a Digital Ocean VPS, following the Deploy Rails guide on this website. Many thanks go to Chris Oliver and James Dullaghan for their help and patience.

Now my app is deployed, I need to create an admin user so I can log in and start to create content.

On heroku I was able manipulate the database through the Rails console, with the command:

heroku run rails console

However, I'm not sure how to manually enter data in the database on my VPS.
Can I also spin a Rails console and access the production database, or do I need to do this another way?

Thanks for your help,

Anthony

Reply

found it, because on the vps I don't have a development environment, I need to start the Rails console in the 'current' folder with:

RAILS_ENV=production bundle exec rails c
Reply

Glad you found it. Here's a protip. If you ever want to test out different code, queries, or manipulate data without permanently writing to the database use the sandbox option.

RAILS_ENV=production bundle exec rails c --sandbox

This will give you a Rails console where you can test out your code and manipulate data in realtime to see what the effects are. Once you exit the console, all changes are rolledback so it's a really safe way to play with production data before you manipulate anything permanently.

Reply

Hi, sorry to bring this topic up again after almost a year. I did as the tutorial showed by Chris to set up a digital ocean vps on Ubunto 14.04 with passenger phusion, nginx and capistrano. However, I am not able to access the the rails console when on my virtual machine. The command above doesn't work for me. It shows..

Usage: rails new APP_PATH [options]

I even tried installing capistrano-rails-console gem but it still show the same error message.

To add, the app works fine after I deployed it last night. It would be great if I could get into console to add some records.

Reply

Ok got it to work. Had to remove bin from set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}.
This is for capistrano 3.

Reply

Ah yeah! I've had to remove bin from that as well. Not sure what changed but that definitely fixes the problem.

Reply

Thanks Chris! Yea spent a whole day trying to figure it out. Most answers were for capistrano 2. Tried installing capistrano rails console and still nothing. Hope it helps anyone facing the same problem. Maybe I'll post a comment on the deployment guide to share this tip.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,972+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.