Add migration to backfill accounts.deleted_at

This commit is contained in:
Claire 2023-03-01 15:17:09 +01:00
parent 5956ce9be8
commit 7a30b8407d
2 changed files with 16 additions and 1 deletions

View File

@ -0,0 +1,15 @@
# frozen_string_literal: true
class BackfillAccountDeletedAt < ActiveRecord::Migration[6.1]
def up
safety_assured do
execute 'UPDATE accounts SET deleted_at = suspended_at, suspended_at = NULL WHERE domain IS NULL AND suspended_at IS NOT NULL AND NOT EXISTS (SELECT 1 FROM users WHERE account_id = accounts.id)'
end
end
def down
safety_assured do
'UPDATE accounts SET suspended_at = deleted_at WHERE domain is NULL AND suspended_at IS NULL AND deleted_at IS NOT NULL'
end
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2024_03_27_145403) do
ActiveRecord::Schema[7.1].define(version: 2024_03_27_145507) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"