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

First mechanism of export from internal DB (postgres) to exploitation DB (mongo) #251

Merged
merged 1 commit into from
Sep 13, 2023

Conversation

antoineludeau
Copy link
Member

@antoineludeau antoineludeau commented Aug 29, 2023

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).

Capture d’écran 2023-08-30 à 11 04 00

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 the export-to-exploitation-db-consumer.js file. This mechanism is :

  • Deleting all data from the district (district, common toponyms, addresses)
  • Getting the district data from PostgreSQL DB
  • Sending the district data to Mongo DB
  • Getting paginated data from common toponyms
  • Sending each page to Mongo DB
  • Getting paginated data from addresses
  • Sending each page to Mongo DB
    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 :

[
  {
    "id": "7d40ffcc-57e2-4621-a538-e3ef20b74b8e",
    "labels": [
      {
        "isoCode": "fra",
        "value": "Toulouse"
      }
    ],
    "updateDate": "2023-01-01",
    "meta": {
        "insee": {
            "cog": "31555"
        }
    },
    "config": {
        "useBanId": true
    }
  }
]

2- After around 10 seconds, you should see the logs :

Exporting districtID 7d40ffcc-57e2-4621-a538-e3ef20b74b8e to exploitation DB...
2023-08-29 14:42:22 Exporting districtID 7d40ffcc-57e2-4621-a538-e3ef20b74b8e done

After a few seconds, check if the data has been exported to MongoDB in the new collection districts

{
  "id": "7d40ffcc-57e2-4621-a538-e3ef20b74b8e",
  "labels": [
    {
      "value": "Toulouse",
      "isoCode": "fra"
    }
  ],
  "updateDate": {
    "$date": "2023-01-01T00:00:00.000Z"
  },
  "config": {
    "useBanId": true
  },
  "meta": {
    "insee": {
      "cog": "31555"
    }
  },
  "createdAt": {
    "$date": "2023-08-28T16:05:16.528Z"
  },
  "updatedAt": {
    "$date": "2023-08-28T16:05:51.037Z"
  }
}

@antoineludeau antoineludeau marked this pull request as draft August 29, 2023 09:15
@antoineludeau antoineludeau self-assigned this Aug 29, 2023
@antoineludeau antoineludeau marked this pull request as ready for review August 29, 2023 14:03
@antoineludeau antoineludeau force-pushed the antoineludeau/export-to-exploitation-db branch 2 times, most recently from 34e955e to b336869 Compare August 29, 2023 15:12
@antoineludeau antoineludeau force-pushed the antoineludeau/export-to-exploitation-db branch from 77f3700 to a7ab5d7 Compare September 13, 2023 10:35
@antoineludeau antoineludeau merged commit ea66f28 into master Sep 13, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BAN-Plateforme] Premier mécanisme d'export de nouvelle BDD (PostgreSQL) vers BDD d'exploitation (Mongo)
4 participants