[**Documentation**](../../../README)

***

[Documentation](../../../README) / [zerotal](../../README) / [testing](../README) / migrateDatabase

# Function: migrateDatabase()

> **migrateDatabase**(`options?`): `Promise`\<`string`[]\>

Defined in: [packages/testing/src/migrateDatabase.ts:44](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/testing/src/migrateDatabase.ts#L44)

Build a test database's schema by running the project's real migrations.

A test schema written by hand is a second definition of the same tables, and
the two drift: a column added in a migration is missing in the tests until
something fails for a reason that has nothing to do with the change. Running
the migrations themselves means the schema under test is the schema that
ships.

## Parameters

### options?

[`MigrateDatabaseOptions`](../interfaces/MigrateDatabaseOptions) = `{}`

## Returns

`Promise`\<`string`[]\>

The names of the migrations that ran.

## Examples

```ts
describe('Post', () => {
  refreshDatabase({ connection: db, migrate: true });
  // …every test now sees the real schema, and rolls back after itself
});
```

```ts
// Standalone, outside refreshDatabase
beforeAll(() => migrateDatabase({ connection: db }));
```
