# Data & Persistence

**Edit one schema file, run one generate, and every consumer follows** — the typed Prisma client, the matching zod validation schemas, and the migration all come out of the same `netscript db` workflow. That matters most when the one doing the editing is an AI agent: persistence is where a generated backend usually drifts, because a model change normally fans out into separate client, validation, and migration updates — each one a turn that can be missed. NetScript folds those into one cycle.

The pillar splits state along one line. **Records** — durable, relational, queried with a typed client — live in the [database layer](https://rickylabs.github.io/netscript/data-persistence/database/), where every plugin contributes its own models to the same datasource. **Execution state** — caches, sessions, work queues, scheduled ticks — lives in [KV, queues & cron](https://rickylabs.github.io/netscript/data-persistence/kv-queues-cron/), provider-agnostic packages that run on zero-config local backends until [Aspire](https://rickylabs.github.io/netscript/explanation/aspire/) provisions the production ones. The scaffold uses both from day one: Postgres for records, Redis/KV for execution state.

Start here when the question is where state lives, how schema changes ship, or how the workspace resolves a second database.

[Overview & Concepts   Database and KV  The persistence layer behind services, queues, and workflow state.](https://rickylabs.github.io/netscript/netscript/data-persistence/database/) [Quickstart   Data contracts  Follow the Storefront data step before service and saga work expand it.](https://rickylabs.github.io/netscript/netscript/tutorials/storefront/03-cart-contracts/) [How-To   Database and migration  Initialize and migrate the primary datasource.](https://rickylabs.github.io/netscript/netscript/data-persistence/how-to/database-migration/) [How-To   Second database  Add and address another datasource from the workspace.](https://rickylabs.github.io/netscript/netscript/data-persistence/how-to/use-a-second-database/) [API Reference   database  Generated database package symbols.](https://rickylabs.github.io/netscript/netscript/reference/database/) [API Reference   kv and Prisma adapter  Generated KV and adapter package symbols.](https://rickylabs.github.io/netscript/netscript/reference/kv/)

## Learn, do, look up

[Learn  Storefront tutorial  Cart contracts back a real database schema from chapter 3 on.](https://rickylabs.github.io/netscript/netscript/tutorials/storefront/) [Do  Recipes  Task-oriented recipes for this area, one problem each.](https://rickylabs.github.io/netscript/netscript/data-persistence/how-to/) [Look up  `@netscript/database` reference  Generated API reference. Related units: `kv`, `prisma-adapter-mysql`.](https://rickylabs.github.io/netscript/netscript/reference/database/) [Understand  Architecture  The design rationale behind this pillar.](https://rickylabs.github.io/netscript/netscript/explanation/architecture/)
