summaryrefslogtreecommitdiff
path: root/rubocop/cop/migration/datetime.rb
diff options
context:
space:
mode:
authorblackst0ne <blackst0ne.ru@gmail.com>2017-06-13 22:44:13 +1100
committerblackst0ne <blackst0ne.ru@gmail.com>2017-06-13 22:44:13 +1100
commitbc00806a4eec785068671f2c995febe01682c2d0 (patch)
treea44f9408df37e2f6ee8c07d8f081b5a2a82684e4 /rubocop/cop/migration/datetime.rb
parentde20057ccbd3b8c94d64ff5d8deb14cab232d08a (diff)
downloadgitlab-ce-bc00806a4eec785068671f2c995febe01682c2d0.tar.gz
Add database helpers 'add_timestamps_with_timezone' and 'timestamps_with_timezone'32054-rails-should-use-timestamptz-database-type-for-postgresql
Diffstat (limited to 'rubocop/cop/migration/datetime.rb')
-rw-r--r--rubocop/cop/migration/datetime.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/rubocop/cop/migration/datetime.rb b/rubocop/cop/migration/datetime.rb
new file mode 100644
index 00000000000..651935dd53e
--- /dev/null
+++ b/rubocop/cop/migration/datetime.rb
@@ -0,0 +1,36 @@
+require_relative '../../migration_helpers'
+
+module RuboCop
+ module Cop
+ module Migration
+ # Cop that checks if datetime data type is added with timezone information.
+ class Datetime < RuboCop::Cop::Cop
+ include MigrationHelpers
+
+ MSG = 'Do not use the `datetime` data type, use `datetime_with_timezone` instead'.freeze
+
+ # Check methods in table creation.
+ def on_def(node)
+ return unless in_migration?(node)
+
+ node.each_descendant(:send) do |send_node|
+ add_offense(send_node, :selector) if method_name(send_node) == :datetime
+ end
+ end
+
+ # Check methods.
+ def on_send(node)
+ return unless in_migration?(node)
+
+ node.each_descendant do |descendant|
+ add_offense(node, :expression) if descendant.type == :sym && descendant.children.last == :datetime
+ end
+ end
+
+ def method_name(node)
+ node.children[1]
+ end
+ end
+ end
+ end
+end