-
Notifications
You must be signed in to change notification settings - Fork 9
Development Guide
The first time you pull from main after ethan/refreshtoken has been incorporated, rm flag.db and rm any files in migrations/versions before you pull from main. If you have already pulled from main do git status and remove any untracked files in migratons/versions.
- Install Postgres
- Install Python or Conda
- Install sqlite
- Clone this repository
- Checkout a new branch if you are making changes
-
If you have customized .env look to see if there are any changes to .env.example.sqlite
-
If you have not customized .env then copy .env.example to .env
cp .env.example.sqlite .env
-
If you have customized .env look to see if there are any changes to .env.example.postgres
-
If you have not customized .env then copy .env.example to .env
cp .env.example.postgres .env
-
If you have not initialized the postgres database or want to recreate db:
psql postgres_setup.sql
- REACT_APP_BACKEND_API=http://127.0.0.1:5000 or https://codefordc-flag.herokuapp.com/
From the Mac or git bash terminal:
chmod -R 777 *.sh
source run_setup.sh
To do the same without the scripts:
======================
source myenv/bin/activate
python3 -m venv myenv
OR
conda create --name myenv
conda activate myenv
=======================
pip install -r requirements.txt
DEBUG=True FLASK_APP=app.py flask db upgrade
python3 populate_seed_data.py
rm flag.db ## required if any schema changes
FLASK_APP=app.py FLASK_ENV=development flask db migrate
FLASK_APP=app.py FLASK_ENV=development flask db upgrade
FLASK_APP=app.py FLASK_ENV=development flask db migrate
Accounts are auto populated with default passwords. Accounts for federal offices include their accounts include FED-HOSS, FED-ADMIN, FED-AOC, FED-MAIL, FED-HOSS-ADMIN, FED-AOC-ADMIN, and FED-MAIL-ADMIN. Accounts for state offices are in the form NY-02 and NY-02-ADMIN. The password is the username plus -1010 (e.g., NY-02-1010). See security for what these accounts are authorized to do.
After making changes to one or more database models you have two optoins:
- Regenerate Schema from Scratch This is the preferred method until the application goes into development so that all schema is defined in a single file.
source setup/init_schema.sh
- Create Schema Upgrade Scripts Once the application is production you need to create schema upgrade scripts that upgrade the schema from the previous model to the current model. You may also need to write scripts to populate the new columns, unless you can provide default values for the columns or make them optional. Follow these steps
source db_schema.sh
- if required:
- create scripts to populate new columns
- look in migrations/versions directory for most recent python script
- add call to those scripts from that script
- if you renamed or dropped tables or columns you may need to adjust the script to do this correctly
When fully implemented:
- Only FED accounts can add orders and view and update all orders regardless of the associated home office
- State office accounts can view and update orders associated with their home office
- Only accounts ending in ADMIN can change passwords for users associated with their home office, e.g. NY-02-ADMIN can change passwords for NY-02 and NY-02-ADMIN
- Accounts not ending in ADMIN cannot change passwords
- FED-ADMIN is unrestricted from doing any task. As of when this is written, the only task that is restricted to just FED-ADMIN is maintaining users.
pytest -s --verbose
pytest --cov --cov-report html:coverage
open coverage/index.html
pip install datasette
first if needed, then
datasette flag.db
click the link (typically port 8001 on localhost)
or run sqlite
- Install Heroku if not done
- If you do not have a heroku account, create an account using
heroku login
- Request permission to push to heroku repository
Below instructions assume you are using codefordc-flag repository and app. If you are using a different repository and app, substitute codefordc-flag with the appropriate name.
heroku login
heroku git:remote -a codefordc-flag
heroku config:set FLASK_APP=app.py FLASK_ENV=development
Follow instructions above to use existing Heroku environment if not done.
git checkout main
git pull origin main
git push heroku main
Follow instructions above to use existing Heroku environment if not done.
heroku pg:reset
heroku run flask db upgrade
heroku run python populate_seed_data.py
URL for current Netlify app is https://codefordc-flag.netlify.app/
This is for first time installation if you need to rebuild or create a new Heroku environment different from the existing codefordc-flag. If you want to use codefordc-flag, see Configuring Heroku Environment
heroku create
=====================
Heroku will create a repository for you with a random name. The app is the same as the repository without the .git. You can rename it. For the shared dev heroku, the name is codefordc-flag
======================
Step #2 For , use the app created in step 1.
heroku git:remote -a <app name>
heroku config:set FLASK_APP=app.py FLASK_ENV=development
heroku addons:create heroku-postgresql:hobby-dev --app <app name>
git checkout main
git pull origin main
git push heroku main
heroku run flask db upgrade
heroku run python populate_seed_data.py
DATABASE_URL in Heroku defaults to start with postgres: but it should start with postgresql to work with Flask. There is code that will make the change when running the app, but it would be better if Heroku had the right values. I (Ethan) was able to get the change to stick once but after trying again, I ran into various problems, so below instructions will need to change.
- Check DATABASE_URL created in Heroku (from heroku.com, navigate to App, click on Settings gear, click on Reveal Config Vars)
- If DATABASE_URL starts with postgres: follow the below steps to change it to postgresql: otherwise continue to step 3
- Copy and paste the DATABASE_URL from Heroku
- will be the same URL but replace postgres: with postgresql:
- Open terminal
# I get error with below command
heroku addons:detach DATABASE --app codefordc-flag
heroku config:add DATABASE_URL=<new URL>
heroku restart
heroku pg:reset
Other potentially useful commands:
heroku addons:add heroku-postgresql:hobby-dev DATABASE
heroku addons:attach heroku-postgresql:hobby-dev --app codefordc-flag
# useful if you accidentally create a second DB that does not use DATABASE_URL
heroku addons:destroy HEROKU_POSTGRESQL_NAVY
# Guidelines
## Proposed
Backend
- When returning an error, use format {"message": "<error message>", <error_number>). For example, ???. See ???.
- Use a parameter class for passing info
- Use table_record_to_json or table_to_json to convert from sqlalchemy to json in util.py
- Convert in the controller, not the actions
- If a function requires three or more parameters, create a class to hold those params. See UserParams
as an example. This simplifies a bunch of code so you don't need to repeat.
## Accepted