Add database migrations

- use Alembic to migrate the PostgreSQL database
  + create initial migration script to set up the database,
    as an alternative to db.Base.metadata.create_all()
  + integrate Alembic into the test suite; the db_engine fixture
    now has two modes:
    * create the latest version of tables all at once
    * invoke `alembic upgrade head`
    => the "e2e" tests are all run twice, once in each mode; this
       ensures that the migration scripts re-create the same database
       schema as db.Base.metadata.create_all() would
    * in both modes, a temporary PostgreSQL schema is used to create the
      tables in
    => could now run "e2e" tests against production database and still
       have isolation
- make the configuration module public (to be used by Alembic)
- adjust linting rules for Alembic
This commit is contained in:
Alexander Hess 2020-08-09 17:14:23 +02:00
commit a16c260543
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
14 changed files with 1104 additions and 35 deletions

View file

@ -74,7 +74,9 @@ PYTEST_LOCATION = 'tests/'
# Paths with all *.py files.
SRC_LOCATIONS = (
f'{DOCS_SRC}/conf.py',
f'{DOCS_SRC}conf.py',
'migrations/env.py',
'migrations/versions/',
'noxfile.py',
PACKAGE_SOURCE_LOCATION,
PYTEST_LOCATION,
@ -235,7 +237,12 @@ def test(session):
# non-develop dependencies be installed in the virtual environment.
session.run('poetry', 'install', '--no-dev', external=True)
_install_packages(
session, 'packaging', 'pytest', 'pytest-cov', 'xdoctest[optional]',
session,
'packaging',
'pytest',
'pytest-cov',
'pytest-env',
'xdoctest[optional]',
)
# Interpret extra arguments as options for pytest.