Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nickruigrok/baseflare/llms.txt
Use this file to discover all available pages before exploring further.
defineSchema is the top-level function that assembles your entire data model. It accepts a plain object mapping table names to TableBuilder instances created by defineTable(), validates each table definition, normalizes partition index assignments across all tables, and returns a fully typed Schema object. The returned schema is the single source of truth consumed by createWorker, the CLI deploy command, and diffSchemas.
Signature
Parameters
A plain object where each key is a table name and each value is a
TableBuilder
returned by defineTable(). Table names must be valid identifiers (letters, digits,
underscores) and must not start with _.Returns
ASchema object with two members:
The normalized table definitions, keyed by table name. Each entry carries the
field validators and the final (normalized) index list with partition flags resolved.
Returns an array of SQL DDL strings — one
CREATE TABLE statement per table
followed by one CREATE INDEX statement per index across all tables. These are
the exact statements the CLI runs during deployment.Validation Rules
defineSchema enforces the following at call time; any violation throws a SchemaError:
- At least one table must be defined.
- Every table name must match
/^[A-Za-z][A-Za-z0-9_]*$/and must not start with_(those names are reserved for internal Baseflare system tables). - At most one partition index is allowed per table.
- Tables with multiple indexes must either mark exactly one index
{ partition: true }, or opt every index out with{ partition: false }. A mix of implicit and explicit partition settings is rejected. - A table with a single index has its partition flag defaulted to
trueunless explicitly set tofalse. - Partition indexes may only reference scalar field types (
boolean,enum,id,literal,number,string).
Example
diffSchemas(current, target)
diffSchemas is also exported from baseflare/server and is used by the Baseflare CLI to compute the delta between the schema currently deployed in a D1 database and the schema defined in your source code.
current against target and returns a SchemaDiff object:
Tables present in
target but not in current — will be created on deploy.Tables present in
current but absent from target. These are reported only — Baseflare never automatically drops tables to prevent data loss. Use the dashboard to remove them explicitly.Indexes present in
target but missing from current, or indexes whose field list has changed (old index is removed, new index is created).Indexes present in
current but absent from target.true if any of the above arrays are non-empty.Returns the ordered SQL statements that apply the diff:
DROP INDEX IF EXISTS for removed indexes, CREATE TABLE for added tables, CREATE INDEX for added indexes.diffSchemas is primarily an internal tool invoked by the CLI. You won’t need to
call it directly in application code.