Skip to main content
zerotal

Documentation


Documentation / @zerotal/testing / index / migrateDatabase

Function: migrateDatabase()

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

Defined in: testing/src/migrateDatabase.ts:44

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 = {}

Returns

Promise<string[]>

The names of the migrations that ran.

Examples

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