Schema management
Deeper dive into how schemas work in Basic
Overview
In Basic, we declare schemas in a JSON format as part of the basic.config.ts
or basic.config.js
file that lives in your repository.
These basic.config
files can be committed to git, and unlock “schema-as-code” capabilities for your project.
Schemas would follow this general format:
The top level requires three parameters:
project_id
This is your project ID, which you can find in the Basic dashboard, or will be auto-generated for you if you had used the CLI to create your project.
version
This will be used for versioning your schema. It should be an integer that starts at 0 and increments by 1 for each new version.
Tables
Let’s double click into the tables to learn how they are declared in the schema.
Each table is declared as an object where the key is the table name and the value is an object with the following two parameters:
type
This refers to the type of database table you are creating. At the moment, Basic only supports collection
, which will operate similarly to MongoDB collections.
fields
Fields are the columns of the table. They will be declared as an object of objects. Learn more about the fields below.
Fields
Each field is declared as an object where the key is the field name and the value is an object with the following 2 parameters:
type
This is the data type of the field. Basic supports the following field types: string
, number
, boolean
, json
.
indexed
This lets you control if the field should be indexed in the user’s client database for local-first benefits. For now, this should always be set to true
.
Example
When put all together, your schema could look like this: