Skip to content

Commit

Permalink
Migration keep :deleted_on as the only only source of truth for disco…
Browse files Browse the repository at this point in the history
…nnect

Migration keep :deleted_on as the only only source of truth for disconnect
  • Loading branch information
Ladas committed Jun 22, 2017
1 parent 7b3bfde commit c6199d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
31 changes: 10 additions & 21 deletions db/migrate/20170530102506_add_deleted_to_containers_tables.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
class AddDeletedToContainersTables < ActiveRecord::Migration[5.0]
def change
add_column :container_definitions, :deleted, :boolean, :default => false, :null => false
add_column :container_groups, :deleted, :boolean, :default => false, :null => false
add_column :container_images, :deleted, :boolean, :default => false, :null => false
add_column :container_projects, :deleted, :boolean, :default => false, :null => false
add_column :containers, :deleted, :boolean, :default => false, :null => false

add_index :container_definitions, :deleted,
:name => "index_container_definitions_on_deleted_false",
:where => "NOT deleted"
add_index :container_groups, :deleted,
:name => "container_groups_on_deleted_false",
:where => "NOT deleted"
add_index :container_images, :deleted,
:name => "index_container_images_on_deleted_false",
:where => "NOT deleted"
add_index :container_projects, :deleted,
:name => "index_container_projects_on_deleted_false",
:where => "NOT deleted"
add_index :containers, :deleted,
:name => "index_containers_on_deleted_false",
:where => "NOT deleted"
add_index :container_definitions, :deleted_on,
:name => "index_container_definitions_on_deleted_on"
add_index :container_groups, :deleted_on,
:name => "container_groups_on_deleted_on"
add_index :container_images, :deleted_on,
:name => "index_container_images_on_deleted_on"
add_index :container_projects, :deleted_on,
:name => "index_container_projects_on_deleted_on"
add_index :containers, :deleted_on,
:name => "index_containers_on_deleted_on"
end
end
4 changes: 2 additions & 2 deletions db/migrate/20170530102536_use_deleted_in_containers_tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class Container < ActiveRecord::Base
end

def disconnect_to_soft_delete(model)
model.where(:ems_id => nil).update_all("ems_id = old_ems_id, deleted = 't'")
model.where.not(:deleted_on => nil).update_all("ems_id = old_ems_id")
end

def soft_delete_to_disconnect(model)
model.where(:deleted => true).update_all(:ems_id => nil, :deleted => false)
model.where.not(:deleted_on => nil).update_all(:ems_id => nil)
end

def up
Expand Down

0 comments on commit c6199d7

Please sign in to comment.