summaryrefslogtreecommitdiff
path: root/db/migrate/20180201110056_add_foreign_keys_to_todos.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrate/20180201110056_add_foreign_keys_to_todos.rb')
-rw-r--r--db/migrate/20180201110056_add_foreign_keys_to_todos.rb38
1 files changed, 0 insertions, 38 deletions
diff --git a/db/migrate/20180201110056_add_foreign_keys_to_todos.rb b/db/migrate/20180201110056_add_foreign_keys_to_todos.rb
deleted file mode 100644
index 6b217632a52..00000000000
--- a/db/migrate/20180201110056_add_foreign_keys_to_todos.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-class AddForeignKeysToTodos < ActiveRecord::Migration[4.2]
- include Gitlab::Database::MigrationHelpers
-
- class Todo < ActiveRecord::Base
- self.table_name = 'todos'
- include EachBatch
- end
-
- BATCH_SIZE = 1000
-
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- def up
- Todo.where('NOT EXISTS ( SELECT true FROM users WHERE id=todos.user_id )').each_batch(of: BATCH_SIZE) do |batch|
- batch.delete_all
- end
-
- Todo.where('NOT EXISTS ( SELECT true FROM users WHERE id=todos.author_id )').each_batch(of: BATCH_SIZE) do |batch|
- batch.delete_all
- end
-
- Todo.where('note_id IS NOT NULL AND NOT EXISTS ( SELECT true FROM notes WHERE id=todos.note_id )').each_batch(of: BATCH_SIZE) do |batch|
- batch.delete_all
- end
-
- add_concurrent_foreign_key :todos, :users, column: :user_id, on_delete: :cascade
- add_concurrent_foreign_key :todos, :users, column: :author_id, on_delete: :cascade
- add_concurrent_foreign_key :todos, :notes, column: :note_id, on_delete: :cascade
- end
-
- def down
- remove_foreign_key :todos, column: :user_id
- remove_foreign_key :todos, column: :author_id
- remove_foreign_key :todos, :notes
- end
-end