aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb16
1 files changed, 16 insertions, 0 deletions
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?)