---
title: "Data model & migrations"
description: "The EdgeCart D1 schema, Drizzle migrations, and store scoping."
---

> Documentation Index
> Fetch the complete documentation index at: https://edgecart.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Data model & migrations

EdgeCart keeps commerce, Better Auth, plugin control-plane, and outbox data in
one Cloudflare D1 database. The schema is managed with Drizzle and applied
through Wrangler migrations.

## Schema ownership

| Area | Tables live in |
|---|---|
| Commerce | `packages/commerce-core/src/schemas` and the commerce modules. |
| Auth | Better Auth schema generated into `commerce-core`. |
| Plugins | Plugin installs, releases, settings, KV, documents. |
| Outbox | Audit, outbox events, webhook endpoints, deliveries, email. |

Commerce rows are scoped by `store_id`. The admin is single-store, but the data
model and Admin API still use `store_id` / `x-store-id`.

## Generate and apply migrations

```sh
pnpm db:generate       # generate Drizzle migrations
pnpm db:migrate:local  # apply to the local D1 database
pnpm db:migrate:remote # apply to the remote D1 database
```

Migrations live in `apps/edgecart/drizzle/migrations`. Better Auth's schema is
generated separately:

```sh
pnpm ba:generate
pnpm db:generate
pnpm db:migrate:local
```

> **Remote migrations are separate**
>
> A local migration does not touch the remote database. Run
> `pnpm db:migrate:remote` after deploying schema changes.

## Design rules

- Money is stored as integer minor units with a currency code.
- Status fields are constrained to known values; invalid states are rejected.
- Audit and outbox rows are written with the mutation that caused them.
- Plugin secrets are encrypted at rest and never serialized into invocations.

The [Commerce modules](https://edgecart.dev/modules/) explain each domain's concepts without the
schema detail.

## Related

- [Architecture](https://edgecart.dev/developers/architecture)
- [Deployment](https://edgecart.dev/developers/deployment)
- [Commerce modules](https://edgecart.dev/modules/)

Source: https://edgecart.dev/developers/data-model/index.mdx
