First mechanism of export from internal DB (postgres) to exploitation DB (mongo) #251
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I. Context
We are currently using mongoDB as our unique DB to store data and to exploit them. We have implemented a PostgreSQL relational DB that stores the data from our new BAN-ID schema API. We now need to implement an export mechanism from PostgreSQL (internal DB) to MongoDB (exploitation DB).
II. Enhancement
1- We have decided to trigger the export of an entire district when : updating, creating and deleting an address or a common toponym from this district.
2- Each time that happens, a job is created (
jobID = districtID
) in a new queue :export-to-exploitation-db
3- The job is delayed for
10s
. If a job with the same ID is created during this delay, it replaces the job waiting in the queue.4- After the
10s
, the job is consumed by a mechanism coded in theexport-to-exploitation-db-consumer.js
file. This mechanism is :5- All of this process is done in a transaction that is locking the data of each pages (for common toponyms and addresses) before each export.
III. How to test
1- Push a district using the API : POST /district
Example :
2- After around 10 seconds, you should see the logs :
After a few seconds, check if the data has been exported to MongoDB in the new collection
districts