---
title: "nuxt-backend/migrations"
description: "Every export of nuxt-backend/migrations, with its signature and where it is defined."
canonical_url: "https://nuxt-backend.dev/docs/reference/api/migrations"
---
# nuxt-backend/migrations

## Interfaces

### MigrationsComponents

Defined in: [src/convex/integrations/migrations.ts](https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/migrations.ts)

The component handle `setupMigrations` reads from your generated `components`
object (the key is picked structurally — pass the whole object).

#### Properties

<table>
<thead>
  <tr>
    <th>
      Property
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Defined in
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="migrations">
        
      </a>
      
       <code>
        migrations
      </code>
    </td>
    
    <td>
      <code>
        ComponentApi
      </code>
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/migrations.ts" rel="nofollow">
        src/convex/integrations/migrations.ts
      </a>
    </td>
  </tr>
</tbody>
</table>

---

### SetupMigrationsOptions

Defined in: [src/convex/integrations/migrations.ts](https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/migrations.ts)

#### Type Parameters

<table>
<thead>
  <tr>
    <th>
      Type Parameter
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="type-parameter-schema">
        
      </a>
      
       <code>
        Schema
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        SchemaDefinition
      </code>
      
      <<code>
        GenericSchema
      </code>
      
      , <code>
        boolean
      </code>
      
      > | <code>
        void
      </code>
    </td>
  </tr>
</tbody>
</table>

#### Properties

<table>
<thead>
  <tr>
    <th>
      Property
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Description
    </th>
    
    <th>
      Defined in
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="schema">
        
      </a>
      
       <code>
        schema?
      </code>
    </td>
    
    <td>
      <code>
        Schema
      </code>
    </td>
    
    <td>
      Your database schema. Recommended — it provides table types to <code>
        migrations.define({ table, migrateOne })
      </code>
      
       and enables custom index ranges.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/migrations.ts" rel="nofollow">
        src/convex/integrations/migrations.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="defaultbatchsize">
        
      </a>
      
       <code>
        defaultBatchSize?
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      Documents processed per transaction batch (default 100).
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/migrations.ts" rel="nofollow">
        src/convex/integrations/migrations.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="migrationslocationprefix">
        
      </a>
      
       <code>
        migrationsLocationPrefix?
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      Prefix added to function names when running migrations from the CLI.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/migrations.ts" rel="nofollow">
        src/convex/integrations/migrations.ts
      </a>
    </td>
  </tr>
</tbody>
</table>

## Functions

### setupMigrations()

```ts
function setupMigrations<Schema>(components, options?): {
  migrations: Migrations<GenericDataModel, Schema, Schema extends SchemaDefinition<any, boolean> ? MaybeMakeLooseDataModel<{ [TableName in string]: Schema["tables"][TableName] extends TableDefinition<DocumentType, Indexes, SearchIndexes, VectorIndexes> ? { document: Expand<IdField<TableName> & Expand<(...) & (...)>>; fieldPaths: "_id" | ExtractFieldPaths<DocumentType>; indexes: Expand<Indexes & SystemIndexes>; searchIndexes: SearchIndexes; vectorIndexes: VectorIndexes } : never }, Schema["strictTableNameTypes"]> : GenericDataModel>;
  run: RegisteredMutation<"internal", {
     fn?: string;
     cursor?: string | null;
     batchSize?: number;
     dryRun?: boolean;
     next?: string[];
     reset?: boolean;
     oneBatchOnly?: boolean;
  }, Promise<Record<string, unknown>>>;
};
```

Defined in: [src/convex/integrations/migrations.ts](https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/migrations.ts)

