---
title: "Your data"
description: "Where your own tables go beside the backend component, how they point at accounts and workspaces, which tier guards them, and how they join export, erasure and the activity trail."
canonical_url: "https://nuxt-backend.dev/docs/build/data/your-data"
---
# Your data

> Where your own tables go beside the backend component, how they point at accounts and workspaces, which tier guards them, and how they join export, erasure and the activity trail.

Version: nuxt-backend 0.6.x · Tab: Build · Kind: concept · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

Your tables live in your own schema, `backend/schema.ts`, beside the tables the `backend` component keeps. Convex gives you the database, its indexes and transactions, and keeps a component's tables apart from yours. The package adds the access tiers that guard your functions, the account and workspace ids they hand you, and the sources that join your tables to a person's export and erasure.

## The model

```text
your deployment
├─ your app             backend/schema.ts and backend/*.ts
│    └─ reaches the package through nuxt-backend/* and components.backend.*
├─ backend component    accounts, workspaces, billing cache, files, activity trail
└─ official components  workflow, workpool, and any your app mounts itself
```

Convex keeps a component's tables apart from the app's. The app cannot query a component's tables, and a component cannot query the app's. So the package's data and yours never mix, and each side reaches the other only through functions. Your schema holds only your tables: the scaffold writes no `schema.ts`, and you add one with your first table.

A row refers to the package's records by their ids. To your schema those ids are strings, because a `v.id()` validator names a table of your own schema. The access tiers hand you both ids, so you never read them from a client's arguments:

<table>
<thead>
  <tr>
    <th>
      Id
    </th>
    
    <th>
      Where you get it
    </th>
    
    <th>
      Store it as
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      The account
    </td>
    
    <td>
      <code>
        ctx.user.id
      </code>
      
      , in every tier
    </td>
    
    <td>
      <code>
        userId: v.string()
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      The workspace
    </td>
    
    <td>
      <code>
        ctx.workspace.id
      </code>
      
      , in the <code>
        workspace
      </code>
      
       and <code>
        withFeature(key)
      </code>
      
       tiers
    </td>
    
    <td>
      <code>
        workspaceId: v.string()
      </code>
    </td>
  </tr>
</tbody>
</table>

## Define a table

```ts [backend/schema.ts]
import { defineSchema, defineTable } from 'convex/server'
import { v } from 'convex/values'

export default defineSchema({
  strips: defineTable({
    workspaceId: v.string(),
    authorId: v.string(),
    title: v.string(),
  }).index('by_workspaceId', ['workspaceId']),
})
```

