diff options
author | blackst0ne <blackst0ne.ru@gmail.com> | 2017-06-13 14:44:13 +0300 |
---|---|---|
committer | blackst0ne <blackst0ne.ru@gmail.com> | 2017-06-13 14:44:13 +0300 |
commit | bc00806a4eec785068671f2c995febe01682c2d0 (patch) | |
tree | a44f9408df37e2f6ee8c07d8f081b5a2a82684e4 /config/initializers/active_record_table_definition.rb | |
parent | de20057ccbd3b8c94d64ff5d8deb14cab232d08a (diff) |
Add database helpers 'add_timestamps_with_timezone' and 'timestamps_with_timezone'
Diffstat (limited to 'config/initializers/active_record_table_definition.rb')
-rw-r--r-- | config/initializers/active_record_table_definition.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/config/initializers/active_record_table_definition.rb b/config/initializers/active_record_table_definition.rb new file mode 100644 index 00000000000..4f59e35f4da --- /dev/null +++ b/config/initializers/active_record_table_definition.rb @@ -0,0 +1,24 @@ +# ActiveRecord custom method definitions with timezone information. +# See https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/11229 + +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 ConnectionAdapters + class TableDefinition + def timestamps_with_timezone(**options) + options[:null] = false if options[:null].nil? + + [:created_at, :updated_at].each do |column_name| + column(column_name, :datetime_with_timezone, options) + end + end + end + end +end |