Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore projects when undestroying user #25125

Merged
merged 2 commits into from
Oct 1, 2018
Merged

Conversation

islemaster
Copy link
Contributor

I've soft-deleted and restored my prod account a few times while working on the new sign-up flow. This morning I made a 馃槺 terrifying discovery: All of my projects were gone!

It turns out we soft-delete (and unfeature) a user's projects when the user is soft-deleted, but we don't restore those projects when the user is restored. 馃槩 Fortunately it was pretty easy to write a test for this scenario and fix it.

PEGASUS_DB[:storage_apps].
where(id: channel_ids, state: 'deleted').
where(Sequel.lit('updated_at >= ?', deleted_at.localtime)).
update(state: 'active', updated_at: Time.now)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most confusing thing here: We're getting a UTC Time when we grab the User's deleted_at (dashboard_db), but the updated_at storage_apps column (pegasus_db) contains a local (server?) time. Both times clearly reported information about their timezone offsets, but I guess comparing them in a Sequel literal isn't clever enough to take the timezone into account. Using .localtime to convert the User's delete time to server time before generating the Sequel literal seems to work.

# Paranoia documentation at https://github.com/rubysherpas/paranoia#usage.
restore(recursive: true, recovery_window: 5.minutes)
result = restore(recursive: true, recovery_window: 5.minutes)
restore_channels_deleted_after(soft_delete_time - 5.minutes)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Projects are soft-deleted before the User is soft-deleted, so I'm restoring them after the User is restored and keeping the 5-minute window.

Copy link
Contributor

@Erin007 Erin007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa! Good find and fix.

@islemaster islemaster merged commit d5f6b36 into staging Oct 1, 2018
@islemaster islemaster deleted the restore-projects branch October 1, 2018 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants