diff options
author | Stan Hu <stanhu@gmail.com> | 2018-07-10 16:07:59 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-07-10 23:28:13 -0700 |
commit | da438233822526a4cde5a06dc276806e49c2c968 (patch) | |
tree | 2ed3409ae7c81f9ea48f531a082b0f66a11cef00 | |
parent | c6b670216c6e011e0007a934decdc003a318405b (diff) | |
download | gitlab-ce-sh-make-group-todos-migration-idempotent.tar.gz |
Add existence checks around todos migration to ensure it is idempotentsh-make-group-todos-migration-idempotent
Since this migration disables transactions, it's possible that the columns
and indexes are created but the migration is aborted in
the `change_column_null` column. Check the existence of the
columns/foreign keys/indexes before attempting to add them to prevent
migration failures.
Relates to https://gitlab.com/gitlab-org/release/tasks/issues/312
-rw-r--r-- | db/migrate/20180608091413_add_group_to_todos.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/db/migrate/20180608091413_add_group_to_todos.rb b/db/migrate/20180608091413_add_group_to_todos.rb index af3ee48b29d..f0f7c44d3d2 100644 --- a/db/migrate/20180608091413_add_group_to_todos.rb +++ b/db/migrate/20180608091413_add_group_to_todos.rb @@ -6,7 +6,7 @@ class AddGroupToTodos < ActiveRecord::Migration disable_ddl_transaction! def up - add_column :todos, :group_id, :integer + add_column :todos, :group_id, :integer unless group_id_exists? add_concurrent_foreign_key :todos, :namespaces, column: :group_id, on_delete: :cascade add_concurrent_index :todos, :group_id @@ -16,7 +16,7 @@ class AddGroupToTodos < ActiveRecord::Migration def down return unless group_id_exists? - remove_foreign_key :todos, column: :group_id + remove_foreign_key :todos, column: :group_id if foreign_key_exists?(:todos, :namespaces, column: :group_id) remove_index :todos, :group_id if index_exists?(:todos, :group_id) remove_column :todos, :group_id |