diff options
author | Andreas Brandl <abrandl@gitlab.com> | 2018-03-20 16:38:43 +0300 |
---|---|---|
committer | Andreas Brandl <abrandl@gitlab.com> | 2018-03-20 20:44:00 +0300 |
commit | 1362d9fe1383a2fa2cca563435064e622ec8e043 (patch) | |
tree | 1a7f473883e1c3eb9e0795ec6ad64d3383087475 /doc/development/migration_style_guide.md | |
parent | 35097c191ef1cf1d8d9070c5978647b54e116b5c (diff) |
Shortcut concurrent index creation/removal if no effect.
Index creation does not have an effect if the index is present already.
Index removal does not have an affect if the index is not present.
This helps to avoid patterns like this in migrations:
```
if index_exists?(...)
remove_concurrent_index(...)
end
```
Diffstat (limited to 'doc/development/migration_style_guide.md')
-rw-r--r-- | doc/development/migration_style_guide.md | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/doc/development/migration_style_guide.md b/doc/development/migration_style_guide.md index 243ac7f0c98..1e060ffd941 100644 --- a/doc/development/migration_style_guide.md +++ b/doc/development/migration_style_guide.md @@ -136,11 +136,14 @@ class MyMigration < ActiveRecord::Migration disable_ddl_transaction! def up - remove_concurrent_index :table_name, :column_name if index_exists?(:table_name, :column_name) + remove_concurrent_index :table_name, :column_name end end ``` +Note that it is not necessary to check if the index exists prior to +removing it. + ## Adding indexes If you need to add a unique index please keep in mind there is the possibility |