Configure the [Migrations](https://www.convex.dev/components/migrations)
component for safe, online, batched schema migrations.

Returns the `migrations` instance (use `migrations.define({ table, migrateOne })`)
and a generic `run` runner to invoke any migration from the CLI/dashboard.

Pass your `schema` so `define()` gets table types. If you need to supply the
`internalMutation` builder instead, construct `Migrations` directly.

#### Type Parameters

<table>
<thead>
  <tr>
    <th>
      Type Parameter
    </th>
    
    <th>
      Default type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="type-parameter-schema-1">
        
      </a>
      
       <code>
        Schema
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        void
      </code>
      
       | <code>
        SchemaDefinition
      </code>
      
      <<code>
        GenericSchema
      </code>
      
      , <code>
        boolean
      </code>
      
      >
    </td>
    
    <td>
      <code>
        void
      </code>
    </td>
  </tr>
</tbody>
</table>

#### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        components
      </code>
    </td>
    
    <td>
      <a href="#migrationscomponents">
        <code>
          MigrationsComponents
        </code>
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        options?
      </code>
    </td>
    
    <td>
      <a href="#setupmigrationsoptions">
        <code>
          SetupMigrationsOptions
        </code>
      </a>
      
      <<code>
        Schema
      </code>
      
      >
    </td>
  </tr>
</tbody>
</table>

#### Returns

```ts
{
  migrations: Migrations<GenericDataModel, Schema, Schema extends SchemaDefinition<any, boolean> ? MaybeMakeLooseDataModel<{ [TableName in string]: Schema["tables"][TableName] extends TableDefinition<DocumentType, Indexes, SearchIndexes, VectorIndexes> ? { document: Expand<IdField<TableName> & Expand<(...) & (...)>>; fieldPaths: "_id" | ExtractFieldPaths<DocumentType>; indexes: Expand<Indexes & SystemIndexes>; searchIndexes: SearchIndexes; vectorIndexes: VectorIndexes } : never }, Schema["strictTableNameTypes"]> : GenericDataModel>;
  run: RegisteredMutation<"internal", {
     fn?: string;
     cursor?: string | null;
     batchSize?: number;
     dryRun?: boolean;
     next?: string[];
     reset?: boolean;
     oneBatchOnly?: boolean;
  }, Promise<Record<string, unknown>>>;
}
```

<table>
<thead>
  <tr>
    <th>
      Name
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Defined in
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        migrations
      </code>
    </td>
    
    <td>
      <code>
        Migrations
      </code>
      
      <<code>
        GenericDataModel
      </code>
      
      , <code>
        Schema
      </code>
      
      , <code>
        Schema
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        SchemaDefinition
      </code>
      
      <<code>
        any
      </code>
      
      , <code>
        boolean
      </code>
      
      > ? <code>
        MaybeMakeLooseDataModel
      </code>
      
      <{ [TableName in string]: Schema["tables"][TableName] extends TableDefinition<DocumentType, Indexes, SearchIndexes, VectorIndexes> ? { document: Expand<IdField<TableName> & Expand<(...) & (...)>>; fieldPaths: "_id" | ExtractFieldPaths<DocumentType>; indexes: Expand<Indexes & SystemIndexes>; searchIndexes: SearchIndexes; vectorIndexes: VectorIndexes } : never }, <code>
        Schema
      </code>
      
      [<code>
        "strictTableNameTypes"
      </code>
      
      ]> : <code>
        GenericDataModel
      </code>
      
      >
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/migrations.ts" rel="nofollow">
        src/convex/integrations/migrations.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        run
      </code>
    </td>
    
    <td>
      <code>
        RegisteredMutation
      </code>
      
      <<code>
        "internal"
      </code>
      
      , { <code>
        fn?
      </code>
      
      : <code>
        string
      </code>
      
      ; <code>
        cursor?
      </code>
      
      : <code>
        string
      </code>
      
       | <code>
        null
      </code>
      
      ; <code>
        batchSize?
      </code>
      
      : <code>
        number
      </code>
      
      ; <code>
        dryRun?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; <code>
        next?
      </code>
      
      : <code>
        string
      </code>
      
      <span>
        
      </span>
      
      ; <code>
        reset?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; <code>
        oneBatchOnly?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }, <code>
        Promise
      </code>
      
      <<code>
        Record
      </code>
      
      <<code>
        string
      </code>
      
      , <code>
        unknown
      </code>
      
      >>>
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/migrations.ts" rel="nofollow">
        src/convex/integrations/migrations.ts
      </a>
    </td>
  </tr>
</tbody>
</table>

#### Example

```ts
import { setupMigrations } from 'nuxt-backend/migrations'
import { components } from './_generated/api'
import schema from './schema'

export const { migrations, run } = setupMigrations(components, { schema })

export const backfillCompleted = migrations.define({
  table: 'todos',
  migrateOne: (_ctx, todo) => (todo.completed === undefined ? { completed: false } : undefined),
})
```


## Sitemap

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