Data generation

Schema in, working stack out.

A backend project’s database comes from files you author plus files Contrast generates. This page is the reference for that loop. It covers browser projects, meaning App and Game; the Website template has no data stack.

Files you author

Three files at the project root define the data model:

FilePurpose
database/schema.tsYour Drizzle tables.
database/relations.tsRelations between tables.
database/drizzle-zero.config.tsWhich tables Zero syncs to the client. A table must be listed here to reach the app.

A fourth, database/seed.ts, holds the rows a fresh database starts with. It is data rather than schema, so it does not take part in the generate/migrate loop below.

Generated outputs

Run → Generate writes these from your schema. They are outputs, so never hand-edit them:

FileWhat it is
data/generated/schema.tsThe generated Zero schema your app imports.
data/generated/*.tsThe generated query, mutation, and model registries.
database/generated/init.sqlThe generated SQL to initialize the database.

Run menu actions

  • Generate regenerates the outputs above from your current schema files, and flags that a migrate is now needed. Run it after you change a table.
  • Migrate compares the running database against your current schema, applies the supported diffs, and requires confirmation for anything destructive (a drop that would lose data). It diffs against a saved baseline of the last-applied schema, so it only acts on what actually changed.
  • Restart disposes and reboots the in-browser dev stack for a clean slate.

Validating a change

After a schema change, run Generate, then Migrate, then confirm in the SQLite DevTools pane that the tables and rows look right. Agents validate the same way, through these project actions and the generated schema rather than any root shell command.

Dependencies

Adding or removing a package is the same idea, driven by package.json: edit it and save. A change to runtime dependencies restarts the project’s runtime and rebuilds the previews; dev-dependency changes may only rebuild; type-only changes don’t rebuild at all. Saving invalid JSON gives a hard error until it parses. For native, check a package against the compatibility scanner before relying on it.

Platform migrations are separate

Contrast’s own repository uses a different, repo-level migration workflow for contributors to Contrast itself. Changing a browser project’s data always goes through the Run menu actions above; never reach for the platform workflow from inside a project.

Ready?

Create a web, iOS, and Android app in minutes with agents working alongside you.