> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# MigrationManager

> API reference for the MigrationManager class used to handle database migrations.

The `MigrationManager` class provides a programmatic way to manage database schema migrations for Agno database tables.

## Constructor

```python theme={null}
MigrationManager(db: Union[AsyncBaseDb, BaseDb])
```

### Parameters

**db** `Union[AsyncBaseDb, BaseDb]` *required*

The database instance to run migrations on. Supports both synchronous and asynchronous database classes.

## Properties

**latest\_schema\_version** `Version`

Returns the latest available schema version from the migration versions list.

**available\_versions** `list[tuple[str, Version]]`

A list of available migration versions as tuples of (version\_string, parsed\_version).

Currently available versions:

* `v2_0_0` (2.0.0)
* `v2_3_0` (2.3.0)
* `v2_5_0` (2.5.0)
* `v2_5_6` (2.5.6)

## Methods

### up()

Executes upgrade migrations to bring database tables to a target schema version.

```python theme={null}
async def up(
    target_version: Optional[str] = None,
    table_type: Optional[str] = None,
    force: bool = False
)
```

#### Parameters

**target\_version** `str`

The version to migrate to (e.g., "2.3.0"). If not provided, migrates to the latest available version.

**table\_type** `str`

The specific table type to migrate. If not provided, all tables will be migrated.

Valid values: `"memories"`, `"sessions"`, `"metrics"`, `"evals"`, `"knowledge"`, `"culture"`, `"approvals"`

**force** `bool` (default: False)

Force the migration even if the current version is equal to or greater than the target version.

#### Example

```python theme={null}
import asyncio
from agno.db.migrations.manager import MigrationManager
from agno.db.postgres import AsyncPostgresDb

db = AsyncPostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai")

async def run_migrations():
    # Migrate all tables to latest version
    await MigrationManager(db).up()
    
    # Migrate specific table to specific version
    await MigrationManager(db).up(
        target_version="2.3.0",
        table_type="memories"
    )
    
    # Force migration
    await MigrationManager(db).up(
        table_type="sessions",
        force=True
    )

if __name__ == "__main__":
    asyncio.run(run_migrations())
```

### down()

Executes downgrade migrations to revert database tables to a target schema version.

```python theme={null}
async def down(
    target_version: str,
    table_type: Optional[str] = None,
    force: bool = False
)
```

#### Parameters

**target\_version** `str` *required*

The version to migrate down to (e.g., "2.0.0"). This parameter is required for down migrations.

**table\_type** `str`

The specific table type to migrate. If not provided, all tables will be migrated.

Valid values: `"memories"`, `"sessions"`, `"metrics"`, `"evals"`, `"knowledge"`, `"culture"`, `"approvals"`

**force** `bool` (default: False)

Force the migration even if the current version is equal to or less than the target version.

#### Example

```python theme={null}
import asyncio
from agno.db.migrations.manager import MigrationManager
from agno.db.postgres import AsyncPostgresDb

db = AsyncPostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai")

async def revert_migrations():
    # Revert all tables to version 2.0.0
    await MigrationManager(db).down(target_version="2.0.0")
    
    # Revert specific table
    await MigrationManager(db).down(
        target_version="2.0.0",
        table_type="memories"
    )

if __name__ == "__main__":
    asyncio.run(revert_migrations())
```

## Supported Databases

The `MigrationManager` supports the following database types:

* PostgreSQL (via `PostgresDb` or `AsyncPostgresDb`)
* SQLite (via `SqliteDb` or `AsyncSqliteDb`)
* MySQL (via `MySQLDb` or `AsyncMySQLDb`)
* SingleStore (via `SingleStoreDb`)

## Table Types

The following table types can be migrated:

| Table Type | Description |
| - | - |
| `memories` | User memory storage |
| `sessions` | Agent, team, and workflow session data |
| `metrics` | Performance and usage metrics |
| `evals` | Evaluation results |
| `knowledge` | Knowledge base entries |
| `culture` | Cultural knowledge entries |
| `approvals` | Human-in-the-loop approval records |

## See Also

* [Database Migrations Guide](https://agno-v2.mintlify.site/other/database-migrations.md)
* [Migration Scripts](https://github.com/agno-agi/agno/tree/main/libs/agno/agno/db/migrations)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.