From 497e1b739af0ebd71204b69253831e1f92e9c6e1 Mon Sep 17 00:00:00 2001 From: gluap Date: Thu, 25 May 2023 22:24:05 +0200 Subject: [PATCH] Add a first shot at upgrade documentation (WIP) --- UPGRADING.md | 24 +++++++++++++++++++++++- api/tools/reimport_tracks.py | 30 ++++++++++++++++++++++++++++++ api/tools/upgrade.py | 15 ++++++++++----- 3 files changed, 63 insertions(+), 6 deletions(-) create mode 100755 api/tools/reimport_tracks.py diff --git a/UPGRADING.md b/UPGRADING.md index e22bf19..e8e981e 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -1,10 +1,32 @@ # Upgrading - This document describes the general steps to upgrade between major changes. Simple migrations, e.g. for adding schema changes, are not documented explicitly. Their general usage is described in the [README](./README.md) (for development) and [docs/production-deployment.md](docs/production-deployment.md) (for production). + +## 0.8.0 +Upgrade to `0.7.x` first. See below for details. Then follow these steps: + +> **Warning** The update includes a reprocessing of tracks after import. Depending on the number of tracks this can take a few hours. The portal is reachable during that time but events disappear and incrementally reappear during reimport. + +> **Info** With this version the Import process for OpenStreetMap data has changed: the [new process](docs/osm-import.md) is easier on resources and finally permits to import a full country on a low-end VM. + +- Do your [usual backup](docs/production-deployment.md) +- Rebuild images +- Stop your portal and worker services +- run upgrade + ```bash + docker-compose run --rm portal tools/upgrade.py + ``` + this automatically does the following + - Migration of database schema using alembic. + - Upgrade of SQL tile schema to new schema. + - Import the nuts-regions from the web into the database. + - Trigger a re-import of all tracks. +- Start your portal and worker services. + + ## 0.7.0 Upgrade to `0.6.x` first. See below for details. Then follow these steps: diff --git a/api/tools/reimport_tracks.py b/api/tools/reimport_tracks.py new file mode 100755 index 0000000..4f201db --- /dev/null +++ b/api/tools/reimport_tracks.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +import logging +import asyncio + +from sqlalchemy import text + +from obs.api.app import app +from obs.api.db import connect_db, make_session + +log = logging.getLogger(__name__) + +async def main(): + logging.basicConfig(level=logging.DEBUG, format="%(levelname)s: %(message)s") + await reimport_tracks() + + +async def reimport_tracks(): + + async with connect_db( + app.config.POSTGRES_URL, + app.config.POSTGRES_POOL_SIZE, + app.config.POSTGRES_MAX_OVERFLOW, + ): + async with make_session() as session: + await session.execute(text("UPDATE track SET processing_status = 'queued';")) + await session.commit() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/api/tools/upgrade.py b/api/tools/upgrade.py index 86ff1d7..8b1c83d 100755 --- a/api/tools/upgrade.py +++ b/api/tools/upgrade.py @@ -1,14 +1,15 @@ #!/usr/bin/env python3 -import logging import asyncio -from alembic.config import Config -from alembic import command -from os.path import join, dirname +import logging log = logging.getLogger(__name__) from prepare_sql_tiles import prepare_sql_tiles, _run +from import_regions import main as import_nuts + +from reimport_tracks import main as reimport_tracks + async def _migrate(): await _run("alembic upgrade head") @@ -20,7 +21,11 @@ async def main(): await _migrate() log.info("Preparing SQL tiles...") await prepare_sql_tiles() - log.info("Upgraded") + log.info("Importing nuts regions...") + await import_nuts() + log.info("Nuts regions imported, scheduling reimport of tracks") + await reimport_tracks() + if __name__ == "__main__":