开发者

Drop and Recreate a single table (on Heroku)

开发者 https://www.devze.com 2023-02-15 03:49 出处:网络
My app is in beta, and I\'ve been doing limited testing of a feature that involves a new model. After a fair amount of testing I had to make a structural change that makes the ol开发者_如何学运维d dat

My app is in beta, and I've been doing limited testing of a feature that involves a new model. After a fair amount of testing I had to make a structural change that makes the ol开发者_如何学运维d data non-functional.

What I need to do is just drop and recreate one table. I know that I could do this in a migration, but that seems like such a hack. In a local dev copy I would just use db:reset, but in the beta app I don't want to lose data in any tables except this one.

Is this a simple way to instruct a production app to drop and recreate a single table. In my case, I'm deploying with Heroku, in case that affects how you would solve this issue.


To empty a table on Heroku without changing the schema, in your application's directory:

$ heroku run console
Ruby console for myap.heroku.com
>> ModelName.delete_all
>> exit


I know that I could do this in a migration, but that seems like such a hack.

It's not a hack. It's precisely what migrations are designed to do.


You need to rerun the migration for that table to make structural changes. I haven't used ActiveRecord before, but I'd also delete the data in the table using ModelName.delete_all from heroku console.


heroku run console
irb(main):001:0> ModelName.delete_all

And you are done.

0

精彩评论

暂无评论...
验证码 换一张
取 消