Skip to content

Fauna DB Schema

Tessa Jones edited this page Apr 6, 2021 · 6 revisions

We store documents in a few Collections, and we make associations between the Collections using a few Indexes.

The schema is represent in the following diagram: https://dbdiagram.io/d/606b73e9ecb54e10c33ec955 and explained below.

Collections:

  • locations: one document represents one vaccination location/clinic (contains name, address, etc), associated with one parentLocation
  • parentLocations: one document represents a parent location's name, address etc. You can equate a "parent location" to a single scraper. Some of our scrapers, like Atrius, only have one location they scrape, but others have multiple - like Walgreens or MAImmunizations.
  • scraperRuns: one document represents one run of a scraper, associated with a particular location and a parentScraperRun
  • parentScraperRuns: one document represents one run of a scraper, associated with one parentLocation
  • appointments: one document represents appointment availability information for one date, associated with one scraperRun

Indexes:

  • scraperRunsByLocationRefSortByTimestamp: given a location's ref (unique id), return all the associated scraperRuns, in order from newest to oldest
  • appointmentsByScraperRun: given a scraperRun's ref, return all the associated appointments
  • locationsByParentLocationRef: given a parentLocation's ref, return all the associated "child" locations
  • scraperRunsByParentScraperRunRef: given a parentScraperRun's ref, return all the associated "child" scraperRuns (more precisely, the scraperRuns of child locations)

Uses

We use these Collections/Indices in the following way:

Writing

  1. For each scraper run, we create a parentLocation entry if it does not exist.
  2. Then, we create a new document in the parentScraperRun table linked to that parentLocation.
  3. For each location we find within that scraper run, we check if a matching entry in locations exists and write a new one if not.
  4. For each location we find within that scraper run, we create a new document in the scraperRun table, linked to the location and parentScraperRun.
  5. If that location has availability, we create a new document in the appointments table to detail the availability.

Reading

  1. For each parentLocation, we find the latest parentScraperRun.
  2. We then link each parentScraperRun with its scraperRuns, and each scraperRun is linked to its location and appointments.

Curious about Fauna's combo document / relational model? "FaunaDB’s model combines relational correctness and integrity with the ease of use of documents." Read more here: https://fauna.com/blog/unifying-relational-document-graph-and-temporal-data-models

Clone this wiki locally