Thursday, 15 March 2012

heroku - What is the best way to drop a table & remove a model in Rails 3? -


I have a model & amp; A table which is no longer needed in my app, I can leave them there but I would like to remove them to keep them clean.

I'm trying to figure out the best way to get them out of my migration & amp; DB / Schema RB files & amp; This can be any side effects in my production environment, my app is on Heroka, I am using PostgreSQL on my local machine and on both;

So far, I have found two ways to do this, but I am not sure who is the best way?

Method 1

I thought about going to my database; Leaving the table & amp; Then destroyed the model.

  Rail DB drop table table_name \ q Removing rail model model_name   

If I do this then what will happen to me for migration? Table? I have two migration for this model, a timestamp_create_model name & amp; An add_attribute_to_table name

Will this method be updated in the DB / SchemaRb file?

When I put the app in Harkaku, I suspect that the model will be removed, but the table will remain in place, there is a command to leave the table.

Method Two

In another way I have read that to leave the table was to create a new migration & amp; Then destroy the model.

  Rail Migration drop_base name   

& amp; Then update the file below:

db / migrate / timestamp_drop_tablename (reply to Dan Witch's reply has been updated in response)

  class DropTablename & Lt; ActiveRecord :: Migration def up drop_table: tablename end def to create_table: tablename do | T | T.string: table_column t.references: other tables t.timestamps end add_index: tablenames, anothertable_id end and   

& amp; Then in the terminal:

  rake db: delete the migrated rail model model ram db: migrate git add git commit -m "deleted table / model_name" git has its Koku master Heroku run rake db Pushed: migrate to restart   

This is the best way, but what happens to old migration files? Will they stay & amp; Update DB / SHAMA Every time I run Rake DB: is to migrate only to DB / migrate / timestamp_drop_tablename override?

I am happy to experiment with the second method, but someone should experience with someone in & amp; Tell me the railway route to do this

The other way is the ideal way to handle: Your migration files Your database has to be changed over time The old migration file will be in your project (if you want to roll back to an earlier version, you hypothetically), but when you rake db: migrate will not run because the railways know Received that they are already running the same (based on data Skima_magreshn table of the database) is.

Your schema. RB will be updated only once that your database is no longer in that table.

One minor changes to your code: Your migration file should leave the table in the above method, and recreate it in the down method. The "above" indicates that your migration leaves the table to advance in time, and if the migration is brought back, then the down method will run.

No comments:

Post a Comment