oguimbal / pg-mem

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

migrate on custom schemas does not work #364

Open stathismor opened 11 months ago

stathismor commented 11 months ago

Describe the bug

Migrations on custom schemas do not seem to be taking effect when using the pg adapter.

To Reproduce

A simplified version of my code:

import { newDb } from 'pg-mem';

const SCHEMA = 'test';

const db = newDb();
db.createSchema(SCHEMA);

const migrationsPath = 'migrations';
await db.getSchema(SCHEMA).migrate({
  migrationsPath,
});

const { Client } = db.adapters.createPg();
const client = new Client();
const query = client.query.bind(client);

console.log(await query('SELECT * FROM information_schema.tables;'));

migrationsPath has just an SQL file with a single query:

CREATE TABLE test_user (
  id uuid NOT NULL
);

This print the following. As you see, table_schema is still public where, when I used my own schema (test):

{
      rows: [
        {
          table_catalog: 'pgmem',
          table_schema: 'public',
          table_name: 'migrations',
          table_type: 'BASE TABLE',
          self_referencing_column_name: null,
          reference_generation: null,
          user_defined_type_catalog: null,
          user_defined_type_schema: null,
          user_defined_type_name: null,
          is_insertable_into: 'YES',
          is_typed: 'NO',
          commit_action: null
        },
        {
          table_catalog: 'pgmem',
          table_schema: 'public',
          table_name: 'test_user',
          table_type: 'BASE TABLE',
          self_referencing_column_name: null,
          reference_generation: null,
          user_defined_type_catalog: null,
          user_defined_type_schema: null,
          user_defined_type_name: null,
          is_insertable_into: 'YES',
          is_typed: 'NO',
          commit_action: null
        }
      ],
      rowCount: 2,
      command: 'SELECT',
      fields: [Getter],
      location: { start: 0, end: 0 }
    }

pg-mem version

2.7.1