Applies when there are changes made to the database and a new models.py file needs to be generated, otherwise skip to Local Environment.
The models.py file is generated using sqlacodegen
Need to add import statement to sqlacodegen/codegen.py
in order to account for geoalchemy2. The codegen.py
file is part of the sqlacodegen
package installed by pip.
From the top level of the repository:
$ cd server/
$ virtualenv -p /PATH_TO/python3 venv
$ source venv/bin/activate
$ pip3 install -r requirements.txt
Assuming venv
is the name of the virtualenv directory the codegen.py
files will be at: /nih-exposures-api/server/venv/lib/python3.6/site-packages/sqlacodegen/codegen.py
.
Update it as follows:
from sqlalchemy.types import Boolean, String
import sqlalchemy
from geoalchemy2 import Geometry, Geography # <-- this line
From the terminal generate the models.py
file.
$ sqlacodegen --outfile models.py postgres://datatrans:datatrans@POSTGRES_DB_IP:5432/exposures
Where POSTGRES_DB_IP
is the actual IP of the database.
Update the generated models.py
file with appropriate imports.
from sqlalchemy.dialects.postgresql import TEXT, DOUBLE_PRECISION
From the top level of the repository:
$ cd server/
$ virtualenv -p /PATH_TO/python3 venv
$ source venv/bin/activate
$ pip3 install -r requirements.txt
ini/connexion.ini
Set up the ini/connexion.ini
file to match your environment. An example file named ini/connexion.ini.example
has been provided as a template.
$ cp ini/connexion.ini.example ini/connexion.ini
-
Change
/PATH_TO/
to be the actual path to the code. -
If using the docker based database update the
FQDN_OR_IP
to be that of the platform docker is being run from.[connexion] server = debug = True port = 5000 keyfile = certfile = [sys-path] exposures = /PATH_TO/nih-exposures-api/server/exposures controllers = /PATH_TO/nih-exposures-api/server/controllers [postgres] host = FQDN_OR_IP port = 5432 database = exposures username = datatrans password = datatrans
Ensure the database is running
- Docker implemented database described in database/README.md
To run the server, please execute the following:
python3 app.py
and open your browser to here:
http://localhost:5000/v1/ui/
Your Swagger definition lives here:
http://localhost:5000/v1/swagger.json
TODO
TODO