1 class SplitExpiryToTrashAndDelete < ActiveRecord::Migration
3 Collection.transaction do
4 add_column(:collections, :trash_at, :datetime)
5 add_index(:collections, :trash_at)
6 add_column(:collections, :is_trashed, :boolean, null: false, default: false)
7 add_index(:collections, :is_trashed)
8 rename_column(:collections, :expires_at, :delete_at)
9 add_index(:collections, :delete_at)
11 Collection.reset_column_information
13 where('delete_at is not null and delete_at <= statement_timestamp()').
16 where('delete_at is not null').
17 update_all('is_trashed = true, trash_at = statement_timestamp()')
18 add_index(:collections, [:owner_uuid, :name],
20 where: 'is_trashed = false',
21 name: 'index_collections_on_owner_uuid_and_name')
22 remove_index(:collections,
23 name: 'collection_owner_uuid_name_unique')
28 Collection.transaction do
29 remove_index(:collections, :delete_at)
30 rename_column(:collections, :delete_at, :expires_at)
31 add_index(:collections, [:owner_uuid, :name],
33 where: 'expires_at is null',
34 name: 'collection_owner_uuid_name_unique')
35 remove_index(:collections,
36 name: 'index_collections_on_owner_uuid_and_name')
37 remove_column(:collections, :is_trashed)
38 remove_index(:collections, :trash_at)
39 remove_column(:collections, :trash_at)