Skip to content

Commit 88004c7

Browse files
committed
refactor: remove env vars + code that allowed different data migrations
this change reflects our decision to use the data migration provided in the repo. configuration values can still vary by setting different values in the Key Vault. documentation has also been updated
1 parent ace85d4 commit 88004c7

File tree

7 files changed

+1
-71
lines changed

7 files changed

+1
-71
lines changed

appcontainer/Dockerfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ COPY manage.py manage.py
1111
COPY bin/ bin/
1212
COPY benefits/ benefits/
1313

14-
# ensure $USER can compile messages in the locale directories and copy migration files from $DJANGO_MIGRATIONS_DIR
14+
# ensure $USER can compile messages in the locale directories
1515
USER root
1616
RUN chmod -R 777 benefits/locale
17-
RUN chmod -R 777 benefits/core/migrations
1817
USER $USER
1918

2019
# configure container executable

benefits/core/migrations/0002_sample_data.py

-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
"""Data migration which loads sample data.
2-
Set environment variable DJANGO_LOAD_SAMPLE_DATA to False to skip loading sample data.
32
"""
43
import json
54
import os
65

7-
from django.conf import settings
86
from django.db import migrations
97
from django.utils.translation import gettext_lazy as _
108

119

1210
def load_sample_data(app, *args, **kwargs):
13-
if not settings.LOAD_SAMPLE_DATA:
14-
print(" LOAD_SAMPLE_DATA is set to False, skipping sample data")
15-
return
16-
1711
EligibilityType = app.get_model("core", "EligibilityType")
1812

1913
mst_senior_type = EligibilityType.objects.create(

benefits/settings.py

-2
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ def _filter_empty(ls):
151151
}
152152
}
153153

154-
LOAD_SAMPLE_DATA = os.environ.get("DJANGO_LOAD_SAMPLE_DATA", "true").lower() != "false"
155-
156154
# Password validation
157155

158156
AUTH_PASSWORD_VALIDATORS = []

bin/init.sh

-9
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ rm -f django.db
88

99
# run database migrations
1010

11-
if [[ ${DJANGO_LOAD_SAMPLE_DATA:-true} = false ]]; then
12-
if [[ -d ${DJANGO_MIGRATIONS_DIR:-false} ]]; then
13-
echo "Copying migrations from ${DJANGO_MIGRATIONS_DIR}"
14-
cp ${DJANGO_MIGRATIONS_DIR}/0002_*.py ./benefits/core/migrations/
15-
else
16-
echo "DJANGO_MIGRATIONS_DIR is either unset or not a directory"
17-
fi
18-
fi
19-
2011
python manage.py migrate
2112

2213
# create a superuser account for backend admin access

docs/configuration/data.md

-29
Original file line numberDiff line numberDiff line change
@@ -68,35 +68,6 @@ Run these commands from within the repository root, inside the devcontainer:
6868
bin/init.sh
6969
```
7070

71-
## Loading new data for different environment
72-
73-
Django will run all migration files found in an app's `migrations` module.
74-
75-
To load new data for a different environment:
76-
77-
1. (Optional) Set an environment variable `DJANGO_LOAD_SAMPLE_DATA` to `false` if you don't want the `core` app's sample data to be loaded.
78-
1. Create a data migration file, and make sure the name is prefixed with `0002`. (The migration process for Benefits expects data migration files to named as such). The basic structure for the contents of this file is:
79-
```python
80-
from django.db import migrations
81-
82-
83-
def load_data(app, *args, **kwargs):
84-
pass
85-
86-
87-
class Migration(migrations.Migration):
88-
dependencies = [
89-
("core", "0001_initial"),
90-
]
91-
92-
operations = [
93-
migrations.RunPython(load_data),
94-
]
95-
```
96-
1. Put this file under `benefits/core/migrations`
97-
1. If `DJANGO_LOAD_SAMPLE_DATA` is `false`, you can also set [`DJANGO_MIGRATIONS_DIR`](../environment-variables/#django_migrations_dir) to a directory path, and put your data migration there.
98-
99-
10071
[core-models]: https://github.com/cal-itp/benefits/blob/dev/benefits/core/models.py
10172
[django-load-initial-data]: https://docs.djangoproject.com/en/4.0/howto/initial-data/
10273
[eligibility-server]: https://docs.calitp.org/eligibility-server

docs/configuration/environment-variables.md

-21
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,6 @@ Boolean:
7373
files are served
7474
- `False` (default): the application is launched with debug mode turned off, similar to how it runs in production
7575

76-
### `DJANGO_LOAD_SAMPLE_DATA`
77-
78-
!!! warning "Deployment configuration"
79-
80-
You may change this setting when deploying the app to a non-localhost domain
81-
82-
Boolean:
83-
84-
- `True` (default): The sample data in `benefits/core/migrations/0002_sample_data.py` is used to initialize the Django configuration database.
85-
- `False`: The sample data from `benefits/core/migrations/0002_sample_data.py` will not be loaded.
86-
87-
See [Configuration data](data.md) for more.
88-
8976
### `DJANGO_LOCAL_PORT`
9077

9178
!!! info "Local configuration"
@@ -113,14 +100,6 @@ The log level used in the application's logging configuration.
113100

114101
By default the application sends logs to `stdout`.
115102

116-
### `DJANGO_MIGRATIONS_DIR`
117-
118-
!!! warning "Deployment configuration"
119-
120-
You may change this setting when deploying the app to a non-localhost domain
121-
122-
If [`DJANGO_LOAD_SAMPLE_DATA`](#django_load_sample_data) is `false`, then you can set `DJANGO_MIGRATIONS_DIR` to the path of a directory containing data migrations that you want to be run. Those data migration files need to be prefixed with `0002` so that the [helper migration file](data.md)) can find it. See [Configuration data](./data.md) for more on loading data for different environments.
123-
124103
### `DJANGO_SECRET_KEY`
125104

126105
!!! warning "Deployment configuration"

terraform/app_service.tf

-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ resource "azurerm_linux_web_app" "main" {
7070
"DJANGO_ADMIN" = (local.is_prod || local.is_test) ? null : "${local.secret_prefix}django-admin)",
7171
"DJANGO_ALLOWED_HOSTS" = "${local.secret_prefix}django-allowed-hosts)",
7272
"DJANGO_DEBUG" = local.is_prod ? null : "${local.secret_prefix}django-debug)",
73-
"DJANGO_LOAD_SAMPLE_DATA" = "false",
7473
"DJANGO_LOG_LEVEL" = "${local.secret_prefix}django-log-level)",
75-
"DJANGO_MIGRATIONS_DIR" = "./config",
7674

7775
"DJANGO_RATE_LIMIT" = local.is_dev ? null : "${local.secret_prefix}django-rate-limit)",
7876
"DJANGO_RATE_LIMIT_METHODS" = local.is_dev ? null : "${local.secret_prefix}django-rate-limit-methods)",

0 commit comments

Comments
 (0)