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

# Running migrations

> Apply pending migrations across every module with talos migration:up.

Apply pending migrations across every module with `talos migration:up`. The command runs each module's `bin/migration/up.ts` script from the module's own directory. Each runner loads every registered migration, sorts it by version, applies each pending one inside a transaction, and records the version when it succeeds.

```bash theme={null}
# Run all pending migrations
talos migration:up

# DROP the schema first, then run every migration (destructive, dev only)
talos migration:up --drop

# Force every module to run, ignoring the cache
talos migration:up --no-cache
```

| Option       | Description                                                      | Default |
| ------------ | ---------------------------------------------------------------- | ------- |
| `--drop`     | Drop and recreate the `public` schema before running migrations. | `false` |
| `--no-cache` | Skip reading and writing the migration cache.                    | `false` |

## How a run proceeds

The runner creates the tracking table if it is missing, then walks every migration in version order. For each one it checks the tracking table for the version's `id`; if the row exists, the migration is already applied and is skipped. Otherwise it opens a transaction, runs the migration's dependencies and then its `up()`, and inserts the version's `id` into the tracking table. Because the insert is part of the same transaction, a failure rolls back both the schema change and the tracking row, and the run stops.

## Dropping the schema

Passing `--drop` runs `DROP SCHEMA public CASCADE` followed by `CREATE SCHEMA public` before any migration runs, then re-applies every migration from scratch. That is destructive — it wipes the whole schema — so reserve it for development and never point it at a shared or production database. `--drop` also bypasses the cache, since the reset must always re-run.

## Running `up()` directly

Outside the CLI you can call `up()` from `@talosjs/migrations`. It reads `DATABASE_URL` and uses the default `migrations` table by default, or takes an explicit connection string and tracking table name:

```typescript theme={null}
import { up } from "@talosjs/migrations";

// Uses DATABASE_URL and the default "migrations" table
await up();

// Or with explicit config
await up({
  databaseUrl: "postgres://user:pass@localhost:5432/mydb",
  tableName: "schema_migrations",
});
```

See the [`migration:up` command](/cli/commands/migration-up) for the full reference.

## Next steps

* [Rolling back](/migrations/rollback): reverse an applied migration with `talos migration:down`.
* [Caching](/migrations/caching): how the per-version run cache skips unchanged migrations.
