diff --git a/README.md b/README.md index f613687..023e0e3 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,17 @@ This will run the seed scripts in the `scripts` directory, and will seed the dat The initial data is a list of major, minor and peripheral stellar bodies as given in the HD-DM-GC-HR-HIP-Bayer-Flamsteed Cross Index (Kostjuk, 2002), which can be found in the VizieR catalogue database here: [VizieR-2](https://vizier.u-strasbg.fr/viz-bin/VizieR-2), and cross-referenced with the IAU list of approved star names (*as of January 1st, 2021), which can be found here: [https://www.iau.org/public/themes/naming_stars/](https://www.iau.org/public/themes/naming_stars/). +### Flushing API Data + +To flush the database, you can use the following command: + +```console +$ docker compose -f local.yml exec api ./scripts/init_db_flush.sh +``` + +This will run the flush scripts in the `scripts` directory, and will flush the database of all data. + + ### Running Tests To run the tests, please ensure you have followed the steps for building the development server: diff --git a/app/flush/__init__.py b/app/flush/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/flush/bodies.py b/app/flush/bodies.py new file mode 100644 index 0000000..0903df9 --- /dev/null +++ b/app/flush/bodies.py @@ -0,0 +1,15 @@ +from logging import Logger + +from sqlalchemy.orm import Session + +from app import crud +from app.utils import ROOT_DIR + + +def flush_bodies(db: Session, logger: Logger) -> None: + """ + This function call flushes the Body model + """ + logger.info("ROOT_DIR: {}".format(ROOT_DIR)) + + crud.body.delete_multi(db) diff --git a/app/init_db_flush.py b/app/init_db_flush.py new file mode 100644 index 0000000..0a5b7fe --- /dev/null +++ b/app/init_db_flush.py @@ -0,0 +1,27 @@ +import logging + +from sqlalchemy.orm import Session + +from app.db.session import SessionLocal +from app.flush.bodies import flush_bodies + +logging.basicConfig(level=logging.INFO) + +logger = logging.getLogger(__name__) + + +def flush(db: Session) -> None: + db = SessionLocal() + # Flush the bodies table: + flush_bodies(db, logger) + + +def main() -> None: + db = SessionLocal() + logger.info("Flushing Existing API Data Started") + flush(db) + logger.info("Flushing Existing API Data Success") + + +if __name__ == "__main__": + main() diff --git a/scripts/init_db_flush.sh b/scripts/init_db_flush.sh new file mode 100755 index 0000000..ef01c43 --- /dev/null +++ b/scripts/init_db_flush.sh @@ -0,0 +1,2 @@ +#!/bin/sh +python app/init_db_flush.py \ No newline at end of file