Read through an index rather than a filter. A filter still reads every row in the index range, so only an index keeps a read small as the table grows. Name an index after its fields (`by_workspaceId_and_title`). Return a bounded list: `take(n)`, or a page at a time with [pagination](https://nuxt-backend.dev/docs/build/data/read-write#pagination). The Convex guide to [indexes](https://docs.convex.dev/database/reading-data/indexes/) covers the rest.

## Guard every function

Anyone who reaches the deployment can call every function you export. So declare each one at the tier it needs, from the builders `backend/functions.ts` exports. A tier checks the caller before your handler runs, and refuses with a [typed error](https://nuxt-backend.dev/docs/build/data/read-write/errors) otherwise:

<table>
<thead>
  <tr>
    <th>
      Tier
    </th>
    
    <th>
      Who may call
    </th>
    
    <th>
      Hands you
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        authed
      </code>
    </td>
    
    <td>
      A signed-in account that is not banned
    </td>
    
    <td>
      <code>
        ctx.user
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        workspace
      </code>
    </td>
    
    <td>
      A member of the active workspace, checked fresh on every call
    </td>
    
    <td>
      <code>
        ctx.user
      </code>
      
      , <code>
        ctx.workspace
      </code>
      
       (<code>
        id
      </code>
      
      , <code>
        slug
      </code>
      
      , <code>
        name
      </code>
      
      , <code>
        role
      </code>
      
      )
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        admin
      </code>
    </td>
    
    <td>
      An application administrator
    </td>
    
    <td>
      <code>
        ctx.user
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        withRole(role)
      </code>
    </td>
    
    <td>
      An account with an app-wide role of yours
    </td>
    
    <td>
      <code>
        ctx.user
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        withFeature(key)
      </code>
    </td>
    
    <td>
      A member of a workspace whose plan has the feature
    </td>
    
    <td>
      <code>
        ctx.user
      </code>
      
      , <code>
        ctx.workspace
      </code>
    </td>
  </tr>
</tbody>
</table>

A mutation or an action can also ask for a recent sign-in. [Protect backend functions](https://nuxt-backend.dev/docs/build/auth/access/functions) covers each tier, its options and its refusals.

## Workspace-scoped tables

Most of a client app's data belongs to a workspace: the account's personal one, or one a few people share. Stamp the workspace on every row you write, index the table by it, and read through that index, all in the `workspace` tier. [Scope tables to a workspace](https://nuxt-backend.dev/docs/build/data/read-write/workspace-scoped) walks through it, with the check a function needs when it takes a row's id.

## Personal data joins export and erasure

When a person exports their data or deletes their account, the package covers every table it keeps, their billing customer, their email contact and the files they uploaded. A table of yours that holds something of a person (what they wrote, uploaded or set) joins as a source in `backend/account.ts`. A source is an internal query that reads an account's rows for the export, and an internal mutation that erases a batch of them. [Export and erase account data](https://nuxt-backend.dev/docs/build/auth/accounts/data) shows both.

Keep personal data where a source can find it: in a field of the row it belongs to, indexed by the account or the address. Rows that belong to a shared workspace stay when one of its members leaves.

## Your events on the activity trail

Sign-ins, workspace changes, subscriptions and administrator actions land on one activity trail, read per account and per workspace. Add your own events with `audit.recordBackendEvent(ctx, { type: 'app.<kind>', … })` from a mutation or an action. In a mutation, the event commits or rolls back with your own writes. [Record your own events](https://nuxt-backend.dev/docs/build/auth/admin/audit-log#record-your-own-events) has the fields and their limits.

## Why it works this way

A component's tables are sealed, so the package can migrate, prune and erase its own records without a migration of yours, and an upgrade never touches your schema. The cost is that a join across the line goes through a function: you store the package's ids as strings and read its records through its API. Ids arrive from `ctx`, after the tier has checked the caller, so a client can never name an account or a workspace it does not belong to.

## What it is not

- **Not another database.** Everything lives in your Convex deployment ([Convex](https://nuxt-backend.dev/docs/services/convex)). There is no adapter for SQL or another store.
- **Not an ORM.** You write Convex queries and mutations directly; the package adds tiers and helpers around them.
- **Not row-level security.** Each function checks access in code, through its tier and your own checks. The [Roadmap](https://nuxt-backend.dev/docs/start/roadmap) lists what waits for later releases.

## Change it later

- **Add a field** as optional, deploy, fill it in with a [migration](https://nuxt-backend.dev/docs/build/data/jobs/migrations), then make it required.
- **Add an index** to a large table with `staged: true`, so the deploy does not wait for its backfill.
- **Count or sum** rows with an [aggregate](https://nuxt-backend.dev/docs/build/data/read-write/aggregates), never by reading every row.
- **Delete what you no longer need** with a [retention rule](https://nuxt-backend.dev/docs/build/data/retention). The component's maintenance never touches your tables.

[Limits and retention](https://nuxt-backend.dev/docs/reference/backend/limits) gives the windows of the package's own tables. The Convex [limits](https://docs.convex.dev/production/state/limits) apply to every table, yours included.

## What this means for you

- Put your tables in `backend/schema.ts`, and store account and workspace ids as strings.
- Give every exported function a tier, and take ids from `ctx`, never from arguments.
- Add a source in `backend/account.ts` for every table that holds something of a person.
- Pick your deployment's region before you store real data: moving it later means a backup and a restore ([Convex](https://nuxt-backend.dev/docs/services/convex)).
- Next: [Query and update data](https://nuxt-backend.dev/docs/build/data/read-write) to read your tables live from Vue.


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
