From bf8d7c5279b3d0876c6144fb201a355e504e50b8 Mon Sep 17 00:00:00 2001 From: nargis-sultani <102271080+nargis-sultani@users.noreply.github.com> Date: Wed, 3 Jan 2024 09:52:18 -0600 Subject: [PATCH] Added a script to reset the db (#80) Co-authored-by: Nargis Sultani --- README.md | 8 ++++++++ db_revisions/dev_setup.sh | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100755 db_revisions/dev_setup.sh diff --git a/README.md b/README.md index 307dbc6..00bd9c3 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,14 @@ $ docker compose up -d pg keycloak ``` ![Docker](images/sbl_project_svcs.png) +--- +## Resetting DB and Seeding mock data +On app startup, alembic creates all the tables and seeds the lookup tables. +Running the below script with the 'reset' argument will reset the db: +db_revisions/dev_setup.sh reset +Passing the 'reset-then-seed' argument to the script will reset the db and then seed the lookup tables: +db_revisions/dev_setup.sh reset-then-seed + --- ## Running the app Once the [Dependencies](#dependencies), and [Pre-requisites](#pre-requisites) have been satisfied: diff --git a/db_revisions/dev_setup.sh b/db_revisions/dev_setup.sh new file mode 100755 index 0000000..87fcd05 --- /dev/null +++ b/db_revisions/dev_setup.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +if [[ $1 == "" ]] +then + echo "No arguments passed!" + echo "The argument must be either reset or reset-then-seed" + exit 0 +fi + +ACTION=$1 + +if [ $ACTION == "reset" ] +then + #If only need to reset db + poetry run alembic downgrade base +elif [ $ACTION == "reset-then-seed" ] +then + #First reset the db + poetry run alembic downgrade base + #Then upgrade it to head + poetry run alembic upgrade head +fi \ No newline at end of file