I'm new to rails and have just had my first bad experience with the mighty rails console. I overwrote a column in ALL instead of just one record and after hours of googling I did not find a common way to rollback this stupid transaction (ended up fixing 76 rows manually!).

I was working on the live environment on heroku and just wanted to fix one entry. There must be a way to rollback a transaction in the database (postgres) if you did stupid things - not by using pgbackup.

Would be great if you can share some best pratices with me or give me a good reading to start. Thanks!

有帮助吗?

解决方案

I'm assuming you've already committed the transaction, but just in case you haven't, you can simply do:

ROLLBACK TRANSACTION;

Since I'm assuming you've tried that, the unfortunate answer is that your only option is a database restore from the last known good state.

There are some options and plugins that might help avoid this problem in the future, but they all come with performance costs. See these other Stack Overflow questions for some information Database Content Versioning and Postgres reverting back.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top