Skip to content

Commit

Permalink
update init db script and documentation (#103)
Browse files Browse the repository at this point in the history
* update init db script and documentation

* load env variable in initdb script

* fix running scripts outside container

* typo

---------

Co-authored-by: Antoine Jeanneney <antoine.jeanneney@justice.fr>
  • Loading branch information
ajeanneney and Antoine Jeanneney committed Jun 6, 2024
1 parent c881d7b commit ba6a2e8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
16 changes: 16 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ yarn init:db

This script is lauch with the `.env` configuration.

### Launch scripts

You can launch scripts with theses commands :

#### With docker

```sh
docker container exec -it label-backend-1 sh -c "cd packages/courDeCassation; sh scripts/runLocalScript.sh ./dist/scripts/myScript.js --myArgument"
```

#### Without docker

```sh
scripts/runScriptLocally.sh "myScript.js --myArgument"
```

## Troubleshooting

To use mongo, you need to run in your terminal:
Expand Down
20 changes: 15 additions & 5 deletions scripts/initializeTestDb.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#!/bin/sh

if [ -f .env ]; then
export $(grep -v '^#' .env | xargs)
fi

cd packages/courDeCassation;

echo "Reset the DB except for users and migrations"
RUN_MODE=LOCAL node packages/courDeCassation/dist/scripts/clearDb.js -s packages/courDeCassation/settings/settings.json
sh scripts/runLocalScript.sh ./dist/scripts/clearDb.js;

echo "Import the documents from SDER database"
RUN_MODE=LOCAL node packages/courDeCassation/dist/scripts/importAllDocumentsFromSderSinceOrBetween.js --fromDaysAgo 2 -s packages/courDeCassation/settings/settings.json
sh scripts/runLocalScript.sh ./dist/scripts/importAllDocumentsFromSderSinceOrBetween.js --fromDaysAgo 2;

echo "Annotate all the documents with the NLP engine"
RUN_MODE=LOCAL node packages/courDeCassation/dist/scripts/annotateDocumentsWithoutAnnotationsWithNlp.js -s packages/courDeCassation/settings/settings.json
sh scripts/runLocalScript.sh ./dist/scripts/annotateDocumentsWithoutAnnotationsWithNlp.js;

echo "Insert mock values in DB"
RUN_MODE=LOCAL node packages/courDeCassation/dist/scripts/initializeTestDb.js -s packages/courDeCassation/settings/settings.json
sh scripts/runLocalScript.sh ./dist/scripts/initializeTestDb.js;

echo "Create initial cache"
RUN_MODE=LOCAL node packages/courDeCassation/dist/scripts/renewCache.js --beforeMinutes=5 -s packages/courDeCassation/settings/settings.json
sh scripts/runLocalScript.sh ./dist/scripts/renewCache.js --beforeMinutes=5;

12 changes: 12 additions & 0 deletions scripts/runScriptLocally.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

SCRIPT_NAME="$1"
shift

if [ -f .env ]; then
export $(grep -v '^#' .env | xargs)
fi

cd packages/courDeCassation;

sh scripts/runLocalScript.sh ./dist/scripts/$SCRIPT_NAME

0 comments on commit ba6a2e8

Please sign in to comment.