From bcb47a843bc3e8430cadea7f98b41e9963ace2de Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 13 Mar 2008 02:17:04 +0000 Subject: Added add/remove_timestamps to the schema statements for adding the created_at/updated_at columns on existing tables (closes #11129) [jramirez] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9014 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../connection_adapters/abstract/schema_statements.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 8bbadd67e7..b471b153de 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -298,6 +298,22 @@ module ActiveRecord sql << " ORDER BY #{options[:order]}" end + # Adds timestamps (created_at and updated_at) columns to the named table. + # ===== Examples + # add_timestamps(:suppliers) + def add_timestamps(table_name) + add_column table_name, :created_at, :datetime + add_column table_name, :updated_at, :datetime + end + + # Removes the timestamp columns (created_at and updated_at) from the table definition. + # ===== Examples + # remove_timestamps(:suppliers) + def remove_timestamps(table_name) + remove_column table_name, :updated_at + remove_column table_name, :created_at + end + protected def options_include_default?(options) options.include?(:default) && !(options[:null] == false && options[:default].nil?) -- cgit v1.2.3