"deprecate" a column

Does anyone know of a plugin to “deprecate” a column so active record
won’t try and save the column back to the DB? This would allow the old
column to eventually be dropped without having to take down your site or
stop mysql replication. For example:

On day 1 you have:

CREATE TABLE users (
id int not null auto_increment primary key,
name varchar(255),
location varchar(255)
);

On day 2 you have lots of INSERT INTO users statements being sent to DB1
and replicated to DB2.

You try and “ALTER TABLE users DROP COLUMN location” but now all these
insert statements start to fail because they still reference the
location column.

We need active record to pretend location is no longer there on insert
and updates. Otherwise we’d have to stop the site and replication and
wait for the drop column command to complete. Could be hours on a large
table.

Thanks.

Does anyone know of a plugin to “deprecate” a column so active record
won’t try and save the column back to the DB? This would allow the old
column to eventually be dropped without having to take down your site or
stop mysql replication. For example:

You may be able to modify this plugin… it says it does half of what
you
want… (the save part, not the create part):

http://www.railsify.com/plugins/61-validates-constancy

-philip

Philip H. wrote:

You may be able to modify this plugin… it says it does half of what
you
want… (the save part, not the create part):

http://www.railsify.com/plugins/61-validates-constancy

-philip

Looking at the code I think all it does is make sure the values are ==
equal. The “update users set name=‘bob’, location=‘123’” still gets
sent to the db.

If I validate constancy of the location field, it’ll make sure it’s
still 123 but still send the same sql. I need the sql to be:

“update users set name=‘bob’”

with no metion of the location column at all.

I’ll try and write a new plugin that lets you do this:

class User < ActiveRecord::Base

deprecate :location

end

oh, it’s actually this simple:

class User < ActiveRecord::Base

def attributes(options = nil)
temp = super
temp.delete(‘location’)
temp
end

end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs