summaryrefslogtreecommitdiff
path: root/rubocop/migration_helpers.rb
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-06-24 17:26:28 +0200
committerYorick Peterse <yorickpeterse@gmail.com>2016-06-29 14:14:02 +0200
commitc740445ad3825da4e5f7fea943be561ece982443 (patch)
treec5b99c0d3665c720b6c307e5b0806767f7b7b19d /rubocop/migration_helpers.rb
parentd33991f8cc343cef704d04fd7b97c69887f3299b (diff)
downloadgitlab-ce-c740445ad3825da4e5f7fea943be561ece982443.tar.gz
Added RuboCop cops for checking DB migrationsmigration-cops
There are currently two cops for this: * Migration/AddIndex: checks if indexes are added concurrently * Migration/ColumnWithDefault: checks if columns with default values are added in a concurrent manner Both cops are fairly simple and make no attempt at correcting the code as this is quite hard to do (e.g. modifications may need to be applied in various places in the same file). They however should provide enough to catch people ignoring the comments in generated migrations telling them to use add_concurrent_index or add_column_with_default.
Diffstat (limited to 'rubocop/migration_helpers.rb')
-rw-r--r--rubocop/migration_helpers.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/rubocop/migration_helpers.rb b/rubocop/migration_helpers.rb
new file mode 100644
index 00000000000..3160a784a04
--- /dev/null
+++ b/rubocop/migration_helpers.rb
@@ -0,0 +1,10 @@
+module RuboCop
+ # Module containing helper methods for writing migration cops.
+ module MigrationHelpers
+ # Returns true if the given node originated from the db/migrate directory.
+ def in_migration?(node)
+ File.dirname(node.location.expression.source_buffer.name).
+ end_with?('db/migrate')
+ end
+ end
+end