**Service environment variables**

DEBUG - show debug information like DB requests, default - empty (off)
DB_NAME - database name
DB_USER - DB username
DB_PASS - DB password
DB_HOST - DB host
DB_PORT - DB port
AUTH0_DOMAIN - auth0 domain
AUTH0_CLIENT_ID - auth0 react app client ID
AUTH0_API_AUDIENCE - auth0 API name
AUTH0_MANAGEMENT_CLIENT_ID - auth0 M2M for management API client id
AUTH0_MANAGEMENT_CLIENT_SECRET - auth 0 M2M for management API secret key
CONSUMER_ANALYTICS_API - API host
RDS_DB_NAME - dev DB name for dump migration
RDS_DB_USER - dev DB user name
RDS_DB_HOST - dev DB host
RDS_DB_PORT - dev DB port
DELPHI_API_CLIENT_ID - Client ID for Delphi API
DELPHI_API_CLIENT_SECRET - Client Secret for Delphi API
REDIS_HOST - hostname for Redis instance
ELASTIC_HOST - hostname for ElasticSearch instance
SNOWFLAKE_USER - username for Snowflake DB
SNOWFLAKE_PASS - password for Snowflake DB
SNOWFLAKE_ACCOUNT - account name for Snowflake DB
SNOWFLAKE_DB - default database name for Snowflake DB
SNOWFLAKE_SCHEMA - default schema for Snowflake DB
SNOWFLAKE_WAREHOUSE - default warehouse for Snowflake DB
DELPHI_API_DOMAIN - domain for Delphi API
APOLLO_API_DOMAIN - domain for Apollo API


**Requirements**
1. Installed Docker
2. Configured AWS credentials (DevOps team)
    1. Login to https://gdb-infra-dev.signin.aws.amazon.com/console
    2. You will be forced to change the password after the login. Password requirements are:
        - 14 symbols minimum
        - Minimum one of each character types - uppercase, lowercase, digit, special character
3. Set up MFA with Google Authenticator for AWS
    1. Download the Google Authenticator app from the Google Play Market or the App Store.
    2. Login into AWS account using your credentials.
    3. In the header click on %username% @ gdb-infra-dev and from the drop-down, select My Security Credentials item.
    4. Assign the MFA device.
    5. Choose Virtual MFA device.
    6. Scan QR code and assign MFA
    7. Finish MFA configuration, log out and log in to apply changes.
4. Install aws-cli onto you machine. Configure it with command `aws configure --profile gdb-infra-dev`
    - `access key id`: can be found in aws -> Security Credentials -> Create Access Key
    - `aws_secret_access_key`: can be found in aws -> Security Credentials -> Create Access Key
    - `region`: us-east-1
5. Configured Delphi VPN and running when you`re working with the project

**Commands**
***1. `make docker/up-local` - to run application locally (The database is empty by default)***
***2. `sh restore_db.sh` - to restore database from the dump***
***3. `sh apply_migrations.sh` - to apply DB migrations***

6. `sh pre-commit.sh` - run code prettifier & linter
7. `sh run_tests.sh` - run all tests
8. `docker exec -it api /bin/sh -c "python manage.py reindex_elastic"` - reindex ElasticSearch. Need to be executed after each application run (if needed). Add flag -m with model name to reindex if need only partial indexation.
9. `sh create_automigration.sh` - creates a new migration with schema changes if needed. Creates empty if schema is the same.
10. `sh revert_migrations.sh` - to revert last DB migration
11. `sh assume_as_default.sh <ACCOUNT_NAME> <OTP-TOKEN>` - sets AWS two-factor auth token in environment. Please note - token will expire in 6-7 hours.

Commands 1-3 are required to run in a sequence when starting application from scratch.

If you are a windows user, please run all file commands one by one in root folder in the PowerShell

Run `sh codestyle.sh` - run linter (PEP codestyle checker)

**Dependency manager**

In the project, we use Poetry as our dependency manager.
Poetry is a powerful tool for managing Python packages and their dependencies.
To download and install Poetry locally, you can use pip by running `pip install poetry` in your command line.
Once Poetry is installed, navigate to project directory and run `poetry install` to install all the necessary
dependencies specified in the `pyproject.toml` file.
For more details on using Poetry, refer to the official documentation at https://python-poetry.org/docs/.


**Environments**

[Development](https://dev.decibel.stream/) - deploys upon merging into `develop` branch
[QA](https://qa.decibel.stream/) - deploy can be performed in Octopus.
[Staging](https://stage.decibel.stream/) - deploys upon merging into `master` branch
[Production](https://decibel.stream/) - deploy can be performed in Octopus.
UAT - deploys upon merging into `uat` branch. **Currently extremely outdated**

All pending migrations are applying automatically when deploying to the env.

**Dynamic Environments**

[test1](https://test1.decibel.stream)
[test2](https://test2.decibel.stream)
[test3](https://test3.decibel.stream)
[test4](https://test4.decibel.stream)
[test5](https://test5.decibel.stream)

**API documentation**

To enable API documentation, you need to set DOCUMENTATION = True

To access the API documentation, you need to visit BE API root url + /doc/

For example dev env: https://dev-api.decibel.stream/doc/

**Finite state machine**

Use the transition decorator to annotate model methods.
Transition can be also used on a class object to create a group of handlers for same target state.
```
@transition(target='Draft')
class DraftTransition:

    @transition(source='Pending Approval')
    def pending_approval_transition_handler(self, instance):
        pass
```
in model class
```
draft_transition_handler = DraftTransition
```
The transition is still to be invoked by calling the model's  method
```
draft_transition_handler.set()
```
