diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /doc/development/what_requires_downtime.md | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) | |
download | gitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'doc/development/what_requires_downtime.md')
-rw-r--r-- | doc/development/what_requires_downtime.md | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/doc/development/what_requires_downtime.md b/doc/development/what_requires_downtime.md index 407899b23d5..d0b8aa18f5c 100644 --- a/doc/development/what_requires_downtime.md +++ b/doc/development/what_requires_downtime.md @@ -130,7 +130,8 @@ class CleanupUsersUpdatedAtRename < ActiveRecord::Migration[4.2] end ``` -NOTE: **Note:** If you're renaming a [large table](https://gitlab.com/gitlab-org/gitlab/-/blob/master/rubocop/rubocop-migrations.yml#L3), please carefully consider the state when the first migration has run but the second cleanup migration hasn't been run yet. +NOTE: **Note:** +If you're renaming a [large table](https://gitlab.com/gitlab-org/gitlab/-/blob/master/rubocop/rubocop-migrations.yml#L3), please carefully consider the state when the first migration has run but the second cleanup migration hasn't been run yet. With [Canary](https://about.gitlab.com/handbook/engineering/infrastructure/library/canary/) it is possible that the system runs in this state for a significant amount of time. ## Changing Column Constraints @@ -202,6 +203,21 @@ end And that's it, we're done! +### Casting data to a new type + +Some type changes require casting data to a new type. For example when changing from `text` to `jsonb`. +In this case, use the `type_cast_function` option. +Make sure there is no bad data and the cast will always succeed. You can also provide a custom function that handles +casting errors. + +Example migration: + +```ruby + def up + change_column_type_concurrently :users, :settings, :jsonb, type_cast_function: 'jsonb' + end +``` + ## Changing The Schema For Large Tables While `change_column_type_concurrently` and `rename_column_concurrently` can be @@ -317,30 +333,11 @@ migrations](background_migrations.md#cleaning-up). ## Adding Indexes -Adding indexes is an expensive process that blocks INSERT and UPDATE queries for -the duration. You can work around this by using the `CONCURRENTLY` option: - -```sql -CREATE INDEX CONCURRENTLY index_name ON projects (column_name); -``` - -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 -``` +Adding indexes does not require downtime when `add_concurrent_index` +is used. -Note that `add_concurrent_index` can not be reversed automatically, thus you -need to manually define `up` and `down`. +See also [Migration Style Guide](migration_style_guide.md#adding-indexes) +for more information. ## Dropping Indexes |