Skip to content

Commit 88f4684

Browse files
authored
Merge pull request #929 from NASA-IMPACT/928-update-cosmos-to-handle-dev-and-test-ej-data
add DestinationServer Choices to EnvironmentalJusticeRow
2 parents d8a199a + 064e489 commit 88f4684

File tree

6 files changed

+88
-25
lines changed

6 files changed

+88
-25
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,26 @@ To load collections:
7878
$ docker-compose -f local.yml run --rm django python manage.py loaddata sde_collections/fixtures/collections.json
7979
```
8080

81-
### Loading the Database from a Backup
81+
### Manually Creating and Loading a ContentTypeless Backup
82+
Navigate to the server running prod, then to the project folder. Run the following command to create a backup:
83+
84+
```bash
85+
docker-compose -f production.yml run --rm --user root django python manage.py dumpdata --natural-foreign --natural-primary --exclude=contenttypes --exclude=auth.Permission --indent 2 --output /app/backups/prod_backup-20240812.json
86+
```
87+
This will have saved the backup in a folder outside of the docker container. Now you can copy it to your local machine.
88+
89+
```bash
90+
mv ~/prod_backup-20240812.json <project_path>/prod_backup-20240812.json
91+
scp sde:/home/ec2-user/sde_indexing_helper/backups/prod_backup-20240812.json prod_backup-20240812.json
92+
```
93+
94+
Finally, load the backup into your local database:
95+
96+
```bash
97+
docker-compose -f local.yml run --rm django python manage.py loaddata prod_backup-20240812.json
98+
```
99+
100+
### Loading the Database from an Arbitrary Backup
82101

83102
1. Build the project and run the necessary containers (as documented above).
84103
2. Clear out content types using the Django shell:

config/settings/base.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,21 @@
7474
"crispy_bootstrap5",
7575
"crispy_forms",
7676
"django_celery_beat",
77+
"django_filters",
7778
"rest_framework_datatables",
7879
"rest_framework",
7980
]
8081

82+
LOCAL_APPS = [
83+
"environmental_justice",
84+
"feedback",
85+
"sde_collections",
86+
"sde_indexing_helper.users",
87+
]
88+
89+
# https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
90+
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
91+
8192
CORS_ALLOWED_ORIGINS = [
8293
"http://localhost:3000",
8394
"http://sde-lrm.nasa-impact.net",
@@ -91,15 +102,6 @@
91102
"http://localhost:4200",
92103
]
93104

94-
LOCAL_APPS = [
95-
"environmental_justice",
96-
"sde_indexing_helper.users",
97-
"sde_collections",
98-
"feedback",
99-
]
100-
# https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
101-
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
102-
103105
# MIGRATIONS
104106
# ------------------------------------------------------------------------------
105107
# https://docs.djangoproject.com/en/dev/ref/settings/#migration-modules
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from django.db import migrations, models
2+
3+
4+
def set_default_destination_server(apps, schema_editor):
5+
EnvironmentalJusticeRow = apps.get_model("environmental_justice", "EnvironmentalJusticeRow")
6+
EnvironmentalJusticeRow.objects.filter(destination_server="").update(destination_server="prod")
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
("environmental_justice", "0004_alter_environmentaljusticerow_data_visualization_and_more"),
13+
]
14+
15+
operations = [
16+
migrations.AddField(
17+
model_name="environmentaljusticerow",
18+
name="destination_server",
19+
field=models.CharField(
20+
blank=True,
21+
choices=[("dev", "Development"), ("test", "Testing"), ("prod", "Production")],
22+
default="",
23+
max_length=10,
24+
verbose_name="Destination Server",
25+
),
26+
),
27+
migrations.RunPython(set_default_destination_server),
28+
]

environmental_justice/models.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@ class EnvironmentalJusticeRow(models.Model):
66
Environmental Justice data from the spreadsheet
77
"""
88

9+
class DestinationServerChoices(models.TextChoices):
10+
DEV = "dev", "Development"
11+
TEST = "test", "Testing"
12+
PROD = "prod", "Production"
13+
14+
destination_server = models.CharField(
15+
"Destination Server", max_length=10, choices=DestinationServerChoices.choices, default="", blank=True
16+
)
17+
918
dataset = models.CharField("Dataset", blank=True, default="")
1019
description = models.CharField("Description", blank=True, default="")
11-
description_simplified = models.CharField(
12-
"Description Simplified", blank=True, default=""
13-
)
20+
description_simplified = models.CharField("Description Simplified", blank=True, default="")
1421
indicators = models.CharField("Indicators", blank=True, default="")
1522
intended_use = models.CharField("Intended Use", blank=True, default="")
1623
latency = models.CharField("Latency", blank=True, default="")
@@ -21,15 +28,11 @@ class EnvironmentalJusticeRow(models.Model):
2128

2229
# fields that needs cleaning
2330
format = models.CharField("Format", blank=True, default="")
24-
geographic_coverage = models.CharField(
25-
"Geographic Coverage", blank=True, default=""
26-
)
31+
geographic_coverage = models.CharField("Geographic Coverage", blank=True, default="")
2732
data_visualization = models.CharField("Data Visualization", blank=True, default="")
2833
spatial_resolution = models.CharField("Spatial Resolution", blank=True, default="")
2934
temporal_extent = models.CharField("Temporal Extent", blank=True, default="")
30-
temporal_resolution = models.CharField(
31-
"Temporal Resolution", blank=True, default=""
32-
)
35+
temporal_resolution = models.CharField("Temporal Resolution", blank=True, default="")
3336

3437
sde_link = models.CharField("SDE Link", default="", blank=True)
3538

environmental_justice/views.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from rest_framework import viewsets
2+
from django_filters.rest_framework import DjangoFilterBackend
23

34
from .models import EnvironmentalJusticeRow
45
from .serializers import EnvironmentalJusticeRowSerializer
@@ -11,6 +12,15 @@ class EnvironmentalJusticeRowViewSet(viewsets.ModelViewSet):
1112

1213
queryset = EnvironmentalJusticeRow.objects.all()
1314
serializer_class = EnvironmentalJusticeRowSerializer
14-
http_method_names = [
15-
"get",
16-
]
15+
http_method_names = ["get"]
16+
filter_backends = [DjangoFilterBackend]
17+
filterset_fields = ["destination_server"]
18+
19+
def get_queryset(self):
20+
"""
21+
if no destination_server is provided, default to PROD
22+
"""
23+
queryset = super().get_queryset()
24+
if not self.request.query_params.get("destination_server"):
25+
queryset = queryset.filter(destination_server=EnvironmentalJusticeRow.DestinationServerChoices.PROD)
26+
return queryset

requirements/base.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ crispy-bootstrap5==2023.10 # https://github.com/django-crispy-forms/crispy-boot
2121
# project-specific
2222
beautifulsoup4==4.12.3
2323
boto3==1.34.31
24+
django-cors-headers==4.3.1
25+
django-filter==24.3
2426
djangorestframework-datatables==0.7.0
2527
djangorestframework==3.14.0
28+
lxml==4.9.2
2629
PyGithub==2.2.0
2730
tqdm==4.66.3
28-
xmltodict==0.13.0
29-
django-cors-headers==4.3.1
3031
unidecode==1.3.8
31-
lxml==4.9.2
32+
xmltodict==0.13.0

0 commit comments

Comments
 (0)