diff --git a/.github/workflows/loaddata.yaml b/.github/workflows/loaddata.yaml new file mode 100644 index 000000000..5d0e2c462 --- /dev/null +++ b/.github/workflows/loaddata.yaml @@ -0,0 +1,40 @@ +name: Reset database + +# This workflow can be run from the CLI +# gh workflow run loaddata.yaml -f environment=staging +# OR +# cf run-task getgov-staging --wait \ +# --command 'python manage.py flush' --name flush +# cf run-task getgov-staging --wait \ +# --command 'python manage.py loaddata registrar/fixtures/*' --name loaddata +on: + workflow_dispatch: + inputs: + environment: + type: choice + description: Where should we load data + options: + - staging + +jobs: + reset-db-staging: + if: ${{ github.event.inputs.environment == 'staging' }} + runs-on: ubuntu-latest + steps: + - name: Delete existing data for staging + uses: 18f/cg-deploy-action@main + with: + cf_username: ${{ secrets.CF_USERNAME }} + cf_password: ${{ secrets.CF_PASSWORD }} + cf_org: cisa-getgov-prototyping + cf_space: staging + full_command: "cf run-task getgov-staging --wait --command 'python manage.py flush' --name flush" + + - name: Load fake data for staging + uses: 18f/cg-deploy-action@main + with: + cf_username: ${{ secrets.CF_USERNAME }} + cf_password: ${{ secrets.CF_PASSWORD }} + cf_org: cisa-getgov-prototyping + cf_space: staging + full_command: "cf run-task getgov-staging --wait --command 'python manage.py loaddata registrar/fixtures/*' --name loaddata" diff --git a/.github/workflows/migrate.yaml b/.github/workflows/migrate.yaml index a58bd30d4..f53e7564b 100644 --- a/.github/workflows/migrate.yaml +++ b/.github/workflows/migrate.yaml @@ -1,4 +1,4 @@ -name: Run Migrations +name: Run migrations # This workflow can be run from the CLI # gh workflow run migrate.yaml -f environment=sandbox diff --git a/.github/workflows/security-check.yaml b/.github/workflows/security-check.yaml index 06c717e0a..fb9b46cf4 100644 --- a/.github/workflows/security-check.yaml +++ b/.github/workflows/security-check.yaml @@ -1,4 +1,4 @@ -name: Security Checks +name: Security checks on: push: diff --git a/docs/developer/database-access.md b/docs/developer/database-access.md index 8635543a1..913f58590 100644 --- a/docs/developer/database-access.md +++ b/docs/developer/database-access.md @@ -21,11 +21,27 @@ can manually run the task with cf run-task getgov-unstable --command 'python manage.py migrate' --name migrate ``` +Optionally, load data from fixtures as well + +```shell +cf run-task getgov-unstable --wait --command 'python manage.py loaddata registrar/fixtures/*' --name loaddata +``` + For the `staging` environment, developers don't have credentials so we need to run that command using Github Actions. Go to and select the "Run workflow" button, making sure that `staging` is selected. +## Getting data for fixtures + +To run the `dumpdata` command, you'll need to ssh to a running container. `cf run-task` is useless for this, as you will not be able to see the output. + +```shell +cf ssh getgov-unstable +/tmp/lifecycle/shell # this configures your environment +./manage.py dumpdata +``` + ## Dropping and re-creating the database For `unstable`, it might be necessary to start the database over from scratch. diff --git a/src/registrar/fixtures/users.json b/src/registrar/fixtures/users.json new file mode 100644 index 000000000..83394cb09 --- /dev/null +++ b/src/registrar/fixtures/users.json @@ -0,0 +1,40 @@ +[ + { + "model": "registrar.user", + "pk": 1, + "fields": { + "password": "", + "last_login": "2022-10-04T15:07:34.590Z", + "is_superuser": true, + "username": "c4a0e101-73b4-4d7d-9e5e-7f19a726a0fa", + "first_name": "Seamus", + "last_name": "Johnston", + "email": "", + "is_staff": true, + "is_active": true, + "date_joined": "2022-09-30T14:14:02.280Z", + "groups": [], + "user_permissions": [] + } + }, + { + "model": "registrar.userprofile", + "pk": 1, + "fields": { + "created_at": "2022-09-30T14:14:02.284Z", + "updated_at": "2022-10-04T15:07:34.593Z", + "street1": "", + "street2": "", + "street3": "", + "city": "", + "sp": "", + "pc": "", + "cc": "", + "voice": "", + "fax": "", + "email": "", + "user": 1, + "display_name": "" + } + } +]