1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 class SplitExpiryToTrashAndDelete < ActiveRecord::Migration[4.2]
7 Collection.transaction do
8 add_column(:collections, :trash_at, :datetime)
9 add_index(:collections, :trash_at)
10 add_column(:collections, :is_trashed, :boolean, null: false, default: false)
11 add_index(:collections, :is_trashed)
12 rename_column(:collections, :expires_at, :delete_at)
13 add_index(:collections, :delete_at)
15 Collection.reset_column_information
17 where('delete_at is not null and delete_at <= statement_timestamp()').
20 where('delete_at is not null').
21 update_all('is_trashed = true, trash_at = statement_timestamp()')
22 add_index(:collections, [:owner_uuid, :name],
24 where: 'is_trashed = false',
25 name: 'index_collections_on_owner_uuid_and_name')
26 remove_index(:collections,
27 name: 'collection_owner_uuid_name_unique')
32 Collection.transaction do
33 remove_index(:collections, :delete_at)
34 rename_column(:collections, :delete_at, :expires_at)
35 add_index(:collections, [:owner_uuid, :name],
37 where: 'expires_at is null',
38 name: 'collection_owner_uuid_name_unique')
39 remove_index(:collections,
40 name: 'index_collections_on_owner_uuid_and_name')
41 remove_column(:collections, :is_trashed)
42 remove_index(:collections, :trash_at)
43 remove_column(:collections, :trash_at)