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

# roll

> Commands for managing database migrations

The `roll` commands help you manage database migrations using pgroll.

<Tip>
  You can override the `pgroll` binary version used by the CLI via the `XATA_PGROLL_BINARY_VERSION` environment variable. See [Binary Version Overrides](/cli/index#binary-version-overrides) for details.
</Tip>

## Subcommands

### baseline

Create a baseline migration for an existing database schema.

```bash theme={null}
xata roll baseline [--lock-timeout <ms>] [--pgroll-schema <schema>] [--postgres-url <url>] [--role <role>] [--schema <schema>] [--use-version-schema] [--verbose] [--json] [--yes] [-h|--help] [<name>] [<folder>]
```

<ParamField path="--lock-timeout" type="number">
  Postgres lock timeout in milliseconds for pgroll DDL operations
</ParamField>

<ParamField path="--pgroll-schema" type="string">
  Postgres schema to use for pgroll internal state
</ParamField>

<ParamField path="--postgres-url" type="string">
  Postgres URL
</ParamField>

<ParamField path="--role" type="string">
  Optional postgres role to set when executing migrations
</ParamField>

<ParamField path="--schema" type="string">
  Postgres schema to use for the migration
</ParamField>

<ParamField path="--use-version-schema" type="boolean">
  Create version schemas for each migration
</ParamField>

<ParamField path="--verbose" type="boolean">
  Enable verbose logging
</ParamField>

<ParamField path="--json" type="boolean">
  Output in JSON format instead of YAML
</ParamField>

<ParamField path="--yes" type="boolean">
  Skip confirmation prompt
</ParamField>

<ParamField path="-h, --help" type="boolean">
  Print help information and exit
</ParamField>

<ParamField path="name" type="string">
  Name of the migration (e.g., "01\_initial\_schema")
</ParamField>

<ParamField path="folder" type="string">
  The directory that contains the migrations (default: `.xata/migrations`)
</ParamField>

### complete

Complete an ongoing migration with the operations present in the given file.

```bash theme={null}
xata roll complete [--lock-timeout <ms>] [--pgroll-schema <schema>] [--postgres-url <url>] [--role <role>] [--schema <schema>] [--use-version-schema] [--verbose] [-h|--help]
```

<ParamField path="--lock-timeout" type="number">
  Postgres lock timeout in milliseconds for pgroll DDL operations
</ParamField>

<ParamField path="--pgroll-schema" type="string">
  Postgres schema to use for pgroll internal state
</ParamField>

<ParamField path="--postgres-url" type="string">
  Postgres URL
</ParamField>

<ParamField path="--role" type="string">
  Optional postgres role to set when executing migrations
</ParamField>

<ParamField path="--schema" type="string">
  Postgres schema to use for the migration
</ParamField>

<ParamField path="--use-version-schema" type="boolean">
  Create version schemas for each migration
</ParamField>

<ParamField path="--verbose" type="boolean">
  Enable verbose logging
</ParamField>

<ParamField path="-h, --help" type="boolean">
  Print help information and exit
</ParamField>

### init

Initialize pgroll in the target database.

```bash theme={null}
xata roll init [--lock-timeout <ms>] [--pgroll-schema <schema>] [--postgres-url <url>] [--role <role>] [--schema <schema>] [--use-version-schema] [--verbose] [-h|--help]
```

<ParamField path="--lock-timeout" type="number">
  Postgres lock timeout in milliseconds for pgroll DDL operations
</ParamField>

<ParamField path="--pgroll-schema" type="string">
  Postgres schema to use for pgroll internal state
</ParamField>

<ParamField path="--postgres-url" type="string">
  Postgres URL
</ParamField>

<ParamField path="--role" type="string">
  Optional postgres role to set when executing migrations
</ParamField>

<ParamField path="--schema" type="string">
  Postgres schema to use for the migration
</ParamField>

<ParamField path="--use-version-schema" type="boolean">
  Create version schemas for each migration
</ParamField>

<ParamField path="--verbose" type="boolean">
  Enable verbose logging
</ParamField>

<ParamField path="-h, --help" type="boolean">
  Print help information and exit
</ParamField>

### latest

Print the name of the latest schema version, either in the target database or a local directory.

```bash theme={null}
xata roll latest [--lock-timeout <ms>] [--pgroll-schema <schema>] [--postgres-url <url>] [--role <role>] [--schema <schema>] [--verbose] [--local] [--with-schema] [-h|--help]
```

<ParamField path="--lock-timeout" type="number">
  Postgres lock timeout in milliseconds for pgroll DDL operations
</ParamField>

<ParamField path="--pgroll-schema" type="string">
  Postgres schema to use for pgroll internal state
</ParamField>

<ParamField path="--postgres-url" type="string">
  Postgres URL
</ParamField>

<ParamField path="--role" type="string">
  Optional postgres role to set when executing migrations
</ParamField>

<ParamField path="--schema" type="string">
  Postgres schema to use for the migration
</ParamField>

<ParamField path="--verbose" type="boolean">
  Enable verbose logging
</ParamField>

<ParamField path="--local" type="boolean">
  Retrieve the latest version from a local migration directory
</ParamField>

<ParamField path="--with-schema" type="boolean">
  Prefix the version with the schema name
</ParamField>

<ParamField path="-h, --help" type="boolean">
  Print help information and exit
</ParamField>

### migrate

Apply outstanding migrations from a directory to a database.

```bash theme={null}
xata roll migrate [--lock-timeout <ms>] [--pgroll-schema <schema>] [--postgres-url <url>] [--role <role>] [--schema <schema>] [--verbose] [--backfill-batch-delay <delay>] [--backfill-batch-size <size>] [--complete] [-h|--help] [<folder>]
```

<ParamField path="--lock-timeout" type="number">
  Postgres lock timeout in milliseconds for pgroll DDL operations
</ParamField>

<ParamField path="--pgroll-schema" type="string">
  Postgres schema to use for pgroll internal state
</ParamField>

<ParamField path="--postgres-url" type="string">
  Postgres URL
</ParamField>

<ParamField path="--role" type="string">
  Optional postgres role to set when executing migrations
</ParamField>

<ParamField path="--schema" type="string">
  Postgres schema to use for the migration
</ParamField>

<ParamField path="--verbose" type="boolean">
  Enable verbose logging
</ParamField>

<ParamField path="--backfill-batch-delay" type="string">
  Duration of delay between batch backfills (eg. 1s, 1000ms)
</ParamField>

<ParamField path="--backfill-batch-size" type="number">
  Number of rows backfilled in each batch
</ParamField>

<ParamField path="--complete" type="boolean">
  Complete the final migration rather than leaving it active
</ParamField>

<ParamField path="-h, --help" type="boolean">
  Print help information and exit
</ParamField>

<ParamField path="folder" type="string">
  The directory that contains the migrations (default: `.xata/migrations`)
</ParamField>

### update

Update outdated migrations in a directory.

```bash theme={null}
xata roll update [--lock-timeout <ms>] [--pgroll-schema <schema>] [--postgres-url <url>] [--role <role>] [--schema <schema>] [--verbose] [-h|--help] [<folder>]
```

<ParamField path="--lock-timeout" type="number">
  Postgres lock timeout in milliseconds for pgroll DDL operations
</ParamField>

<ParamField path="--pgroll-schema" type="string">
  Postgres schema to use for pgroll internal state
</ParamField>

<ParamField path="--postgres-url" type="string">
  Postgres URL
</ParamField>

<ParamField path="--role" type="string">
  Optional postgres role to set when executing migrations
</ParamField>

<ParamField path="--schema" type="string">
  Postgres schema to use for the migration
</ParamField>

<ParamField path="--verbose" type="boolean">
  Enable verbose logging
</ParamField>

<ParamField path="-h, --help" type="boolean">
  Print help information and exit
</ParamField>

<ParamField path="folder" type="string">
  The directory that contains the migrations (default: `.xata/migrations`)
</ParamField>

### pull

Pull migration history from the target database and write it to disk.

```bash theme={null}
xata roll pull [--lock-timeout <ms>] [--pgroll-schema <schema>] [--postgres-url <url>] [--role <role>] [--schema <schema>] [--verbose] [--json] [--with-prefixes] [-h|--help] [<folder>]
```

<ParamField path="--lock-timeout" type="number">
  Postgres lock timeout in milliseconds for pgroll DDL operations
</ParamField>

<ParamField path="--pgroll-schema" type="string">
  Postgres schema to use for pgroll internal state
</ParamField>

<ParamField path="--postgres-url" type="string">
  Postgres URL
</ParamField>

<ParamField path="--role" type="string">
  Optional postgres role to set when executing migrations
</ParamField>

<ParamField path="--schema" type="string">
  Postgres schema to use for the migration
</ParamField>

<ParamField path="--verbose" type="boolean">
  Enable verbose logging
</ParamField>

<ParamField path="--json" type="boolean">
  Output each migration in JSON format instead of YAML
</ParamField>

<ParamField path="--with-prefixes" type="boolean">
  Prefix each migration filename with its position in the schema history
</ParamField>

<ParamField path="-h, --help" type="boolean">
  Print help information and exit
</ParamField>

<ParamField path="folder" type="string">
  The target directory to pull migrations into (default: `.xata/migrations`)
</ParamField>

### rollback

Roll back an ongoing migration.

```bash theme={null}
xata roll rollback [--lock-timeout <ms>] [--pgroll-schema <schema>] [--postgres-url <url>] [--role <role>] [--schema <schema>] [--verbose] [-h|--help]
```

<ParamField path="--lock-timeout" type="number">
  Postgres lock timeout in milliseconds for pgroll DDL operations
</ParamField>

<ParamField path="--pgroll-schema" type="string">
  Postgres schema to use for pgroll internal state
</ParamField>

<ParamField path="--postgres-url" type="string">
  Postgres URL
</ParamField>

<ParamField path="--role" type="string">
  Optional postgres role to set when executing migrations
</ParamField>

<ParamField path="--schema" type="string">
  Postgres schema to use for the migration
</ParamField>

<ParamField path="--verbose" type="boolean">
  Enable verbose logging
</ParamField>

<ParamField path="-h, --help" type="boolean">
  Print help information and exit
</ParamField>

### start

Start a migration for the operations present in the given file.

```bash theme={null}
xata roll start <file> [--lock-timeout <ms>] [--pgroll-schema <schema>] [--postgres-url <url>] [--role <role>] [--schema <schema>] [--use-version-schema] [--verbose] [--backfill-batch-delay <delay>] [--backfill-batch-size <size>] [--complete] [--skip-validation] [-h|--help]
```

<ParamField path="file" type="string" required>
  The migration file to start
</ParamField>

<ParamField path="--lock-timeout" type="number">
  Postgres lock timeout in milliseconds for pgroll DDL operations
</ParamField>

<ParamField path="--pgroll-schema" type="string">
  Postgres schema to use for pgroll internal state
</ParamField>

<ParamField path="--postgres-url" type="string">
  Postgres URL
</ParamField>

<ParamField path="--role" type="string">
  Optional postgres role to set when executing migrations
</ParamField>

<ParamField path="--schema" type="string">
  Postgres schema to use for the migration
</ParamField>

<ParamField path="--use-version-schema" type="boolean">
  Create version schemas for each migration
</ParamField>

<ParamField path="--verbose" type="boolean">
  Enable verbose logging
</ParamField>

<ParamField path="--backfill-batch-delay" type="string">
  Duration of delay between batch backfills (eg. 1s, 1000ms)
</ParamField>

<ParamField path="--backfill-batch-size" type="number">
  Number of rows backfilled in each batch
</ParamField>

<ParamField path="--complete" type="boolean">
  Mark the migration as complete
</ParamField>

<ParamField path="--skip-validation" type="boolean">
  Skip migration validation
</ParamField>

<ParamField path="-h, --help" type="boolean">
  Print help information and exit
</ParamField>

### status

Show pgroll status.

```bash theme={null}
xata roll status [--lock-timeout <ms>] [--pgroll-schema <schema>] [--postgres-url <url>] [--role <role>] [--schema <schema>] [--verbose] [-h|--help]
```

<ParamField path="--lock-timeout" type="number">
  Postgres lock timeout in milliseconds for pgroll DDL operations
</ParamField>

<ParamField path="--pgroll-schema" type="string">
  Postgres schema to use for pgroll internal state
</ParamField>

<ParamField path="--postgres-url" type="string">
  Postgres URL
</ParamField>

<ParamField path="--role" type="string">
  Optional postgres role to set when executing migrations
</ParamField>

<ParamField path="--schema" type="string">
  Postgres schema to use for the migration
</ParamField>

<ParamField path="--verbose" type="boolean">
  Enable verbose logging
</ParamField>

<ParamField path="-h, --help" type="boolean">
  Print help information and exit
</ParamField>

### convert

Convert SQL statements to a pgroll migration.

```bash theme={null}
xata roll convert <file> [--lock-timeout <ms>] [--pgroll-schema <schema>] [--postgres-url <url>] [--role <role>] [--schema <schema>] [--verbose] [--json] [-h|--help]
```

<ParamField path="file" type="string" required>
  The migration file to start
</ParamField>

<ParamField path="--lock-timeout" type="number">
  Postgres lock timeout in milliseconds for pgroll DDL operations
</ParamField>

<ParamField path="--pgroll-schema" type="string">
  Postgres schema to use for pgroll internal state
</ParamField>

<ParamField path="--postgres-url" type="string">
  Postgres URL
</ParamField>

<ParamField path="--role" type="string">
  Optional postgres role to set when executing migrations
</ParamField>

<ParamField path="--schema" type="string">
  Postgres schema to use for the migration
</ParamField>

<ParamField path="--verbose" type="boolean">
  Enable verbose logging
</ParamField>

<ParamField path="--json" type="boolean">
  Output migration file in JSON format instead of YAML
</ParamField>

<ParamField path="-h, --help" type="boolean">
  Print help information and exit
</ParamField>

## Global Flags

<ParamField path="-h, --help" type="boolean">
  Print help information and exit
</ParamField>
