Is it safe to delete updated_at field in rails ActiveRecord?

The title really says it all. I have a Rails 3.2 app with a table of many rows, which are added but never changed or deleted. So the default updated_at column isn't useful, though the created_at column is. Can I safely do a migration to delete only updated_at?

Addition: After a good pointer, I'm still plumbing for the code that creates the SQL update statements. It's here the created_at column would have to be omitted if it weren't in the schema. In this app I can't afford to merely "try it" and assume that if it works in testing it will always work. I need to be absolutely sure. The search and cross-links of the Rails source on line that I can find are not very helpful for drilling down.

Answers


It's actually safe to do so;

Checkout line#204 from the Persitence layer of ActiveRecord : https://github.com/rails/rails/blob/master/activerecord/lib/active_record/persistence.rb

It says :

updated_at/updated_on column is updated if that column is available.

Moreover, if you dig deeper, you'll see that the touch method is what performs the updating of updated_at/on attributes, and it's only invoked if that column exists.

Edit

Digging further: the class /lib/active_record/timestamp.rb is responsible for timestamping the created/updated records, IF the created_at/updated_at column exist. The check is done in Timestamp::create_record where it builds an array of all "to timestamp columns" and loops over them. I guess the code is pretty clear if respond_to?(column) && respond_to?("#{column}=") && self.send(column).nil? write_attribute(column.to_s, current_time)


Need Your Help

Netezza, Teradata, DB2 Parallel/Enterprise, … versus Hadoop or others?

db2 data-warehouse mapreduce teradata netezza

I'm looking at building some data warehousing/querying infrastructure, right now on top of Map/Reduce solutions like Hadoop.

Summing two numbers recursively digit by digit in C

c recursion sum digit

I need to write to recursive functions, where in the first one, I need to sum two integers digit by digit. I have written some code, but it gives me the final result multiplied by 10. I see that the

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.