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

"Driver not connected" #9

Open
nmacherey opened this issue Dec 8, 2023 · 4 comments
Open

"Driver not connected" #9

nmacherey opened this issue Dec 8, 2023 · 4 comments
Assignees

Comments

@nmacherey
Copy link

The module si not working with postgres dialect, postgres does not have in memory databases.

There are various issues:

  1. The loadEntities method is missing a call to await mockDb.initialize() actually it throws Driver not connected exception
  2. To terminate the process, await mockDB.destroy(); should be added at the end of the method before returning the queries.
  3. Postgres does not offers in-memory databases. You have various approaches, one of them would be to use pg-mem but it is not officially supported by postgres. Or really connect to a non vistrual DB. To to so additional parameters should be added to the script such as the dbname, username and password. Or the function should allow to add environment variables.
  4. The method does not export all objects required for our database. Enums are not exported which make the initial migration to fail.

Please find a modified version here:

export async function loadEntities(
  dialect: Dialect,
  // eslint-disable-next-line @typescript-eslint/ban-types
  entities: (Function | EntitySchema | string)[],
) {
  const mockDB = new DataSource({
    type: dialect,
    host: process.env.TYPEORM_HOST,
    port: Number(process.env.TYPEORM_PORT),
    username: process.env.TYPEORM_USERNAME,
    password: process.env.TYPEORM_PASSWORD,
    database: process.env.TYPEORM_DATABASE,
    schema: process.env.TYPEORM_SCHEMA,
    entities,
    logging: false,
    synchronize: false,
  });

  await mockDB.initialize();

  const driver = mockDB.driver;
  const sqlInMemory = await driver.createSchemaBuilder().log();

  const queries = sqlInMemory.upQueries.map((query) => query.query);

  await mockDB.destroy();
  return queries.join(';\n');
}
@ronenlu
Copy link
Member

ronenlu commented Dec 8, 2023

@nmacherey Thanks for reporting the issue. We found an issue with how the provider handles enums. We are working on a fix and will report back

@ronenlu
Copy link
Member

ronenlu commented Dec 10, 2023

@nmacherey Postgres enums are now supported.
You can install the latest version of the provider:
npm i @ariga/[email protected]

Thank you for reporting the bug :)

@nmacherey
Copy link
Author

nmacherey commented Dec 11, 2023

@ronenlu Thank you for your feed back but the db connexion does not work with postgres...
Or you should give in arguments all TYPEORM_* environment variables
and create the :memory: database.

My I have missed something ?

I also have issues with postgres SQL schema and extensions, as extensions can only be installed in a single schema and there is no way to specifiy the extension search path.

@ronenlu
Copy link
Member

ronenlu commented Dec 11, 2023

@nmacherey Can you share the error trace you are getting and the command you are running?

The reason Im not passing the TYPEORM_* args inside the loadEntities function, because there a lot of scenarios where you cannot connet to the DB instace ( CI etc ).
So Im not really connecting to the DB., rather I just use the Driver to parse the given Entities to DDL of the schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants