generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migration to allow users to be anonymised
This is the first step in a larger piece of work. We will use DateTime to store when a user is deactivated, this will replace the `active` attribute: - when the deactivated_at is nil the user is active - when the deactivated_at has a date time the user has been deactivated We have no way to know when a user was deactivated (hence the work!) so we'll use the updated_at to be our best guess. At this point the application is broken, but we'll keep this commit separate and fix that next.
- Loading branch information
Showing
2 changed files
with
26 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class AddUserAnonymisation < ActiveRecord::Migration[6.1] | ||
def up | ||
add_column :users, :deactivated_at, :datetime | ||
add_column :users, :anonymised_at, :datetime | ||
|
||
User.where(active: false).each do |user| | ||
user.update_column(:deactivated_at, user.updated_at) | ||
end | ||
|
||
remove_column :users, :active | ||
end | ||
|
||
def down | ||
add_column :users, :active, :boolean, default: true | ||
|
||
User.where(deactivated_at: nil).each do |user| | ||
user.update_column(:active, true) | ||
end | ||
|
||
remove_column :users, :deactivated_at, :datetime | ||
remove_column :users, :anonymised_at, :datetime | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters