Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added data flushing scripts for Body model. #69

Merged
merged 1 commit into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Empty file added app/flush/__init__.py
Empty file.
15 changes: 15 additions & 0 deletions app/flush/bodies.py
Original file line number Diff line number Diff line change
@@ -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)
27 changes: 27 additions & 0 deletions app/init_db_flush.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions scripts/init_db_flush.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
python app/init_db_flush.py