Skip to content

Instantly share code, notes, and snippets.

@wconrad
Created November 15, 2016 17:24
Show Gist options
  • Save wconrad/449ef69e4cfbcf6196294d7678a1cd8c to your computer and use it in GitHub Desktop.
Save wconrad/449ef69e4cfbcf6196294d7678a1cd8c to your computer and use it in GitHub Desktop.
Some opaque logic
# Avoid linking an active user to franchises for which the user
# is inactive.
#
# * If the source user is inactive in all franchises, the user
# should be linked to all of the franchises in which it was
# present.
#
# * If the source user is active in all franchises, the
# destination user should be linked to all of the franchises
# in which it was present.
#
# * If the source user was active in some franchises and
# inactive in others, the destination user should only be
# linked to the franchises in which the source user was
# active.
#
# This is complicated by the fact that we do not migrate all of
# a source user's franchises at once, but instead we migrate
# them one after the other. The only think we know about is the
# current destination user, and the new source user.
def migrate_existing_user
load_existing_user
case [existing_user_active?, new_user_active?]
when [false, false]
link_user_to_franchise
when [false, true]
delete_existing_franchise_links
link_user_to_franchise
when [true, false]
when [true, true]
link_user_to_franchise
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment