driescroons/mikro-orm-graphql-example

`set_session_replication_role = 'replica'` error

Closed this issue · 2 comments

idkjs commented

I am trying to run you example and getting the above error:

❯ postgres --version

postgres (PostgreSQL) 13.0
❯ yarn loadFixtures
yarn run v1.22.5
$ yarn test --grep "should clear database and load fixtures"
$ cross-env NODE_DEV=true NODE_ENV=test ts-mocha ./tests/**/*.test.ts --package package.json --grep 'should clear database and load fixtures'


  Sample tests
== Migration20200809143205: migrating =======
== Migration20200809143205: migrated (0.119s)

🚀 http://localhost:8080/graphql
    1) should clear database and load fixtures


  0 passing (2s)
  1 failing

  1) Sample tests
       should clear database and load fixtures:
     DriverException: set session_replication_role = 'replica'; - permission denied to set parameter "session_replication_role"
      at PostgreSqlExceptionConverter.convertException (node_modules/@mikro-orm/core/platforms/ExceptionConverter.js:8:16)
      at PostgreSqlExceptionConverter.convertException (node_modules/@mikro-orm/postgresql/PostgreSqlExceptionConverter.js:40:22)
      at PostgreSqlDriver.convertException (node_modules/@mikro-orm/core/drivers/DatabaseDriver.js:147:54)
      at /Users/mandalarian/Downloads/mikro-orm-graphql-example/node_modules/@mikro-orm/core/drivers/DatabaseDriver.js:151:24
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
      at SchemaGenerator.execute (node_modules/@mikro-orm/knex/schema/SchemaGenerator.js:108:13)
      at SchemaGenerator.dropSchema (node_modules/@mikro-orm/knex/schema/SchemaGenerator.js:55:9)
      at Object.exports.clearDatabase (src/utils/services/clearDatabase.service.ts:5:5)
      at Context.<anonymous> (tests/sample.test.ts:25:9)

  previous error: set session_replication_role = 'replica'; - permission denied to set parameter "session_replication_role"
      at Parser.parseErrorMessage (node_modules/pg-protocol/src/parser.ts:357:11)
      at Parser.handlePacket (node_modules/pg-protocol/src/parser.ts:186:21)
      at Parser.parse (node_modules/pg-protocol/src/parser.ts:101:30)
      at Socket.<anonymous> (node_modules/pg-protocol/src/index.ts:7:48)
      at Socket.EventEmitter.emit (domain.js:485:12)
      at addChunk (_stream_readable.js:302:12)
      at readableAddChunk (_stream_readable.js:278:9)
      at Socket.Readable.push (_stream_readable.js:217:10)
      at TCP.onStreamRead (internal/stream_base_commons.js:186:23)



error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Am i missing a step from the Readme?

Thank for sharing.

@idkjs you can get past the error by adding the following to your migrations config:

disableForeignKeys: true, // wrap statements with 'set foreign_key_checks = 0' or equivalent.

eg.

  migrations: {
    path: path.join(__dirname, "./migrations"),
    pattern: /^[\w-]+\d+\.[tj]s$/,
    disableForeignKeys: false,
  },

However, disabling foreign keys might not be the best idea in the long run -- not sure what the exact consequences of using this flag are.

tks - foreignkeys are useless if you ask me. they will create issues once you go do a distributed model/db
plus they slow down the insertions.