Package: eflips-model
eflips-modelPart of theeFLIPS/simBAlist of projects.This repository contains both thereference specification, anSQLALchemy implementationand ausage exampleof the eFLIPS database.Reference SpecificationThe reference specification is located (for now) in the huge PDF fileschema.pdf. It is a UML diagram of the database schema. The diagram was created usingOmniGraffle(proprietary).SQLAlchemy ImplementationThe SQLAlchemy implementation is located in theeflips/modeldirectory. It is a Python package that contains the SQLAlchemy models and the database migration scripts. The package is structured as follows:InstallationReleases of the package will be made available onhttps://pypi.org/. As such, it is installable withpip install eflips-model. However, it should be used by including it in other packages as a dependency. The versioning scheme issemantic versioning. This means that:patch releases (e.g.1.0.0to1.0.1) are backwards compatible bug fixes, without schama changesminor releases (e.g.1.0.0to1.1.0) are backwards compatible feature additions, with the schema changes being optionalmajor releases (e.g.1.0.0to2.0.0) are backwards incompatible changes, with the schema changes being mandatorySupported database backends arePostgreSQLwith thePostGISextension (CREATE EXTENSION postgis;)
andbtree_gist(CREATE EXTENSION btree_gist;)UsageThis package is not expected to be used directly. It is a dependency of theeflips-*packages.This package utilizes GIS extensions throughGeoAlchemy.
However, we are not handling geometry on the python side in any special way. When developing a paclage that useseflips-model, you will probably additionally
needShapelyandpyProj, which are not pure python packages and require additional
dependencies to be installed on the system.Schema updatesThe schema updates are handled byAlembic. The migration scripts are located in theeflips/model/migrationsdirectory. To create a new migration script, execute the following commands in the root directory of the repository:cdeflips/model
alembicrevision--autogenerate-m"vx.y.z"# Edit the migration script, as necessaryCreating a migration script is required for every change to the database schema, which should also correspond to a minor or major version change in the package version.To apply the migration scripts, execute the following command in the root directory of the repository:cdeflips/modelexportDATABASE_URL=postgresql://user:pass@hostname:port/dbname# Change to your database URLalembicupgradeheadTestingWe usepytestfor testing. The tests are located in thetestsdirectory. To run the tests, execute the following command in the root directory of the repository (after installing thedevdependencies):NOTE: Be aware that the tests will clear the database specified in theDATABASE_URLenvironment variable. Make sure that you are not using a database that you want to keep.# Change to your database URLexportDATABASE_URL=postgresql://user:pass@hostname:port/dbnamepytestDocumentationThe documentation is generated usingsphinx. To generate the documentation,
execute the following command in the root directory of the repository:sphinx-builddoc/doc/_build-WDevelopmentWe utilize theGitHub Flowbranching structure. This means  that themainbranch is always deployable and that all development happens in feature branches. The feature branches are merged intomainvia pull requests. We utilize thesemantic versioningscheme for versioning.Dependencies are managed usingpoetry. To install the dependencies, execute the following command in the root directory of the repository:poetryinstallWe use black for code formatting. You can useblack .to format the code.We useMyPyfor static type checking. You can
usemypy --strict --explicit-package-bases  eflips/to run MyPy on the code.Please make sure that yourpoetry.lockandpyproject.tomlfiles are consistent before committing. You can usepoetry checkto check this. This is also checked by pre-commit.You can usepre-committo ensure that MyPy, Black, and Poetry are run before committing. To
install pre-commit, execute the following command in the root directory of the repository:We recommend utilizing linters such asPyLintfor static code
analysis (but not
doing everything it says blindly).Usage ExampleInexamplesa well-documented (german-language)Jupyternotebook can be found that explains how all pieces of the data structure fit together using the SQLAlchemy Implementation. See itsREADMEfor details.LicenseThis project is licensed under the AGPLv3 license - see theLICENSEfile for details.Funding NoticeThis code was developed as part of the projecteBus2030+funded by the Federal German Ministry for Digital and Transport (BMDV) under grant number 03EMF0402.