Merge branch '17004-properties-on-output' refs #17004
[arvados.git] / services / api / db / migrate / 20170824202826_trashable_groups.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class TrashableGroups < ActiveRecord::Migration[4.2]
6   def up
7     add_column :groups, :trash_at, :datetime
8     add_index(:groups, :trash_at)
9
10     add_column :groups, :is_trashed, :boolean, null: false, default: false
11     add_index(:groups, :is_trashed)
12
13     add_column :groups, :delete_at, :datetime
14     add_index(:groups, :delete_at)
15
16     Group.reset_column_information
17     add_index(:groups, [:owner_uuid, :name],
18               unique: true,
19               where: 'is_trashed = false',
20               name: 'index_groups_on_owner_uuid_and_name')
21     remove_index(:groups,
22                  name: 'groups_owner_uuid_name_unique')
23   end
24
25   def down
26     Group.transaction do
27       add_index(:groups, [:owner_uuid, :name], unique: true,
28                 name: 'groups_owner_uuid_name_unique')
29       remove_index(:groups,
30                    name: 'index_groups_on_owner_uuid_and_name')
31
32       remove_index(:groups, :delete_at)
33       remove_column(:groups, :delete_at)
34
35       remove_index(:groups, :is_trashed)
36       remove_column(:groups, :is_trashed)
37
38       remove_index(:groups, :trash_at)
39       remove_column(:groups, :trash_at)
40     end
41   end
42 end