-
Notifications
You must be signed in to change notification settings - Fork 33
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.
-
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 aparentScraperRun
-
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
-
scraperRunsByLocationRefSortByTimestamp: given a
location
's ref (unique id), return all the associatedscraperRun
s, in order from newest to oldest -
appointmentsByScraperRun: given a
scraperRun
's ref, return all the associatedappointments
-
locationsByParentLocationRef: given a
parentLocation
's ref, return all the associated "child"location
s -
scraperRunsByParentScraperRunRef: given a
parentScraperRun
's ref, return all the associated "child"scraperRun
s (more precisely, thescraperRun
s of childlocation
s)
We use these Collections/Indices in the following way:
- For each scraper run, we create a
parentLocation
entry if it does not exist. - Then, we create a new document in the
parentScraperRun
table linked to thatparentLocation
. - 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. - For each location we find within that scraper run, we create a new document in the
scraperRun
table, linked to thelocation
andparentScraperRun
. - If that location has availability, we create a new document in the
appointments
table to detail the availability.
- For each
parentLocation
, we find the latestparentScraperRun
. - We then link each
parentScraperRun
with itsscraperRun
s, and eachscraperRun
is linked to itslocation
andappointments
.
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