Skip to content

Commit

Permalink
Add migration to backfill accounts.deleted_at
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire committed Nov 17, 2023
1 parent e059051 commit 82d21e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions db/post_migrate/20231122145507_backfill_account_deleted_at.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_11_22_145403) do
ActiveRecord::Schema[7.0].define(version: 2023_11_22_145507) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down

0 comments on commit 82d21e5

Please sign in to comment.