-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initialize Django with admin, superuser, and existing config data #1856
Comments
This PR #1855 now completes the last to do item for this issue. It's necessary for the test to run properly. |
@thekaveman Do you think this task should remove the data migration? |
Yes I think that makes sense! We might want to think about some kind of local setup e.g. fixtures that can be imported to get up and running locally. But for the production code, I think we won't need the data migrations. |
Blocked until #1881 is merged. |
This depends on #1847
The following set of tasks/criteria should be performed and checked after the secrets refactor. Once complete, the app will officially be "live" with the Admin interface.
Acceptance Criteria
bin/init.sh
runs:python manage.py migrate
,python manage.py compilemessages
, andpython manage.py collectstatic --no-input
bin/init.sh
no longer tries to delete/recreate the database file or a superuserbin/reset_db.sh
contains logic for creating the database and superuserDJANGO_ADMIN
,DJANGO_DB_RESET
,DJANGO_SUPERUSER_*
-- keepDJANGO_DB_DIR
ADMIN
variable and associatedif
statements insettings.py
go away -- we assume Django admin is enabled. Also update the test in https://github.com/cal-itp/benefits/blob/dev/tests/pytest/core/test_settings.pyBefore merge #1881
DJANGO_DB_DIR
fortest
to ensure database is saved in the file shareDJANGO_DB_DIR
forprod
to ensure database is saved in the file sharedev
database locallybin/reset_db.sh
fordev
locally withSUPERUSER
values from shared LastPass entryAfter merge #1881
dev
database to Azure, reset site, testdev
, see list belowtest
database locallybin/reset_db.sh
fortest
locally withSUPERUSER
values from shared LastPass entrydev
totest
Deploy to test #1909After merge #1909
test
database to Azure, reset site, testtest
, see list belowprod
database locallybin/reset_db.sh
forprod
locally withSUPERUSER
values from shared LastPass entrytest
toprod
After deploy
test
toprod
prod
database to Azure, reset site, testprod
, see list belowExport data
See the Django docs on the
dumpdata
management command.For exporting
dev
,test
, andprod
data, this has to be done on the existing corresponding branch (before merging #1881 up) because that PR changes the structure of the existing databases. This causes a mismatch when the below command is run and the database schema is checked against the (since updated in #1881) model schema.Temporarily rename the environment-specific database file, e.g.
dev_django.db
, todjango.db
, then follow the environment specific steps below.dev
:Since we've already merged the basic Admin changes to dev (i.e. #1855, #1874) the below command excludes some data types from export that will be recreated automatically when the
dev
database is reinitialized with changes for #1881.python manage.py dumpdata \ --natural-foreign \ --natural-primary \ --exclude auth \ --exclude contenttypes > dev_fixtures.json
test
andprod
:Since these two environments do not have any Admin changes merged to them yet, the process will be slightly different. First the export command does not need to exclude any data types (since they don't exist anyway):
python manage.py dumpdata \ --natural-foreign \ --natural-primary > [env]_fixtures.json
And the resulting fixtures need to be hand-edited to account for the move to secret-backed fields in #1874:
PemData
core.pemdata.fields.text
entries (i.e. the certs/keys)text_secret_name
AuthProvider
core.authprovider.client_id
entries (i.e. the actual client IDs)client_id_secret_name
EligibilityVerifier
core.eligibilityverifier.api_auth_key
entries (i.e. the actual API auth keys)api_auth_key_secret_name
(The last step only applies to the 2 Eligibility API verifiers: Courtesy Cards and Mobility Pass).
Reinitialize database with fixtures
Once the fixtures are generated for each environment, the following steps should be performed to reinitialize a local database from the environment configuration:
.env
withSUPERUSER
values from the corresponding environment (from LastPass).env
to point to the corresponding environment fixtures filebin/reset_db.sh
to generate a newdjango.db
from the environment fixturesdjango.db
to reflect which environment it corresponds withdjango.db
Unused secrets
These secrets can be removed from Key Vault in all environments:
dev
,test
,prod
-- they are no longer used after the Admin is live in all environments:sorted in alpha order to match Key Vault
Additional context
Discussion around #1851 led us to decide that it was simpler to just move forward with enabling the Admin for good, vs. trying to make the code work for both the current situation (resetting the db, maybe/maybe not enabling Admin) and the new situation (Admin is always enabled, db is never reset, etc.)
The text was updated successfully, but these errors were encountered: