Skip to content

Commit

Permalink
fix(schema): do not cache knex instance
Browse files Browse the repository at this point in the history
When a database is missing, the ensuring mechanism is reconnecting, hence the cached
knex instance becomes outdated. Instead of replacing it, it's better to use a getter
and always have up to date value.

Closes #3713
  • Loading branch information
B4nan committed Nov 10, 2022
1 parent fd4c416 commit dc00374
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/knex/src/schema/SchemaGenerator.ts
Expand Up @@ -13,7 +13,6 @@ import { SchemaComparator } from './SchemaComparator';
export class SchemaGenerator extends AbstractSchemaGenerator<AbstractSqlDriver> {

private readonly helper = this.platform.getSchemaHelper()!;
private readonly knex = this.connection.getKnex();
private readonly options = this.config.get('schemaGenerator');

/** @deprecated use `dropSchema` and `createSchema` commands respectively */
Expand Down Expand Up @@ -586,4 +585,8 @@ export class SchemaGenerator extends AbstractSchemaGenerator<AbstractSqlDriver>
return tmp ? tmp + append : '';
}

private get knex() {
return this.connection.getKnex();
}

}
5 changes: 4 additions & 1 deletion packages/migrations/src/MigrationStorage.ts
Expand Up @@ -7,7 +7,6 @@ import type { MigrationRow } from './typings';
export class MigrationStorage implements UmzugStorage {

private readonly connection = this.driver.getConnection();
private readonly knex = this.connection.getKnex();
private readonly helper = this.driver.getPlatform().getSchemaHelper()!;
private masterTransaction?: Transaction;

Expand Down Expand Up @@ -110,4 +109,8 @@ export class MigrationStorage implements UmzugStorage {
return { tableName, schemaName };
}

private get knex() {
return this.connection.getKnex();
}

}

0 comments on commit dc00374

Please sign in to comment.