Skip to content

Migrations can't be run on multiple schemas in the same database #92

Open
@slifty

Description

@slifty

I am using schemas to parallelize integration tests (one schema per test worker).

Before each test I want to run the following setup:

  1. Create a new schema
  2. Set the search_path to be the schema
  3. Run my migrations

Unfortunately right now postgres-migrations only allows migrations to be once per database (NOT per schema). It looks like this is because in migrate.ts the check for the migrations table doesn't account for the idea that more than one schema can exist (and that migrations existing in one doesn't mean migrations exists in the current search_path).

async function doesTableExist(client: BasicPgClient, tableName: string) {
  const result = await client.query(SQL`SELECT EXISTS (
  SELECT 1
  FROM   pg_catalog.pg_class c
  WHERE  c.relname = ${tableName}
  AND    c.relkind = 'r'
);`)

As an example, if I manually create a migrations table in two different schemas this query would return more than one row:

image

I hope this makes sense! It would be wonderful if this tool could support the parallel-test-schema use case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions