updated documentation and added public contact

This commit is contained in:
David Kennedy 2024-06-01 08:22:52 -04:00
parent 1e540335d6
commit 7c50b5fc2a
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
3 changed files with 51 additions and 14 deletions

View file

@ -1,18 +1,19 @@
# Export / Import Tables # Export / Import Tables
A means is provided to export and import individual tables from A means is provided to export and import tables from
one environment to another. This allows for replication of one environment to another. This allows for replication of
production data in a development environment. Import and export production data in a development environment. Import and export
are provided through the django admin interface, through a modified are provided through a modified library, django-import-export.
library, django-import-export. Each supported model has an Import Simple scripts are provided as detailed below.
and an Export button on the list view.
### Export ### Export
When exporting models from the source environment, make sure that To export from the source environment, run the following command from src directory:
no filters are selected. This will ensure that all rows of the model manage.py export_tables
are exported. Due to database dependencies, the following models
need to be exported: This exports a file, exported_tables.zip, to the tmp directory
For reference, the zip file will contain the following tables in csv form:
* User * User
* Contact * Contact
@ -25,6 +26,17 @@ need to be exported:
* Host * Host
* HostIP * HostIP
After exporting the file from the target environment, scp the exported_tables.zip
file from the target environment to local.
Get passcode by running:
cf ssh-code
scp file from app (app is getgov-stable in example below) to local cwd:
scp -P 2222 -o User=cf:$(cf curl /v3/apps/$(cf app getgov-stable --guid)/processes | jq -r '.resources[] | select(.type=="web") | .guid')/0 ssh.fr.cloud.gov:app/tmp/exported_tables.zip .
when prompted, supply the passcode retrieved in the 'cf ssh-code' command
### Import ### Import
When importing into the target environment, if the target environment When importing into the target environment, if the target environment
@ -34,7 +46,11 @@ that there are no database conflicts on import.
#### Preparing Target Environment #### Preparing Target Environment
Delete all rows from tables in the following order through django admin: In order to delete all rows from the appropriate tables, run the following
command:
manage.py clean_tables
For reference, this deletes all rows from the following tables:
* DomainInformation * DomainInformation
* DomainRequest * DomainRequest
@ -48,10 +64,23 @@ Delete all rows from tables in the following order through django admin:
#### Importing into Target Environment #### Importing into Target Environment
Once target environment is prepared, files can be imported in the following Once target environment is prepared, files can be imported.
order:
* User (After importing User table, you need to delete all rows from Contact table before importing Contacts) To scp the exported_tables.zip file from local to the sandbox, run the following:
Get passcode by running:
cf ssh-code
scp file from app (app is getgov-stable in example below) to local cwd:
scp -P 2222 -o User=cf:$(cf curl /v3/apps/$(cf app getgov-stable --guid)/processes | jq -r '.resources[] | select(.type=="web") | .guid')/0 tmp/exported_tables.zip ssh.fr.cloud.gov:app/tmp/exported_tables.zip
when prompted, supply the passcode retrieved in the 'cf ssh-code' command
Then connect to a shell in the target environment, and run the following import command:
manage.py import_tables
For reference, this imports tables in the following order:
* User
* Contact * Contact
* Domain * Domain
* Host * Host

View file

@ -2244,10 +2244,18 @@ class DraftDomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
# If no redirection is needed, return the original response # If no redirection is needed, return the original response
return response return response
class PublicContactResource(resources.ModelResource):
"""defines how each field in the referenced model should be mapped to the corresponding fields in the
import/export file"""
class PublicContactAdmin(ListHeaderAdmin): class Meta:
model = models.PublicContact
class PublicContactAdmin(ListHeaderAdmin, ImportExportModelAdmin):
"""Custom PublicContact admin class.""" """Custom PublicContact admin class."""
resource_classes = [PublicContactResource]
change_form_template = "django/admin/email_clipboard_change_form.html" change_form_template = "django/admin/email_clipboard_change_form.html"
autocomplete_fields = ["domain"] autocomplete_fields = ["domain"]

View file

@ -15,7 +15,7 @@ class Command(BaseCommand):
"""Generates CSV files for specified tables and creates a zip archive""" """Generates CSV files for specified tables and creates a zip archive"""
table_names = [ table_names = [
"User", "Contact", "Domain", "DomainRequest", "DomainInformation", "User", "Contact", "Domain", "DomainRequest", "DomainInformation",
"UserDomainRole", "DraftDomain", "Website", "HostIp", "Host" "UserDomainRole", "DraftDomain", "Website", "HostIp", "Host", "PublicContact"
] ]
# Ensure the tmp directory exists # Ensure the tmp directory exists