-
Notifications
You must be signed in to change notification settings - Fork 1
Airtable Schema Generator
The Airtable Schema Generator is a tool we developed alongside this web app that generates helper functions on top of the basic Airtable Javascript client. It generates these helper functions in accordance with your Airtable Schema. The details on how it works and all the settings available can be found on its readme. Below are details about how it is configured on our repositories.
Whenever the schema on airtable is changed, it's necessary to run the schema generator in order to keep the local files in sync with Airtable. Generally speaking, since schema changes affect every branch immediately, schema updates should be merged separately from a development branch.
The schema can be regenerated with the command yarn generate-schema
. You must fill in the AIRTABLE_EMAIL
and AIRTABLE_PASSWORD
sections of your own .env file and allow password login on Airtable. These credentials are not saved anywhere except on your computer. This allows the schema generator to scrape your schema from Airtable. If you're curious what is happening, change auto-headless
in the schema generator's settings in package.json
to auto
.
The schema generator's settings are in package.json
. For the most part, they will not need to be edited. Details are below.
The schema generator outputs 4 files:
This file interacts with the airtable client and exposes the core CRUD functions. It also contains the logic that translates the airtable column names to JS-formatted names. "First Name"
becomes "firstName"
, "Project Group"
becomes "projectGroupId"
(assuming it is a one-to-one relation field).
This file contains helper functions for every crud operation for every table. It's a convenience layer over airtable.js
This file is a schema mapping that describes all the table and column names in a JS format. The app should never use this file but it is necessary for airtable.js
to translate records to JS-readable variable names. It should be used as a reference to know what a column name has been translated to.
This is a JSON version of schema.js
for reference.
Schema Generator Settings:
"airtable-schema-generator": {
"output": "src/lib/airtable",
"input": "src/lib/airtable",
"defaultView": "Grid view",
"mode": "auto-headless",
"airlock": true
}
-
output
signifies where to save the generated files -
input
signifies where to look for input files (currently unused, there are no input files) -
defaultView
signifies which View to use on Airtable. It uses the same view across all tables -
mode
signifies how to fetch the schema. The options are detailed on the schema generator repo, butauto-headless
will scrape the schema for you with no unnecessary windows -
airlock
signifies that we want theairlock
version of theairtable.js
file.
"airtable-schema-generator": {
"output": "airtable",
"mode": "auto-headless",
"overwrite": false,
"schemaMeta": {
"Owner": {
"lookupFields": [
"Email"
]
}
}
}
-
output
signifies where to output generated files -
mode
signifies how to get the files -
overwrite
signifies that we do not want to overwrite airtable.js. This is set to true because on node, we need one extra line in ourairtable.js
to make it work. If the schema generator is updated, however, it's crucial to grab the latest version ofairtable.js
by setting this flag to false. -
schemaMeta
describes any extra helper functions we want to create. In this case, we want to create a helper function that lets us look up owners by their email. This extra function is created inrequest.js