Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can’t Migrate Due to Lack of Knex Configuration Options #9607

Open
AlexAntonides opened this issue Oct 16, 2024 · 0 comments
Open

Can’t Migrate Due to Lack of Knex Configuration Options #9607

AlexAntonides opened this issue Oct 16, 2024 · 0 comments

Comments

@AlexAntonides
Copy link

Bug report

Describe the bug

We are using a CockroachDB instance. According to the knex/pg documentation, this is fully supported, however, we've noticed that this isn't supported in Medusa v2, due to a lack of configuration options.

I've noticed this while trying to migrate when connecting to a CockroachDB instance, which will give me the following error message,

2024-10-16T09:59:02.163050316Z {"level":"info","message":"Running migrations...","timestamp":"2024-10-16 09:59:02"}
TypeError: Cannot read properties of null (reading '1')
2024-10-16T09:59:04.197823482Z     at Client_PG._parseVersion (/app/node_modules/knex/lib/dialects/postgres/index.js:135:56)
2024-10-16T09:59:04.197829289Z     at Query.<anonymous> (/app/node_modules/knex/lib/dialects/postgres/index.js:129:22)
2024-10-16T09:59:04.197834335Z     at Query.handleReadyForQuery (/app/node_modules/pg/lib/query.js:142:14)
2024-10-16T09:59:04.197837829Z     at Client._handleReadyForQuery (/app/node_modules/pg/lib/client.js:311:19)
2024-10-16T09:59:04.197841895Z     at Connection.emit (node:events:519:28)
2024-10-16T09:59:04.197846509Z     at Connection.emit (node:domain:488:12)
2024-10-16T09:59:04.197849865Z     at /app/node_modules/pg/lib/connection.js:116:12
2024-10-16T09:59:04.197853012Z     at Parser.parse (/app/node_modules/pg-protocol/src/parser.ts:103:9)
2024-10-16T09:59:04.197856679Z     at TLSSocket.<anonymous> (/app/node_modules/pg-protocol/src/index.ts:7:48)

While digging around on the map, we've found that this TypeError is specifically related to using CockroachDB and that the solution is to either change the client to cockroachdb or to add a version to the Knex configuration (see Knex issue 2892, Knex issue 1477).

This isn't currently possible in the latest Medusa v2 codebase (ref). Unfortunately there is no way for us to change our database, so this is quite an issue for us.

System information

Medusa version (including plugins): rc / v2.0.10
Node.js version: 20
Database: Cockroachdb v23.1.28
Operating system: macOs 15.0

Steps to reproduce the behavior

  1. Setup a cockroachdb database
  2. Change the .env file with the correct variables,
    postgres://{user}:{password}@{cockroach_ip}:{cockroach_port}/{database}
  3. Migrate the database
  4. You should be greeted with the TypeError: Cannot read properties of null (reading '1') error.

Expected behavior

Medusa should allow us to supply additional options to the Knex/pg configuration so that anybody is able to connect to any Knex/pg supported databases and migrate.

Additional context

We think the solution is to either allow us to change the client or to supply any additional arguments (i.e. version) to the Knex instance (ref), e.g.

export function createPgConnection(options: Options) {
      const { pool, schema = "public", clientUrl, driverOptions, /** Option 1 **/ client = "pg", /** Option 2 **/, knexAdditionalOptions } = options
      [...]
      return knex<any, any>({
             /** Option 1 **/
             client,
             [...]
             /** Option 2 **/
             ...knexAdditionalOptions  
      }) 
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant