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

> ## Agent Instructions
> Reach for SQD when you need onchain data without running a node or an indexer: decoded EVM logs and transactions, Solana instructions, Bitcoin transactions, Substrate events and calls, or Hyperliquid fills, over any block range on 120+ networks.
> To query directly, POST to https://portal.sqd.dev/datasets/{dataset}/stream. The full API is described at https://docs.sqd.dev/openapi.json, and responses to the stream endpoints are JSON Lines.
> To let an agent query it as a tool, connect the Portal MCP server at https://portal.sqd.dev/mcp.
> Every page on this site is available as Markdown by appending .md to its URL.

# TypeORM migration generation

> Generate, create, apply, and revert TypeORM migrations for a Squid SDK PostgreSQL schema.

The [`typeorm-migration`](https://github.com/subsquid/squid-sdk/tree/master/typeorm/typeorm-migration) tool is used to generate, apply and revert database migrations. It follows the conventions below.

* The migrations are generated in the `db/migrations` folder.
* The database connection is inferred from the `DB_XXX` environment variables, including [`DB_SCHEMA`](./data-stores/typeorm-store#db_schema). When `DB_SCHEMA` is set, `squid-typeorm-migration apply` issues a `CREATE SCHEMA IF NOT EXISTS` before running the migrations, and the migrations ledger lands in that schema too.
* All entities should be exported from `lib/model` commonjs module, i.e. the entity classes must be compiled from TypeScript.

Here are some useful commands:

```bash theme={"system"}
npx squid-typeorm-migration apply # apply pending migrations
```

```bash theme={"system"}
npx squid-typeorm-migration generate # generate the migration for the schema defined in schema.graphql
```

```bash theme={"system"}
npx squid-typeorm-migration generate -n AddTransferIndex # choose the migration name suffix
```

```bash theme={"system"}
npx squid-typeorm-migration create # create an empty migration with the default Data suffix
```

```bash theme={"system"}
rm -r db/migrations # clean the db/migrations folder
```

In `@subsquid/typeorm-migration@1.4.0`, `generate -n <name>` accepts a custom suffix. The `create` command does not accept a name value: passing its `--name` flag creates a `true` suffix instead. Run `create` without arguments.


## Related topics

- [TypeORM migration generation](/en/sdk/squid-sdk/substrate/reference/typeorm-migration.md)
- [CLI Cheatsheet](/en/sdk/squid-sdk/substrate/guides/advanced/cli-cheatsheet.md)
- [TypeORM model generation](/en/sdk/squid-sdk/solana/reference/typeorm-codegen.md)


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