Using the Data Layer
Where the database code is, for a contributor writing code against it.
- The API keeps its data in PostgreSQL through SQLAlchemy. The models are in
backend/app/models/, and the optional modules' inmodules/backend/app/models/. - The models' tables are in the schema
POSTGRES_SCHEMAnames. When it is not set, that istest_experimentationwithAPP_ENV=testorTESTING=true, andexperimentationotherwise. - A route's session comes from a dependency: see Dependency Injection.
- Import a model from the module that defines it, rooted at
backend.app:from backend.app.models.experiment import Experiment. - A script that runs outside the API calls
register_core_models()frombackend.app.modelsbefore its first query, so that SQLAlchemy can configure the mappers. - A change to a model needs a migration: see Guide to Using the SQLAlchemy Models and Database Migrations.