# "deprecate" a column

**URL:** <https://www.ruby-forum.com/t/deprecate-a-column/114378>\
**Category:** Rails\
**Created:** [September 11, 2007, 11:45pm UTC](https://www.ruby-forum.com/t/deprecate-a-column/114378 "2007-09-11T23:45:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chillexistence](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ee7513/32.png) [@chillexistence](https://www.ruby-forum.com/u/chillexistence)\
**Post date:** [September 11, 2007, 11:45pm UTC](https://www.ruby-forum.com/t/deprecate-a-column/114378/1 "2007-09-11T23:45:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![chillexistence](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ee7513/32.png) [@chillexistence](https://www.ruby-forum.com/u/chillexistence)\
**Post date:** [September 12, 2007, 12:35am UTC](https://www.ruby-forum.com/t/deprecate-a-column/114378/2 "2007-09-12T00:35:40Z")

</div>

> 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](http://www.railsify.com/plugins/61-validates-constancy)

-philip

---

<div class="post-metadata">

**Author:** ![chillexistence](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ee7513/32.png) [@chillexistence](https://www.ruby-forum.com/u/chillexistence)\
**Post date:** [September 12, 2007, 12:53am UTC](https://www.ruby-forum.com/t/deprecate-a-column/114378/3 "2007-09-12T00:53:50Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![chillexistence](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ee7513/32.png) [@chillexistence](https://www.ruby-forum.com/u/chillexistence)\
**Post date:** [September 12, 2007, 1:22am UTC](https://www.ruby-forum.com/t/deprecate-a-column/114378/4 "2007-09-12T01:22:49Z")

</div>

oh, it’s actually this simple:

class User \< ActiveRecord::Base

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

end
