postgres-migrations icon indicating copy to clipboard operation
postgres-migrations copied to clipboard

MigrateDBConfig does not support pre-existing client and ensureDatabaseExists at the same time

Open Tethik opened this issue 3 years ago • 4 comments

I noticed the createDb was marked as deprecated, so I moved to refactor my code to support the newer syntax.

In my client I'd like to do the following:

  client = await createPostgresPool(); 
  const config: MigrateDBConfig = {
    client,
    ensureDatabaseExists: true,
    defaultDatabase: databaseName,
  };
  await migrate(config, "src/data/migrations");

However, the type defined for MigrateDBConfig does not allow for ensureDatabaseExists at the same time with an existing client: https://github.com/ThomWright/postgres-migrations/blob/5a73373160b4e95200b1578c42101d67b9d28a6f/src/types.ts#L51-L55

Tethik avatar Aug 17 '21 10:08 Tethik

Yeah, honestly I'm not sure there's much value in supporting using existing clients - I can't even remember why I introduced it! I guess in case people want to use connection strings for the credentials or something?

Thanks for the issue. I'll see if I can find some time to look into supporting this combination of parameters.

ThomWright avatar Aug 17 '21 11:08 ThomWright

In my case it means I don't have to write the same code twice for e.g. fetching the secrets and setting up the connection to the database (with properties such as pinned CA etc).

Tethik avatar Aug 17 '21 12:08 Tethik

I can potentially try for a PR later this week too, but very hesitant to promise anything :)

Tethik avatar Aug 17 '21 12:08 Tethik

The current shortfall of not allowing a custom client is this library doesn't support the ssl setting of the client. If removing the ability to use a custom client, the ssl setting should be made available through the client config object.

Another potential issue with removing it, I currently use the aws-xray-sdk to wrap the pg library so I get trace data. Removing the ability to pass in a client would make this impossible(or much mroe difficult).

bruceharrison1984 avatar Apr 28 '22 14:04 bruceharrison1984