diff --git a/docs/operations/data_migration.md b/docs/operations/data_migration.md index 6e8a58b73..3e22a64f6 100644 --- a/docs/operations/data_migration.md +++ b/docs/operations/data_migration.md @@ -84,6 +84,10 @@ FILE 1: **escrow_domain_contacts.daily.gov.GOV.txt** -> has the map of domain na FILE 2: **escrow_contacts.daily.gov.GOV.txt** -> has the mapping of contact id to contact email address (which is what we care about for sending domain invitations) FILE 3: **escrow_domain_statuses.daily.gov.GOV.txt** -> has the map of domains and their statuses +We need to run a few scripts to parse these files into our domain tables. +We can do this both locally and in a sandbox. + +## OPTION 1: SANDBOX ## Load migration data onto a production or sandbox environment **WARNING:** All files uploaded in this manner are temporary, i.e. they will be deleted when the app is restaged. Do not use this method to store data you want to keep around permanently. @@ -169,6 +173,7 @@ Run the following script to transfer the existing data on our .txt files to our ./manage.py load_transition_domain migrationdata/escrow_domain_contacts.daily.gov.GOV.txt migrationdata/escrow_contacts.daily.gov.GOV.txt migrationdata/escrow_domain_statuses.daily.gov.GOV.txt ``` +## OPTION 2: LOCAL ## Load migration data onto our local environments Transferring this data from these files into our domain tables happens in two steps; diff --git a/src/registrar/management/commands/test_domain_migration.py b/src/registrar/management/commands/test_domain_migration.py index bc9efa9df..12f4bd745 100644 --- a/src/registrar/management/commands/test_domain_migration.py +++ b/src/registrar/management/commands/test_domain_migration.py @@ -12,7 +12,8 @@ from django.contrib.auth import get_user_model from registrar.models import TransitionDomain from registrar.models import Domain from registrar.models import DomainInvitation -from registrar.models.domain_information import DomainInformation +from registrar.models import DomainInformation +from registrar.models import User from registrar.management.commands.utility.terminal_helper import TerminalColors from registrar.management.commands.utility.terminal_helper import TerminalHelper @@ -337,19 +338,33 @@ class Command(BaseCommand): ================== {TerminalColors.ENDC} """) - for invite in DomainInvitation.objects.all(): - #DEBUG: - TerminalHelper.print_debug(debug_on,f"""{TerminalColors.OKCYAN}Processing invite: {invite}{TerminalColors.ENDC}""") - # get a user with this email address - User = get_user_model() - try: - user = User.objects.get(email=invite.email) - #DEBUG: - TerminalHelper.print_debug(debug_on,f"""{TerminalColors.OKCYAN}Logging in user: {user}{TerminalColors.ENDC}""") - Client.force_login(user) - except User.DoesNotExist: - #TODO: how should we handle this? - logger.warn(f"""{TerminalColors.FAIL}No user found {invite.email}{TerminalColors.ENDC}""") + # for invite in DomainInvitation.objects.all(): + # #DEBUG: + # TerminalHelper.print_conditional(debug_on,f"""{TerminalColors.OKCYAN}Processing invite: {invite}{TerminalColors.ENDC}""") + # # get a user with this email address + # user_exists = User.objects.filter(email=invite.email).exists() + # user, _ = User.objects.get_or_create(email=invite.email) + # #DEBUG: + # TerminalHelper.print_conditional(user_exists,f"""{TerminalColors.OKCYAN}No user found (creating temporary user object){TerminalColors.ENDC}""") + # TerminalHelper.print_conditional(debug_on,f"""{TerminalColors.OKCYAN}Logging in user: {user}{TerminalColors.ENDC}""") + # user.first_login() + # if not user_exists: + # logger.warn(f"""{TerminalColors.YELLOW}(Deleting temporary user object){TerminalColors.ENDC}""") + # user.delete() + + # for invite in DomainInvitation.objects.all(): + # #DEBUG: + # TerminalHelper.print_debug(debug_on,f"""{TerminalColors.OKCYAN}Processing invite: {invite}{TerminalColors.ENDC}""") + # # get a user with this email address + # User = get_user_model() + # try: + # user = User.objects.get(email=invite.email) + # #DEBUG: + # TerminalHelper.print_debug(debug_on,f"""{TerminalColors.OKCYAN}Logging in user: {user}{TerminalColors.ENDC}""") + # Client.force_login(user) + # except User.DoesNotExist: + # #TODO: how should we handle this? + # logger.warn(f"""{TerminalColors.FAIL}No user found {invite.email}{TerminalColors.ENDC}""") def handle( self, diff --git a/src/registrar/management/commands/utility/terminal_helper.py b/src/registrar/management/commands/utility/terminal_helper.py index ec7580e21..abfcdcae0 100644 --- a/src/registrar/management/commands/utility/terminal_helper.py +++ b/src/registrar/management/commands/utility/terminal_helper.py @@ -49,7 +49,7 @@ class TerminalHelper: else: logger.info("Please respond with 'yes' or 'no' " "(or 'y' or 'n').\n") - def print_debug(print_condition: bool, print_statement: str): + def print_conditional(print_condition: bool, print_statement: str): """This function reduces complexity of debug statements in other functions. It uses the logger to write the given print_statement to the