Commit 0a863c8b authored by Michael Kozono's avatar Michael Kozono

Add `datetime_with_timezone` to table definition

So the method can be used in a `create_table` block. There is a new Rubocop style cop that requires the usage of `datetime_with_timezone`.
parent 45b1de84
...@@ -3,15 +3,15 @@ ...@@ -3,15 +3,15 @@
require 'active_record/connection_adapters/abstract/schema_definitions' require 'active_record/connection_adapters/abstract/schema_definitions'
# Appends columns `created_at` and `updated_at` to a table.
#
# It is used in table creation like:
# create_table 'users' do |t|
# t.timestamps_with_timezone
# end
module ActiveRecord module ActiveRecord
module ConnectionAdapters module ConnectionAdapters
class TableDefinition class TableDefinition
# Appends columns `created_at` and `updated_at` to a table.
#
# It is used in table creation like:
# create_table 'users' do |t|
# t.timestamps_with_timezone
# end
def timestamps_with_timezone(**options) def timestamps_with_timezone(**options)
options[:null] = false if options[:null].nil? options[:null] = false if options[:null].nil?
...@@ -19,6 +19,16 @@ module ActiveRecord ...@@ -19,6 +19,16 @@ module ActiveRecord
column(column_name, :datetime_with_timezone, options) column(column_name, :datetime_with_timezone, options)
end end
end end
# Adds specified column with appropriate timestamp type
#
# It is used in table creation like:
# create_table 'users' do |t|
# t.datetime_with_timezone :did_something_at
# end
def datetime_with_timezone(column_name, **options)
column(column_name, :datetime_with_timezone, options)
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment