Kornfeld
Kornfeld

Reputation: 1

delete data from postgres database using heroku (ruby on rails)

I am developing an website with heroku (ruby on rails). I use the postgres database. Now I made a mistake and there is a row inside this database which I want to delete. But I have no access. The data is shown on the website. But there is no picture or other content. It was just a trial and a big error ;)

How can I delete this data without to delete the whole database? I found nothing...

I hope you can help me.

with best regards

Upvotes: 0

Views: 2980

Answers (2)

Mason
Mason

Reputation: 161

I'm a little late here, but this might help someone who stumbles across this thread...

If you go to your Heroku app's dashboard (through the website) > settings > "Reveal Config Vars" > DATABASE_URL, and then paste that URL into the browser.

I use TablePlus for database management, when I paste the link into the browser it asks if it can open TablePlus and then I can edit my production database in real time like I would in development.

I'm not sure what pasting the URL into the browser will do if you don't have TablePlus. I imagine it will request to open any other SQL management app you might have.

Upvotes: 1

ChrisJ
ChrisJ

Reputation: 2812

Assuming your rails application is otherwise configured properly (I'm guessing it is, since you got it far enough to insert that incorrect row in the database), as the comments said, you can use the heroku toolbelt to access the rails console.

To install the heroku toolbelt follow the instructions here.

Since you've been developing in Rails, this will probably feel most familiar.

Open a terminal window, change to your application directory, and run

heroku run rails c

This should give you something like this

Loading production environment (Rails 4.2.0)
irb(main):001:0>

From there you can type rails code and the console will run that code against your database.

eg if the model you want to delete is a Post, then you might type

Post.pluck :name

to find the names of the posts you have.

Then you might do

Post.where(name: 'my broken post').destroy_all

Upvotes: 1

Related Questions