X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/2c5abff2c2799d6eb7ddc59c18091bc0170962a2..a7631a1ccb6e2a6925d00a06562e171c4ce4ea2f:/services/api/db/migrate/20170824202826_trashable_groups.rb diff --git a/services/api/db/migrate/20170824202826_trashable_groups.rb b/services/api/db/migrate/20170824202826_trashable_groups.rb index b7e3373c66..81a4722652 100644 --- a/services/api/db/migrate/20170824202826_trashable_groups.rb +++ b/services/api/db/migrate/20170824202826_trashable_groups.rb @@ -1,7 +1,42 @@ -class TrashableGroups < ActiveRecord::Migration - def change +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + +class TrashableGroups < ActiveRecord::Migration[4.2] + def up add_column :groups, :trash_at, :datetime - add_column :groups, :delete_at, :datetime + add_index(:groups, :trash_at) + add_column :groups, :is_trashed, :boolean, null: false, default: false + add_index(:groups, :is_trashed) + + add_column :groups, :delete_at, :datetime + add_index(:groups, :delete_at) + + Group.reset_column_information + add_index(:groups, [:owner_uuid, :name], + unique: true, + where: 'is_trashed = false', + name: 'index_groups_on_owner_uuid_and_name') + remove_index(:groups, + name: 'groups_owner_uuid_name_unique') + end + + def down + Group.transaction do + add_index(:groups, [:owner_uuid, :name], unique: true, + name: 'groups_owner_uuid_name_unique') + remove_index(:groups, + name: 'index_groups_on_owner_uuid_and_name') + + remove_index(:groups, :delete_at) + remove_column(:groups, :delete_at) + + remove_index(:groups, :is_trashed) + remove_column(:groups, :is_trashed) + + remove_index(:groups, :trash_at) + remove_column(:groups, :trash_at) + end end end