oguimbal / pg-mem

An in memory postgres DB instance for your unit tests
MIT License
1.95k stars 94 forks source link

Cannot set schema option in db.adapters.createTypeormDataSource #334

Closed konradschewe closed 1 year ago

konradschewe commented 1 year ago

Describe the bug

I am trying to give the schema option with the TypeORM Data Source to create a connection to a specific schema. This is an issue, because pg-mem creates a connection to the public schema instead of the specified schema. Is there a workaround to connect to the correct schema with TypeORM anyways?

this.db.adapters.createTypeormDataSource({
        type: 'postgres',
        schema: `tenant_${tenantId}`,
        entities: SCHEMA_ENTITIES,
        migrations: SCHEMA_MIGRATIONS,
})

To Reproduce

  1. Create a TypeORM datasource as above.
  2. Run migrations on this schema.
  3. Tables are created in public schema.
  4. Any queries will go to the public schema.

pg-mem version

2.6.12