Skip to content

Allow configurable postgres extensions #7584

Closed

Description

@dncnkrs

Feature Description

There should be an option to add additional postgres extensions when connecting to a database.

The Problem

We're using the tablefunc module in some of our view entities. Right now, we need to make sure the extension is installed when we create the database. It would be better if TypeORM could ensure the extension is created while it installs other extensions, such as uuid-ossp.

The Solution

From my perspective, ideally we provide an array of extensions when we're configuring the connection. This only really needs to be a string array. The extensions could then be at the same time as the others.

Considered Alternatives

We could add a migration that runs this query, but this isn't compatible with development workflows using synchronize. It also feels slightly awkward. An ORM should manage the minutia of a database for us, which includes making sure the necessary features are enabled.

Additional Context

Relevant Database Driver(s)

  • aurora-data-api
  • aurora-data-api-pg
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time, and I know how to start.
  • Yes, I have the time, but I don't know how to start. I would need guidance.
  • No, I don't have the time, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.

(I'm a little stretched right now.)

Activity

  1. strongpauly commented on Jun 13, 2025

    @strongpauly
    Contributor

    I've worked around this by doing something like this when the DataSource gets created:

    const extensions = ['tablefunc']; // Whatever extensions you want to install
    const dataSource = new DataSource(config);
    (dataSource as any).__initialize = dataSource.initialize;
    dataSource.initialize = async function () {
         await this.__initialize();
         for (const extension of extensions) {
             await this.query(/*sql*/ `CREATE EXTENSION IF NOT EXISTS ${extension}`);
         }
         return this;
    };
    dataSource.initialize.bind(dataSource);

    A bit hacky, but it works until this feature is implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions