From 0ce4a04b4bf78f957e3f96e882bf186409e52616 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 20 Nov 2023 10:14:10 -0700 Subject: [PATCH] Add documentation --- docs/operations/data_migration.md | 52 +++++++++++++++++++ .../commands/load_organization_data.py | 14 ++++- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/docs/operations/data_migration.md b/docs/operations/data_migration.md index 7290349ad..fe3d5f45e 100644 --- a/docs/operations/data_migration.md +++ b/docs/operations/data_migration.md @@ -421,3 +421,55 @@ purposes Used by the migration scripts to trigger a prompt for deleting all table entries. Useful for testing purposes, but *use with caution* + +## Import organization data +During MVP, our import scripts did not populate the following fields: `address_line, city, state_territory, and zipcode`. This was primarily due to time constraints. Because of this, we need to run a follow-on script to load this remaining data on each `DomainInformation` object. + +This script is intended to run under the assumption that the [load_transition_domain](#step-1-load-transition-domains) and the [transfer_transition_domains_to_domains](#step-2-transfer-transition-domain-data-into-main-domain-tables) scripts have already been ran. + +##### LOCAL COMMAND +to run this command locally, enter the following: +```shell +docker compose run -T app ./manage.py load_organization_data {filename_of_migration_json} --debug +``` +* filename_of_migration_filepath_json - This is a [JSON containing a list of filenames](#step-2-obtain-json-file-for-file-locations). This same file was used in the preceeding steps, `load_transition_domain` and `transfer_transition_domains_to_domains`, however, this script only needs two fields: +``` +{ + "domain_additional_filename": "example.domainadditionaldatalink.adhoc.dotgov.txt", + "organization_adhoc_filename": "example.organization.adhoc.dotgov.txt" +} +``` +If you already possess the old JSON, you do not need to modify it. This script can run even if you specify multiple filepaths. It will just skip over unused ones. + +**Example** +```shell +docker compose run -T app ./manage.py load_organization_data migrationFilepaths.json --debug +``` + +##### SANDBOX COMMAND +```shell +./manage.py load_organization_data {filename_of_migration_json} --debug +``` +* **filename_of_migration_filepath_json** - This is a [JSON containing a list of filenames](#step-2-obtain-json-file-for-file-locations). This same file was used in the preceeding steps, `load_transition_domain` and `transfer_transition_domains_to_domains`, however, this script only needs two fields: +``` +{ + "domain_additional_filename": "example.domainadditionaldatalink.adhoc.dotgov.txt", + "organization_adhoc_filename": "example.organization.adhoc.dotgov.txt" +} +``` +If you already possess the old JSON, you do not need to modify it. This script can run even if you specify multiple filepaths. It will just skip over unused ones. + +**Example** +```shell +./manage.py load_organization_data migrationFilepaths.json --debug +``` + +##### Optional parameters +The `load_organization_data` script has five optional parameters. These are as follows: +| | Parameter | Description | +|:-:|:---------------------------------|:----------------------------------------------------------------------------| +| 1 | **sep** | Determines the file separator. Defaults to "\|" | +| 2 | **debug** | Increases logging detail. Defaults to False | +| 3 | **directory** | Specifies the containing directory of the data. Defaults to "migrationdata" | +| 4 | **domain_additional_filename** | Specifies the filename of domain_additional. Used as an override for the JSON. Has no default. | +| 5 | **organization_adhoc_filename** | Specifies the filename of organization_adhoc. Used as an override for the JSON. Has no default. | diff --git a/src/registrar/management/commands/load_organization_data.py b/src/registrar/management/commands/load_organization_data.py index 9a15f646e..3cfba0ca8 100644 --- a/src/registrar/management/commands/load_organization_data.py +++ b/src/registrar/management/commands/load_organization_data.py @@ -35,11 +35,13 @@ class Command(BaseCommand): parser.add_argument("--directory", default="migrationdata", help="Desired directory") + # Serves as a domain_additional_filename override parser.add_argument( "--domain_additional_filename", help="Defines the filename for additional domain data", ) + # Serves as a organization_adhoc_filename override parser.add_argument( "--organization_adhoc_filename", help="Defines the filename for domain type adhocs", @@ -56,8 +58,18 @@ class Command(BaseCommand): # load JSON object as a dictionary try: data = json.load(jsonFile) + + skipped_fields = ["domain_additional_filename", "organization_adhoc_filename"] # Iterate over the data from the JSON file. Skip any unused values. - options.update({key: value for key, value in data.items() if value is not None and value.strip() != ""}) + for key, value in data.items(): + if value is not None or value.strip() != "": + continue + + # If any key in skipped_fields has a value, then + # we override what is specified in the JSON. + if key not in skipped_fields: + options[key] = value + except Exception as err: logger.error( f"{TerminalColors.FAIL}"