Add more documentation

This commit is contained in:
zandercymatics 2024-06-24 09:12:59 -06:00
parent d25d8f5d1f
commit 26ddf317d5
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 33 additions and 4 deletions

View file

@ -697,3 +697,30 @@ Example: `cf ssh getgov-za`
| | Parameter | Description |
|:-:|:-------------------------- |:----------------------------------------------------------------------------|
| 1 | **debug** | Increases logging detail. Defaults to False. |
## Transfer federal agency script
The transfer federal agency script adds the "federal_type" field on each associated DomainRequest, and uses that to populate the "federal_type" field on each FederalAgency.
**Important:** When running this script, note that data generated by our fixtures will be inaccurate (since we assign random data to them). Use real data on this script.
Do note that there is a check on record uniqueness. If two or more records do NOT have the same value for federal_type for any given federal agency, then the record is skipped. This protects against fixtures data when loaded with real data.
### Running on sandboxes
#### Step 1: Login to CloudFoundry
```cf login -a api.fr.cloud.gov --sso```
#### Step 2: SSH into your environment
```cf ssh getgov-{space}```
Example: `cf ssh getgov-za`
#### Step 3: Create a shell instance
```/tmp/lifecycle/shell```
#### Step 4: Running the script
```./manage.py transfer_federal_agency_type```
### Running locally
#### Step 1: Running the script
```docker-compose exec app ./manage.py transfer_federal_agency_type```

View file

@ -18,7 +18,7 @@ class Command(BaseCommand, PopulateScriptTemplate):
def handle(self, **kwargs):
"""Loops through each valid User object and updates its verification_type value"""
# Get all existing domain requests
# Get all existing domain requests. Select_related allows us to skip doing db queries.
self.all_domain_requests = DomainRequest.objects.select_related("federal_agency").distinct()
self.mass_update_records(
FederalAgency, filter_conditions={"agency__isnull": False}, fields_to_update=["federal_type"]
@ -28,9 +28,11 @@ class Command(BaseCommand, PopulateScriptTemplate):
"""Defines how we update the federal_type field on each record."""
request = self.all_domain_requests.filter(federal_agency__agency=record.agency).first()
record.federal_type = request.federal_type
def should_skip_record(self, record) -> bool: # noqa
"""Defines the conditions in which we should skip updating a record."""
request = self.all_domain_requests.filter(federal_agency__agency=record.agency).first()
return not request or not request.federal_agency
requests = self.all_domain_requests.filter(federal_agency__agency=record.agency, federal_type__isnull=False)
# Check if all federal_type values are the same. Skip the record otherwise.
distinct_federal_types = requests.values('federal_type').distinct()
return distinct_federal_types.count() != 1