Commit 4d09e88a authored by Peter Leitzen's avatar Peter Leitzen

Link to Migration Style Guide in Adding Indexes section

Treat the Migration Style Guide as single source of truth
and link to it from other resources.
parent 7b4340f1
...@@ -495,9 +495,11 @@ by calling the method `disable_ddl_transaction!` in the body of your migration ...@@ -495,9 +495,11 @@ by calling the method `disable_ddl_transaction!` in the body of your migration
class like so: class like so:
```ruby ```ruby
class MyMigration < ActiveRecord::Migration[4.2] class MyMigration < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction! disable_ddl_transaction!
def up def up
......
...@@ -317,30 +317,11 @@ migrations](background_migrations.md#cleaning-up). ...@@ -317,30 +317,11 @@ migrations](background_migrations.md#cleaning-up).
## Adding Indexes ## Adding Indexes
Adding indexes is an expensive process that blocks INSERT and UPDATE queries for Adding indexes does not require downtime when `add_concurrent_index`
the duration. You can work around this by using the `CONCURRENTLY` option: is used.
```sql See also [Migration Style Guide](migration_style_guide.md#adding-indexes)
CREATE INDEX CONCURRENTLY index_name ON projects (column_name); for more information.
```
Migrations can take advantage of this by using the method
`add_concurrent_index`. For example:
```ruby
class MyMigration < ActiveRecord::Migration[4.2]
def up
add_concurrent_index :projects, :column_name
end
def down
remove_index(:projects, :column_name) if index_exists?(:projects, :column_name)
end
end
```
Note that `add_concurrent_index` can not be reversed automatically, thus you
need to manually define `up` and `down`.
## Dropping Indexes ## Dropping Indexes
......
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